database

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 19 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

Index

Constants

View Source
const (
	// Driver names as stored in DB_DRIVER and returned by Driver.Name.
	DriverSQLite   = "sqlite"
	DriverPostgres = "postgres"
	DriverMySQL    = "mysql"

	// Migration subdirs as stored under internal/database/migrations and every
	// module's future migration FS. PostgreSQL differs from its driver name.
	MigrationSQLite   = "sqlite"
	MigrationPostgres = "postgresql"
	MigrationMySQL    = "mysql"
)

Variables

View Source
var (
	ErrDatabaseNotFound  = errors.New("database file not found")
	ErrUnsupportedDriver = errors.New("unsupported database driver")
)

Functions

func Drivers added in v1.0.0

func Drivers() (*kerneldatabase.DriverRegistry, error)

Drivers returns the registry of every compiled-in database driver. Open resolves through it on every call so driver selection stays in one place; modules use it to resolve Dialects without importing drivers.

func MigrateModules added in v1.0.0

func MigrateModules(db *sql.DB, driver string, reg *kernel.Registry) error

MigrateModules runs pending migrations for every Migrator in reg, after the core migrations. Each module versions independently in its own schema_migrations_<module> table, so modules install, upgrade, and disable without touching the core sequence or each other. A module with no migration subdir for the active driver is skipped.

Module migrations must be idempotent for upgrades (CREATE TABLE IF NOT EXISTS): pre-module installs already carry the tables from the core sequence they were extracted from.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database wraps the SQL database connection

func Open

func Open(driver, dsn string, poolMaxConns int) (*Database, error)

Open opens a database connection for the specified driver and DSN. For SQLite, the DSN is a file path (parent directories are created). For PostgreSQL, the DSN is a connection string. poolMaxConns is used only for PostgreSQL to set the connection pool size.

Driver selection resolves through the kernel driver registry: an unknown driver fails with both the legacy ErrUnsupportedDriver (back-compat) and a kernel UnknownDriverError listing installed drivers.

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection

func (*Database) DB

func (d *Database) DB() *sql.DB

DB returns the underlying SQL database connection

func (*Database) RunMigrations

func (d *Database) RunMigrations(driver string) error

RunMigrations runs all pending database migrations from the embedded filesystem for the specified driver ("sqlite", "postgres", or "mysql").

Jump to

Keyboard shortcuts

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