db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db provides GORM database connection management for serverless and HTTP services.

Index

Constants

This section is empty.

Variables

View Source
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

func SQLitePragmaInt(gdb *gorm.DB, name string) (int, error)

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

func SQLitePragmaString(gdb *gorm.DB, name string) (string, error)

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

func VerifySQLitePragmas(gdb *gorm.DB) error

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.

Jump to

Keyboard shortcuts

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