db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package db owns database setup, dialect adaptation, and schema migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBool

func ParseBool(value any) (bool, error)

func ParseDate

func ParseDate(value any) (time.Time, error)

func ParseTime

func ParseTime(value any) (time.Time, error)

func ParseUUID

func ParseUUID(value any) (uuid.UUID, error)

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB embeds database/sql and carries the type conversion rules for one dialect.

func Open

func Open(ctx context.Context, dialect Dialect, dsn, backupDir string) (*DB, error)

Open connects to the database, verifies the migration history and applies the pending migrations. Before changing a database that already holds tables it writes a private backup into backupDir; if that is impossible it fails without touching the database.

func (*DB) BoolArg

func (d *DB) BoolArg(value bool) any

func (*DB) DateArg

func (d *DB) DateArg(value time.Time) any

func (*DB) Dialect

func (d *DB) Dialect() Dialect

func (*DB) Initialized

func (d *DB) Initialized(ctx context.Context) (bool, error)

func (*DB) SQL

func (d *DB) SQL(query string) string

SQL rewrites positional ? placeholders to PostgreSQL's $n syntax. SQL used by this project keeps placeholders out of quoted strings and comments.

func (*DB) TimeArg

func (d *DB) TimeArg(value time.Time) any

func (*DB) UUIDArg

func (d *DB) UUIDArg(value uuid.UUID) any

func (*DB) WasNew

func (d *DB) WasNew() bool

WasNew reports whether this Open call found a database with no tables at all, before the first migration. It remains distinct from Initialized, which reports whether the owner row exists.

func (*DB) WithTx

func (d *DB) WithTx(ctx context.Context, fn func(*sql.Tx) error) error

type Dialect

type Dialect string
const (
	SQLite   Dialect = "sqlite"
	Postgres Dialect = "postgres"
)

Directories

Path Synopsis
Package dbtest creates isolated databases for store and migration tests.
Package dbtest creates isolated databases for store and migration tests.

Jump to

Keyboard shortcuts

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