sqlutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendInClause

func AppendInClause(b *strings.Builder, column string, values []string, args *[]any)

AppendInClause appends "column IN (?,?,...)" to a strings.Builder and adds the values to the args slice. It does not handle the leading AND/OR.

func ContainsFold

func ContainsFold(slice []string, value string) bool

ContainsFold reports whether slice contains value (case-insensitive comparison).

func ExecDeleteCount

func ExecDeleteCount(ctx context.Context, db LifecycleSQL, query string, args ...any) (int64, error)

ExecDeleteCount executes a DELETE query and returns the number of rows affected.

func HasWildcard

func HasWildcard(values []string) bool

HasWildcard reports whether values contains "*".

func IsSQLiteDuplicateColumnError

func IsSQLiteDuplicateColumnError(err error) bool

IsSQLiteDuplicateColumnError reports whether err is SQLite's duplicate-column migration error.

func IsSQLiteNoSuchTableError

func IsSQLiteNoSuchTableError(err error) bool

IsSQLiteNoSuchTableError reports whether err is SQLite's missing-table error.

func IsSQLiteTransientLockError

func IsSQLiteTransientLockError(err error) bool

IsSQLiteTransientLockError reports whether err is a retryable SQLite lock/busy error.

func NullIfBlank

func NullIfBlank(value string) any

NullIfBlank returns nil for blank/whitespace values or the original string for non-blank values. Use when a blank string should be stored as SQL NULL.

func OriginSourceFromChatKey

func OriginSourceFromChatKey(chatKey string) string

OriginSourceFromChatKey extracts the source prefix from a "source:chatID" chat key.

func SanitizeFTS5Pattern

func SanitizeFTS5Pattern(raw string) string

SanitizeFTS5Pattern removes punctuation that is unsafe in a SQLite FTS5 MATCH pattern while preserving word characters, whitespace, wildcard, plus, and quotes.

func SessionKeyMatchesSources

func SessionKeyMatchesSources(sessionKey string, sources []string) bool

SessionKeyMatchesSources checks whether a turn session key is allowed by a source filter. Turn rows match either the storage kind "turn" or the session key's adapter/source prefix (for example "discord"). If sources is empty or contains a wildcard, returns true.

Types

type LifecycleSQL

type LifecycleSQL interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...any) *sql.Row
}

LifecycleSQL is the minimal interface satisfied by both *sql.DB and *sql.Tx.

Jump to

Keyboard shortcuts

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