sqlutil

package
v0.1.63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sqlutil provides small SQL query-building and value-conversion helpers shared by the SQL-backed stores and readers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildWhereClause

func BuildWhereClause(conditions []string) string

BuildWhereClause joins condition strings into a SQL WHERE clause. Returns an empty string when conditions is empty.

func ClampLimitOffset

func ClampLimitOffset(limit, offset, defaultLimit, maxLimit int) (int, int)

ClampLimitOffset normalises pagination parameters: limit defaults to defaultLimit when non-positive and is capped at maxLimit; offset floors at 0.

func DerefTrimmed

func DerefTrimmed(value *string) string

DerefTrimmed converts an optional text column to a trimmed string.

func EscapeLikeWildcards

func EscapeLikeWildcards(s string) string

EscapeLikeWildcards escapes SQL LIKE/ILIKE wildcard characters in user input to prevent wildcard injection. Escapes \, %, and _.

func NullableJSONStrings

func NullableJSONStrings(values []string, ref string) any

NullableJSONStrings marshals values to a JSON array for binding to a JSON column. Returns nil (SQL NULL) when values is empty or marshaling fails; failures are logged with ref identifying the row.

func NullableString

func NullableString(value string) any

NullableString returns the trimmed value, or nil when blank, for binding optional strings to nullable text columns.

func ParseSQLiteTimestamp

func ParseSQLiteTimestamp(ts string) (time.Time, bool)

ParseSQLiteTimestamp parses a SQLite text timestamp in the formats GoModel writes (RFC3339Nano, SQLite datetime with offset, or bare UTC seconds). Returns the zero time and false when no format matches.

func StringsFromJSON

func StringsFromJSON(raw string, ref string) []string

StringsFromJSON parses a JSON array column into a string slice, tolerating NULL, empty, and malformed values so one bad row cannot break listing; malformed values are logged with ref identifying the row.

func TimeFromUnixPtr

func TimeFromUnixPtr(value *int64) *time.Time

TimeFromUnixPtr converts an optional Unix timestamp to a *time.Time.

func UnixOrNil

func UnixOrNil(value *time.Time) any

UnixOrNil returns the UTC Unix timestamp for value, or nil when value is nil, for binding optional timestamps to nullable integer columns.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL