Documentation
¶
Index ¶
- func NewConnectionPool(ctx context.Context, connString string, opts ...ConnectionPoolOption) (*sql.DB, error)
- type ConnectionPoolOption
- func WithHealthCheckPeriod(d time.Duration) ConnectionPoolOption
- func WithMaxConnIdleTime(d time.Duration) ConnectionPoolOption
- func WithMaxConnLifetime(d time.Duration) ConnectionPoolOption
- func WithMaxConnLifetimeJitter(d time.Duration) ConnectionPoolOption
- func WithMaxConnections(max int32) ConnectionPoolOption
- func WithMinConnections(min int32) ConnectionPoolOption
- func WithMinIdleConnections(min int32) ConnectionPoolOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnectionPool ¶
func NewConnectionPool(ctx context.Context, connString string, opts ...ConnectionPoolOption) (*sql.DB, error)
NewConnectionPool creates a new connection pool for Postgres using the provided connection string.
The connection string uses standard Postgres format: `postgres://user:password@host:port/database?sslmode=disable`.
It returns a sql.DB instance that can be used to interact with the database.
The function accepts optional configuration options to customize the connection pool.
Types ¶
type ConnectionPoolOption ¶
ConnectionPoolOption is a function type that modifies the pgxpool.Config for a Postgres connection pool.
func WithHealthCheckPeriod ¶
func WithHealthCheckPeriod(d time.Duration) ConnectionPoolOption
WithHealthCheckPeriod sets the interval for health checks on connections in the pool.
func WithMaxConnIdleTime ¶
func WithMaxConnIdleTime(d time.Duration) ConnectionPoolOption
WithMaxConnIdleTime sets the maximum idle time of a connection in the pool.
func WithMaxConnLifetime ¶
func WithMaxConnLifetime(d time.Duration) ConnectionPoolOption
WithMaxConnLifetime sets the maximum lifetime of a connection in the pool.
func WithMaxConnLifetimeJitter ¶
func WithMaxConnLifetimeJitter(d time.Duration) ConnectionPoolOption
WithMaxConnLifetimeJitter sets the maximum lifetime jitter for connections in the pool.
func WithMaxConnections ¶
func WithMaxConnections(max int32) ConnectionPoolOption
WithMaxConnections sets the maximum number of connections in the pool.
func WithMinConnections ¶
func WithMinConnections(min int32) ConnectionPoolOption
WithMinConnections sets the minimum number of connections in the pool.
func WithMinIdleConnections ¶
func WithMinIdleConnections(min int32) ConnectionPoolOption
WithMinIdleConnections sets the minimum number of idle connections in the pool.