Documentation
¶
Overview ¶
Package dbutil provides shared helpers for database-layer operations.
Index ¶
- func FormatTime(t time.Time) string
- func IsUniqueViolation(err error) bool
- func MergeSettings(existing, newSettings json.RawMessage) json.RawMessage
- func NullInt32(p *int) *int64
- func NullInt32FromInt64Ptr(p *int64) *int64
- func NullInt32Value(p *int64) int
- func NullInt64FromInt(v int) *int64
- func NullString(p *string) *string
- func NullStringFromString(s string) *string
- func NullStringPtr(p *string) *string
- func NullStringValue(p *string) string
- func NullTime(p *time.Time) *string
- func NullTimePtr(s *string) *time.Time
- func NullableString(s string) *string
- func ParseRFC3339(s string) time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTime ¶
FormatTime returns the RFC3339Nano UTC string for t. Used at write sites for TIMESTAMPTZ columns stored as TEXT.
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a SQLite unique constraint violation (extended result codes SQLITE_CONSTRAINT_UNIQUE / SQLITE_CONSTRAINT_PRIMARYKEY).
func MergeSettings ¶
func MergeSettings(existing, newSettings json.RawMessage) json.RawMessage
MergeSettings returns newSettings with any keys absent from newSettings filled in from existing. Keys present in newSettings win, except the masked placeholder "***": API responses mask secrets that way, so a client that echoes a response back must not overwrite the real secret. This preserves secret fields (passwords, API keys) when the frontend omits them, or round-trips them masked, in an update request.
func NullInt32 ¶
NullInt32 converts a *int to *int64 (SQLite stores INTEGER as int64). A nil pointer yields nil.
func NullInt32FromInt64Ptr ¶
NullInt32FromInt64Ptr returns p unchanged; sqlc-sqlite emits *int64 for nullable integer columns. Kept under the old name so existing call sites continue to compile against the migrated API.
func NullInt32Value ¶
NullInt32Value returns the dereferenced value of p, or 0 if nil.
func NullInt64FromInt ¶
NullInt64FromInt converts a Go int to *int64. Returns nil for zero values when callers want "0 means NULL"; otherwise pair with a direct &v cast.
func NullString ¶
NullString returns p unchanged. Kept as a no-op for callers that built against the older sql.NullString-based API.
func NullStringFromString ¶
NullStringFromString is an alias of NullableString.
func NullStringPtr ¶
NullStringPtr is the identity for *string.
func NullStringValue ¶
NullStringValue returns the dereferenced value of p, or "" if nil.
func NullTime ¶
NullTime converts a *time.Time to its RFC3339Nano UTC string representation. A nil pointer yields nil so the column stores as SQL NULL.
TIMESTAMPTZ columns are stored as TEXT in SQLite (see migration squash); using RFC3339 keeps lexicographic ordering identical to chronological ordering, which several queries rely on.
func NullTimePtr ¶
NullTimePtr parses an RFC3339-encoded *string back to *time.Time. Nil or unparseable input yields nil.
func NullableString ¶
NullableString returns nil for an empty string, otherwise a pointer to s. Used to feed sqlc-generated *string params from string values where the convention is "empty means SQL NULL".
func ParseRFC3339 ¶
ParseRFC3339 parses an RFC3339(Nano) timestamp string, returning the zero time on any error.
Types ¶
This section is empty.