Documentation
¶
Index ¶
- Variables
- func EscapeLIKE(s string) string
- func Exec(ctx context.Context, db *sqlx.DB) sqlx.ExtContext
- func WithContentionFlag(ctx context.Context) (context.Context, *atomic.Bool)
- type DB
- func (d *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *DB) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (d *DB) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
- func (d *DB) PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
- func (d *DB) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
- func (d *DB) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
- func (d *DB) Rebind(query string) string
- func (d *DB) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (d *DB) WithinTx(ctx context.Context, fn func(context.Context) error) error
- type DBTime
- type SQLite
- type Transactor
Constants ¶
This section is empty.
Variables ¶
var ErrContended = errors.New("database write contention")
ErrContended is returned when a write could not proceed because SQLite's single writer was held and busy_timeout expired. It is an availability signal, not a domain error: the HTTP boundary maps it to 503 Service Unavailable with a Retry-After header, never a 500.
Functions ¶
func EscapeLIKE ¶ added in v0.4.0
EscapeLIKE escapes SQL LIKE wildcards (`%`, `_`) and the escape character itself (`\`) in user-supplied input so it matches literally. Pair the returned value with an `ESCAPE '\'` clause in the query, e.g.:
sq.Expr(`col LIKE ? ESCAPE '\'`, "%"+database.EscapeLIKE(input)+"%")
func WithContentionFlag ¶ added in v0.4.0
WithContentionFlag returns a context carrying a contention flag plus the flag itself. withinTx sets the flag when a write transaction fails with ErrContended; a caller (the HTTP layer) reads it after the work completes to translate the response — out of band, since the contention error is otherwise swallowed by handlers' own error mapping.
Types ¶
type DB ¶ added in v0.3.0
type DB struct {
// contains filtered or unexported fields
}
DB is the repo-facing handle. It has the full query surface + WithinTx.
func (*DB) ExecContext ¶ added in v0.3.0
func (*DB) GetContext ¶ added in v0.3.0
func (*DB) NamedExecContext ¶ added in v0.3.0
func (*DB) PreparexContext ¶ added in v0.4.0
PreparexContext prepares a statement against the ctx's transaction if one is present, else the pool. Reuse the returned *sqlx.Stmt to amortize statement compilation across many executions of the same query — e.g. a per-row insert inside a batch. The caller must Close it before the surrounding tx commits.
func (*DB) QueryRowxContext ¶ added in v0.3.0
func (*DB) QueryxContext ¶ added in v0.3.0
func (*DB) Rebind ¶ added in v0.3.0
Rebind translates `?` placeholders to whatever the underlying driver expects. Lets callers compose queries via sqlx.In (e.g. `WHERE id IN (?)`) without having to think about driver-specific bind styles.
func (*DB) SelectContext ¶ added in v0.3.0
type DBTime ¶
DBTime is only needed for aggregate functions (MAX, MIN etc.) that return TEXT even for DATETIME columns. Regular columns declared as DATETIME scan directly into time.Time when using modernc.org/sqlite with _texttotime=1 in the DSN.
type SQLite ¶
type SQLite struct {
// contains filtered or unexported fields
}
func (*SQLite) Transactor ¶ added in v0.3.0
func (s *SQLite) Transactor() *Transactor
type Transactor ¶ added in v0.3.0
type Transactor struct {
// contains filtered or unexported fields
}
Transactor is the service-facing handle. It exposes ONLY tx orchestration — no query methods. A service holding one can compose operations atomically but cannot perform SQL.
func NewTransactor ¶ added in v0.3.0
func NewTransactor(pool *sqlx.DB) *Transactor