Database (pgx)
pkg/db/drivers/pgx manages a PostgreSQL connection pool using jackc/pgx.
lakta.NewRuntime( config.NewModule( config.WithConfigDirs(".", "./config"), config.WithArgs(os.Args[1:]), ), tint.NewModule(), slog.NewModule(), pgx.NewModule(), myapp.NewModule(),)Consuming the connection
Section titled “Consuming the connection”func (m *MyModule) Init(ctx context.Context) error { pool := do.MustInvoke[*pgxpool.Pool](lakta.GetInjector(ctx)) m.pool = pool return nil}Multi-instance
Section titled “Multi-instance”pgx.NewModule(pgx.WithName("primary")),pgx.NewModule(pgx.WithName("replica")),modules: db: pgx: primary: dsn: "postgres://user:pass@primary:5432/mydb" replica: dsn: "postgres://user:pass@replica:5432/mydb"Configuration Reference
Section titled “Configuration Reference”Config path: modules.db.pgx.<name>
dsn required dSN is the database connection string used to configure the database connection
env
LAKTA_MODULES_DB_PGX_<NAME>_DSN max_open_conns maxOpenConns specifies the maximum number of open connections to the database. It maps to the "max_open_conns" configuration
env
LAKTA_MODULES_DB_PGX_<NAME>_MAX_OPEN_CONNS log_level logLevel specifies the logging level for database operations, supporting values like trace, debug, info, warn, error, none
env
LAKTA_MODULES_DB_PGX_<NAME>_LOG_LEVEL health_check healthCheck enables or disables the database health check mechanism
env
LAKTA_MODULES_DB_PGX_<NAME>_HEALTH_CHECK