Versions in this module Expand all Collapse all v0 v0.1.0 Nov 10, 2023 Changes in this version + const ContextKeyDatabaseTransaction + const ContextKeyDoTxnCallerSkip + var ErrForeignTables = errors.New("the database contains foreign tables") + var ErrNotOwned = errors.New("the database is owned by") + var ErrTxn = errors.New("transaction") + var ErrTxnBegin = fmt.Errorf("%w: begin", ErrTxn) + var ErrTxnCommit = fmt.Errorf("%w: commit", ErrTxn) + var ErrUnsupportedDatabaseVersion = errors.New("unsupported database schema version") + var ErrUnsupportedDialect = errors.New("unsupported database dialect") + type Config struct + ReadOnlyPool PoolConfig + type ContextExecable interface + ExecContext func(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + QueryContext func(ctx context.Context, query string, args ...interface{}) (Rows, error) + QueryRowContext func(ctx context.Context, query string, args ...interface{}) *sql.Row + type Database struct + Dialect Dialect + IgnoreForeignTables bool + IgnoreUnsupportedDatabase bool + Log DatabaseLogger + Owner string + RawDB *sql.DB + ReadOnlyDB *sql.DB + UpgradeTable UpgradeTable + VersionTable string + func NewFromConfig(owner string, cfg Config, logger DatabaseLogger) (*Database, error) + func NewWithDB(db *sql.DB, rawDialect string) (*Database, error) + func NewWithDialect(uri, rawDialect string) (*Database, error) + func (db *Database) Child(versionTable string, upgradeTable UpgradeTable, log DatabaseLogger) *Database + func (db *Database) Close() error + func (db *Database) ColumnExists(tx Execable, table, column string) (exists bool, err error) + func (db *Database) Configure(cfg Config) error + func (db *Database) Conn(ctx context.Context) ContextExecable + func (db *Database) DoTxn(ctx context.Context, opts *sql.TxOptions, fn func(ctx context.Context) error) error + func (db *Database) TableExists(tx Execable, table string) (exists bool, err error) + func (db *Database) Upgrade() error + func (ld *Database) Begin() (*LoggingTxn, error) + func (ld *Database) BeginTx(ctx context.Context, opts *sql.TxOptions) (*LoggingTxn, error) + type DatabaseLogger interface + DoUpgrade func(from, to int, message string, txn bool) + PrepareUpgrade func(current, compat, latest int) + QueryTiming func(ctx context.Context, method, query string, args []interface{}, nrows int, ...) + Warn func(msg string, args ...interface{}) + WarnUnsupportedVersion func(current, compat, latest int) + var NoopLogger DatabaseLogger = &noopLogger{} + func ZeroLogger(log zerolog.Logger, cfg ...ZeroLogSettings) DatabaseLogger + func ZeroLoggerPtr(log *zerolog.Logger, cfg ...ZeroLogSettings) DatabaseLogger + type Dialect int + const DialectUnknown + const Postgres + const SQLite + func ParseDialect(engine string) (Dialect, error) + func (dialect Dialect) String() string + type Execable interface + Exec func(query string, args ...interface{}) (sql.Result, error) + Query func(query string, args ...interface{}) (Rows, error) + QueryRow func(query string, args ...interface{}) *sql.Row + type JSON struct + Data any + func (j JSON) Scan(i any) error + func (j JSON) Value() (driver.Value, error) + type LoggingExecable struct + UnderlyingExecable UnderlyingExecable + func (le *LoggingExecable) Exec(query string, args ...interface{}) (sql.Result, error) + func (le *LoggingExecable) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + func (le *LoggingExecable) Query(query string, args ...interface{}) (Rows, error) + func (le *LoggingExecable) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) + func (le *LoggingExecable) QueryRow(query string, args ...interface{}) *sql.Row + func (le *LoggingExecable) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row + type LoggingRows struct + func (lrs *LoggingRows) Close() error + func (lrs *LoggingRows) ColumnTypes() ([]*sql.ColumnType, error) + func (lrs *LoggingRows) Columns() ([]string, error) + func (lrs *LoggingRows) Err() error + func (lrs *LoggingRows) Next() bool + func (lrs *LoggingRows) NextResultSet() bool + func (lrs *LoggingRows) Scan(dest ...any) error + type LoggingTxn struct + EndTime time.Time + StartTime time.Time + UnderlyingTx *sql.Tx + func (lt *LoggingTxn) Commit() error + func (lt *LoggingTxn) Rollback() error + type PoolConfig struct + ConnMaxIdleTime string + ConnMaxLifetime string + MaxIdleConns int + MaxOpenConns int + Type string + URI string + type Rows interface + Close func() error + ColumnTypes func() ([]*sql.ColumnType, error) + Columns func() ([]string, error) + Err func() error + Next func() bool + NextResultSet func() bool + Scan func(...any) error + type Scannable interface + Scan func(...interface{}) error + type Transaction interface + Commit func() error + Rollback func() error + type UnderlyingContextExecable interface + ExecContext func(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + QueryContext func(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + QueryRowContext func(ctx context.Context, query string, args ...interface{}) *sql.Row + type UnderlyingExecable interface + Exec func(query string, args ...interface{}) (sql.Result, error) + Query func(query string, args ...interface{}) (*sql.Rows, error) + QueryRow func(query string, args ...interface{}) *sql.Row + type UpgradeTable []upgrade + func (ut *UpgradeTable) Register(from, to, compat int, message string, txn bool, fn upgradeFunc) + func (ut *UpgradeTable) RegisterFS(fs fullFS) + func (ut *UpgradeTable) RegisterFSPath(fs fullFS, dir string) + type ZeroLogSettings struct + Caller bool + CallerSkipFrame int + TraceLogAllQueries bool