Documentation
¶
Index ¶
- Variables
- func BulkInsertStructs[T any](ctx context.Context, p *Postgres, tableName string, columns []string, ...) (int64, error)
- func ForceMigrationVersion(dbURI, source string, version int) error
- func IsRetryableError(err error, retryableCodes []string) bool
- func MigrateDown(dbURI, source string) error
- func MigrateSteps(dbURI, source string, steps int) error
- func MigrateUp(dbURI, source string) error
- func RunMigration(dbURI, source string) error
- func WithRetry(ctx context.Context, config RetryConfig, fn RetryableFunc) error
- type Config
- type DBPool
- type HealthCheckOption
- type HealthCheckOptions
- type MigrationVersion
- type PoolStats
- type Postgres
- func (p *Postgres) BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]any) (int64, error)
- func (p *Postgres) GetPoolStats() (*PoolStats, error)
- func (p *Postgres) HealthCheck(ctx context.Context, opts ...HealthCheckOption) error
- func (p *Postgres) IsHealthy(ctx context.Context) bool
- func (p *Postgres) Name() string
- func (p *Postgres) Start(ctx context.Context) error
- func (p *Postgres) Stop() error
- func (p *Postgres) WithReadOnlyTransaction(ctx context.Context, fn TxFunc) error
- func (p *Postgres) WithRepeatableReadTransaction(ctx context.Context, fn TxFunc) error
- func (p *Postgres) WithRetryTx(ctx context.Context, config RetryConfig, fn TxFunc) error
- func (p *Postgres) WithRetryTxDefault(ctx context.Context, fn TxFunc) error
- func (p *Postgres) WithSerializableTransaction(ctx context.Context, fn TxFunc) error
- func (p *Postgres) WithTransaction(ctx context.Context, fn TxFunc) error
- func (p *Postgres) WithTransactionOptions(ctx context.Context, txOptions pgx.TxOptions, fn TxFunc) error
- type RetryConfig
- type RetryableFunc
- type TxFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrHealthCheckTimeout = errors.New("postgres: health check timeout") ErrNoActiveConnections = errors.New("postgres: no active connections in pool") )
View Source
var ( ErrConnectionPoolNil = errors.New("postgres: connection pool is nil") ErrConfigNil = errors.New("postgres: configuration must not be nil") )
View Source
var ( ErrDBPoolCastFailed = errors.New("postgres: unable to cast DBPool to *pgxpool.Pool") ErrBeginTxFailed = errors.New("postgres: failed to begin transaction") ErrTxRollbackFailed = errors.New("postgres: transaction rollback failed") ErrTxRolledBack = errors.New("postgres: transaction rolled back") ErrTxCommitFailed = errors.New("postgres: failed to commit transaction") )
Functions ¶
func BulkInsertStructs ¶
func ForceMigrationVersion ¶
func IsRetryableError ¶
func MigrateDown ¶
func MigrateSteps ¶
func RunMigration ¶
func WithRetry ¶
func WithRetry(ctx context.Context, config RetryConfig, fn RetryableFunc) error
Types ¶
type Config ¶
type Config struct {
URL string
MaxConnection int32
MinConnection int32
MaxConnectionIdleTime time.Duration
MaxConnectionLifetime time.Duration
HealthCheckPeriod time.Duration
ConnectTimeout time.Duration
LogLevel tracelog.LogLevel
StatementTimeout time.Duration
LockTimeout time.Duration
IdleInTransactionTimeout time.Duration
}
type DBPool ¶
type DBPool interface {
pgxscan.Querier
SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
Begin(ctx context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
Ping(ctx context.Context) error
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Close()
}
type HealthCheckOption ¶
type HealthCheckOption func(*HealthCheckOptions)
func WithCustomHealthCheckSQL ¶
func WithCustomHealthCheckSQL(sql string) HealthCheckOption
func WithHealthCheckTimeout ¶
func WithHealthCheckTimeout(timeout time.Duration) HealthCheckOption
func WithMinIdleConns ¶
func WithMinIdleConns(minConns int32) HealthCheckOption
func WithRequireActiveConns ¶
func WithRequireActiveConns() HealthCheckOption
type HealthCheckOptions ¶
type MigrationVersion ¶
func GetMigrationVersion ¶
func GetMigrationVersion(dbURI, source string) (*MigrationVersion, error)
type Postgres ¶
type Postgres struct {
DBPool
}
func (*Postgres) BulkInsert ¶
func (*Postgres) GetPoolStats ¶
func (*Postgres) HealthCheck ¶
func (p *Postgres) HealthCheck(ctx context.Context, opts ...HealthCheckOption) error
func (*Postgres) WithReadOnlyTransaction ¶
func (*Postgres) WithRepeatableReadTransaction ¶
func (*Postgres) WithRetryTx ¶
func (*Postgres) WithRetryTxDefault ¶
func (*Postgres) WithSerializableTransaction ¶
func (*Postgres) WithTransaction ¶
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
RetryableErrs []string
}
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
type RetryableFunc ¶
Click to show internal directories.
Click to hide internal directories.