Documentation ¶
Overview ¶
Package clpostgres provides re-usable components for using PostgreSQL
Index ¶
- func New(pcfg *pgxpool.Config, _ Migrater, trp trace.TracerProvider, ...) (*sql.DB, error)
- func NewPool(pcfg *pgxpool.Config, cfg Config, _ Migrater) (*pgxpool.Pool, error)
- func NewReadOnlyConfig(cfg Config, logs *zap.Logger, awsc aws.Config) (*pgxpool.Config, error)
- func NewReadWriteConfig(cfg Config, logs *zap.Logger, awsc aws.Config) (*pgxpool.Config, error)
- func Provide() fx.Option
- func TestProvide() fx.Option
- type Config
- type Logger
- type Migrater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New( pcfg *pgxpool.Config, _ Migrater, trp trace.TracerProvider, mtp metric.MeterProvider, ) (*sql.DB, error)
New inits a stdlib sql connection. Any other dependency can optionally be provided as migrated to force it's lifecycle to be run before the database is connected. This is mostly useful to run migration logic (such as initializing the database).
func NewPool ¶ added in v0.10.8
NewPool inits a raw pgx postgres connection pool. Migrater is specified as a dependency so it force it's lifecycle hooks to be run.
func NewReadOnlyConfig ¶
NewReadOnlyConfig constructs a config for a read-only database connecion. The aws config is optional and is only used when IamAuth option is set.
func NewReadWriteConfig ¶
NewReadWriteConfig constructs a config for a read-write database connecion. The aws config is optional and only used when the IamAuth option is set.
func TestProvide ¶ added in v0.17.0
TestProvide configures the DI for a test environment.
Types ¶
type Config ¶
type Config struct { // DatabaseName names the database the connection will be made to DatabaseName string `env:"DATABASE_NAME" envDefault:"postgres"` // ReadWriteHostname endpoint allows configuration of a endpoint that can read and write ReadWriteHostname string `env:"RW_HOSTNAME" envDefault:"localhost"` // ReadOnlyHostname endpoint allows configuration of a endpoint that can read and write ReadOnlyHostname string `env:"RO_HOSTNAME" envDefault:"localhost"` // Port for to the database connection(s) Port int `env:"PORT" envDefault:"5432"` // Username configures the username to connect to the postgres instance Username string `env:"USERNAME" envDefault:"postgres"` // Password configures the postgres password for authenticating with the instance Password string `env:"PASSWORD"` // ApplicationName allows the application to indicate its name so connections can be more easily debugged ApplicationName string `env:"APPLICATION_NAME" envDefault:"unknown"` // PgxLogLevel is provided to pgx to determine the level of logging of postgres interactions PgxLogLevel string `env:"PGX_LOG_LEVEL" envDefault:"info"` // SSLMode sets tls encryption on the database connection SSLMode string `env:"SSL_MODE" envDefault:"disable"` // IamAuthRegion will cause the password to be set to an IAM token for authentication IamAuthRegion string `env:"IAM_AUTH_REGION"` // PoolConnectionTimeout configures how long the pgx pool connect logic waits for the connection to establish PoolConnectionTimeout time.Duration `env:"POOL_CONNECTION_TIMEOUT" envDefault:"10s"` // Connection pool parameters PoolMaxConns int32 `env:"POOL_MAX_CONNS"` }
Config configures the code in this package.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a pgx logger that uses a main zap logger for logging but will prefer using a context specific logger if it exists.
Directories ¶
Path | Synopsis |
---|---|
Package clpgmigrate implements the postgres migration logic.
|
Package clpgmigrate implements the postgres migration logic. |
Package cltx is a small package for adding and retrieving pgx transactions from the context.
|
Package cltx is a small package for adding and retrieving pgx transactions from the context. |