Documentation
¶
Index ¶
Constants ¶
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 ¶
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
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 ¶
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) RunMigrations ¶
RunMigrations runs all pending database migrations from the embedded filesystem for the specified driver ("sqlite", "postgres", or "mysql").