Documentation
¶
Overview ¶
Package sqlx provides base types and helper functions to work with SQL databases.
Index ¶
- Constants
- Variables
- func ConstraintFailed(err error, constraint, column string) bool
- func DataSource(path string, writable bool, pragma map[string]string) string
- func ExpandIn[T any](query string, param string, args []T) (string, []any)
- func Select[T any](db Tx, query string, args []any, scan func(rows *sql.Rows) (T, error)) ([]T, error)
- func TypedError(err error) error
- type DB
- type RowScanner
- type Tx
Constants ¶
const ( Asc = "asc" Desc = "desc" )
Sorting direction.
const ( Sum = "sum" Min = "min" Max = "max" )
Aggregation functions.
Variables ¶
var DefaultPragma = map[string]string{
"journal_mode": "wal",
"synchronous": "normal",
"temp_store": "memory",
"mmap_size": "268435456",
"foreign_keys": "on",
}
DefaultPragma is a set of default database settings.
Functions ¶
func ConstraintFailed ¶ added in v0.4.0
ConstraintFailed checks if the error is due to a constraint violation on a column.
func DataSource ¶ added in v0.4.0
DataSource returns an SQLite connection string for a read-only or read-write mode.
func TypedError ¶ added in v0.2.0
Returns typed errors for some specific cases.
Types ¶
type DB ¶
type DB[T any] struct { RW *sql.DB // read-write handle RO *sql.DB // read-only handle sync.Mutex // contains filtered or unexported fields }
DB is a generic database-backed repository with a domain-specific transaction of type T. Has separate database handles for read-write and read-only operations.
func New ¶
newSqlDB creates a new database-backed repository. Like openSQL, but does not create the database schema.
func Open ¶
Open creates a new database-backed repository. Creates the database schema if necessary.
func (*DB[T]) UpdateContext ¶
UpdateContext executes a function within a writable transaction.
type RowScanner ¶
rowScanner is an interface to scan rows.