Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect returns a pgxpool.Pool for the given database URL. If dbURL starts with "postgres:tc:", it spins up a Testcontainer automatically. The testcontainer process lifetime is managed by the Docker daemon; callers should invoke pool.Close() when done with the connection.
func OpenPool ¶
OpenPool returns the process-wide singleton pgxpool connection. The caller supplies the DBConfig (typically from AppConfig.DBConfig). The pool is created on the first call and reused on subsequent calls. A SIGTERM/SIGINT handler is registered to gracefully close the pool on shutdown.
Types ¶
type DBConfig ¶
type DBConfig struct {
Host string `env:"HOST" envDefault:"localhost"`
Port int `env:"PORT" envDefault:"5432"`
User string `env:"USER"`
Password string `env:"PASSWORD"`
Name string `env:"NAME"`
CloudSQLInstance string `env:"CLOUD_SQL_INSTANCE"`
DatabaseURLTemplate string `env:"URL_TEMPLATE" envDefault:"postgres:tc://[username]:[password]@[host]:[port]/[database_name]"`
}
DBConfig holds the database connection parameters. Environment variables are read with the "DB_" prefix (e.g. DB_HOST, DB_PORT).
func (DBConfig) ResolveURL ¶
ResolveURL expands the DatabaseURLTemplate placeholders using the struct's own credential fields.