Documentation
¶
Overview ¶
Package db provides GORM database connection management for serverless and HTTP services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSQLitePragma = errors.New("sqlite: connection is missing a required pragma")
ErrSQLitePragma reports that a SQLite connection is missing a pragma the caller requires. VerifySQLitePragmas wraps it, naming the offending pragma, so errors.Is(err, ErrSQLitePragma) matches while the message stays specific.
Functions ¶
func NewConnection ¶
func NewConnection(cfg config.DatabaseConfig) (*gorm.DB, error)
NewConnection creates a new GORM database connection based on the configuration. It supports "sqlite" and "postgres" drivers. Accepts any type that implements the DatabaseConfig interface.
func SQLitePragmaInt ¶ added in v0.4.0
SQLitePragmaInt reads an integer-valued PRAGMA from gdb (for example busy_timeout or synchronous). The pragma name is a caller-controlled constant, not user input.
func SQLitePragmaString ¶ added in v0.4.0
SQLitePragmaString reads a text-valued PRAGMA from gdb (for example journal_mode). The pragma name is a caller-controlled constant, not user input.
func VerifySQLitePragmas ¶ added in v0.4.0
VerifySQLitePragmas verifies the connection pragmas a concurrent SQLite workload relies on, returning ErrSQLitePragma (naming the pragma) on a hard failure.
A file database must be in WAL so readers do not block a writer; an in-memory database — which cannot use WAL — is exempt from that one requirement but, like any database, still needs a positive busy_timeout to absorb a brief write lock and a safe synchronous level so a committed write survives a crash. synchronous is required to be NORMAL(1) or FULL(2); OFF(0) is refused.
The check reads pragmas only, so it needs no dialector and makes no assumptions about how the connection was opened. Warnings a caller may want on top of the fatal checks — foreign_keys, DSN-only settings such as _txlock=immediate — are left to the caller, which knows its own schema.
Types ¶
This section is empty.