dbconfig

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package dbconfig resolves the driver-scoped database connection environment.

Connection variables are namespaced per driver — DB_MYSQL_* and DB_PGSQL_* — and DB_DRIVER selects the active set at runtime. This leaf package lets both internal/platform/database and internal/platform/services/adapter resolve the active connection without an import cycle.

Index

Constants

View Source
const (
	DriverMySQL    = "mysql"
	DriverMariaDB  = "mariadb"
	DriverPostgres = "postgres"
)

Canonical driver names returned by NormalizeDriver and Driver.

Variables

This section is empty.

Functions

func Driver

func Driver() string

Driver returns the active, normalized driver: TEST_DB_DRIVER when set (test runs), else DB_DRIVER, else MySQL.

func Env

func Env(key string) string

Env returns the driver-scoped value of DB_<key>: DB_MYSQL_<key> when the active driver is MySQL/MariaDB, DB_PGSQL_<key> when it is PostgreSQL. Falls back to the legacy flat DB_<key> when the namespaced var is unset, so test targets and scripts that inject flat DB_* credentials keep working.

func EnvDefault

func EnvDefault(key, def string) string

EnvDefault returns Env(key), or def when the driver-scoped value is unset or empty.

func EnvInt

func EnvInt(key string, def int) int

EnvInt returns Env(key) parsed as an int, or def when unset or unparseable.

func IsPostgres

func IsPostgres() bool

IsPostgres reports whether the active driver is PostgreSQL.

func NormalizeDriver

func NormalizeDriver(raw string) string

NormalizeDriver maps a configured driver name to its canonical form: every PostgreSQL alias ("postgres", "postgresql", "pgsql") becomes "postgres"; other values are lower-cased and trimmed ("mysql", "mariadb", ...). An empty value means MySQL. This is the only place driver aliases are known.

Types

This section is empty.

Jump to

Keyboard shortcuts

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