Documentation
¶
Index ¶
- Constants
- func AutoMigrate(models ...any) error
- func Close() error
- func Get() *gorm.DB
- func GetDB() *gorm.DB
- func Init(cfg *config.DatabaseConfig) error
- func PackageStorageSource(cfg *config.DatabaseConfig) (string, error)
- func PostgresDSN(cfg *config.DatabaseConfig) string
- func Reset()
- func SQLitePath(cfg *config.DatabaseConfig) string
Constants ¶
const DefaultSQLitePath = "config/data/v2board.db"
DefaultSQLitePath is the SQLite database file used when none is configured.
Variables ¶
This section is empty.
Functions ¶
func PackageStorageSource ¶ added in v4.1.0
func PackageStorageSource(cfg *config.DatabaseConfig) (string, error)
PackageStorageSource returns what package storage derives package connections from: the kernel's PostgreSQL connection string, or the absolute path of the SQLite database file. It holds kernel credentials and must stay in the kernel.
func PostgresDSN ¶ added in v4.1.0
func PostgresDSN(cfg *config.DatabaseConfig) string
PostgresDSN builds a PostgreSQL keyword/value connection string from cfg.
Every value is single-quoted and escaped the way libpq and pgx expect (`\` becomes `\\`, `'` becomes `\'`), so empty values and values containing spaces, quotes, `=` or backslashes cannot swallow the next keyword. Without quoting, an empty password turned `password= dbname=x` into the password "dbname=x" and silently connected to the user's default database.
An empty Host and a Port <= 0 are omitted so the driver defaults apply (libpq and pgx: the local Unix socket directory or localhost, port 5432), matching libpq, which treats an empty host or port as unset.
The `sslmode` and `TimeZone` settings come first (defaults `disable` and `Asia/Shanghai`): gorm.io/driver/postgres also scans the raw DSN for the first `TimeZone=`, so a password that happens to contain that text cannot override the time zone.
A non-empty cfg.DSN is returned unchanged, for connection strings supplied whole by a secret store or database operator.
func SQLitePath ¶ added in v4.1.0
func SQLitePath(cfg *config.DatabaseConfig) string
SQLitePath returns the configured SQLite database file.
Types ¶
This section is empty.