Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildConnectionString ¶
func BuildConnectionString(config PostgresConfig) string
BuildConnectionString builds a connection string for external use (testing, migrations, etc.) Properly URL-encodes components to handle special characters
Types ¶
type Listener ¶
type Listener interface {
Close(ctx context.Context) error
Connect(ctx context.Context) error
ListenToChannel(ctx context.Context, channel string) error
Ping(ctx context.Context) error
UnlistenToChannel(ctx context.Context, channel string) error
WaitForNotification(ctx context.Context) (*Notification, error)
}
Listener interface connects to the database and listen to a channel WaitForNotification blocks until receiving a notification or until the supplied context expires.
func NewListener ¶
type Notification ¶
type PostgresConfig ¶
type PostgresConfig struct {
Host string
Port int
Username string
Password string
Database string
SSLMode string
ConnectTimeout time.Duration
ApplicationName string
MaxConns int32
MinConns int32
MaxConnLifetime time.Duration
MaxConnIdleTime time.Duration
HealthCheckPeriod time.Duration
MaxRetries int
InitialRetryDelay time.Duration
BackoffMultiplier float64
MaxRetryDelay time.Duration
}
PostgresConfig holds database configuration parameters
func DefaultConfig ¶
func DefaultConfig() PostgresConfig
DefaultConfig returns a configuration with sensible defaults
type PostgresDatabase ¶
type PostgresDatabase struct {
// contains filtered or unexported fields
}
PostgresDatabase is the Postgres implementation of the database store.
func NewDatabase ¶
func NewDatabase(ctx context.Context, logger *slog.Logger, config PostgresConfig) (*PostgresDatabase, error)
NewDatabase creates a database connection pool and tests the connection.
func (*PostgresDatabase) Close ¶
func (db *PostgresDatabase) Close()
Close closes the connection pool gracefully
func (*PostgresDatabase) Ping ¶
func (db *PostgresDatabase) Ping(ctx context.Context) error
Ping tests the database connection
func (*PostgresDatabase) Pool ¶
func (db *PostgresDatabase) Pool() *pgxpool.Pool
Pool returns the underlying connection pool for direct access when needed
func (*PostgresDatabase) Stats ¶
func (db *PostgresDatabase) Stats() *pgxpool.Stat
Stats returns a copy of connection pool statistics