Documentation
¶
Overview ¶
Package sqlutil provides small SQL query-building and value-conversion helpers shared by the SQL-backed stores and readers.
Index ¶
- func BuildWhereClause(conditions []string) string
- func ClampLimitOffset(limit, offset, defaultLimit, maxLimit int) (int, int)
- func DerefTrimmed(value *string) string
- func EscapeLikeWildcards(s string) string
- func NullableJSONStrings(values []string, ref string) any
- func NullableString(value string) any
- func ParseSQLiteTimestamp(ts string) (time.Time, bool)
- func StringFromNullable(value sql.NullString) string
- func StringsFromJSON(raw string, ref string) []string
- func TimeFromUnix(value sql.NullInt64) *time.Time
- func TimeFromUnixPtr(value *int64) *time.Time
- func UnixOrNil(value *time.Time) any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildWhereClause ¶
BuildWhereClause joins condition strings into a SQL WHERE clause. Returns an empty string when conditions is empty.
func ClampLimitOffset ¶
ClampLimitOffset normalises pagination parameters: limit defaults to defaultLimit when non-positive and is capped at maxLimit; offset floors at 0.
func DerefTrimmed ¶
DerefTrimmed converts an optional text column to a trimmed string.
func EscapeLikeWildcards ¶
EscapeLikeWildcards escapes SQL LIKE/ILIKE wildcard characters in user input to prevent wildcard injection. Escapes \, %, and _.
func NullableJSONStrings ¶
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 ¶
NullableString returns the trimmed value, or nil when blank, for binding optional strings to nullable text columns.
func ParseSQLiteTimestamp ¶
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 StringFromNullable ¶
func StringFromNullable(value sql.NullString) string
StringFromNullable converts a nullable text column to a trimmed string.
func StringsFromJSON ¶
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 TimeFromUnix ¶
TimeFromUnix converts a nullable Unix timestamp column to a *time.Time.
func TimeFromUnixPtr ¶
TimeFromUnixPtr converts an optional Unix timestamp to a *time.Time.
Types ¶
This section is empty.