Documentation ¶
Index ¶
- func AzureBeforeConnect(log logrus.FieldLogger) (func(ctx context.Context, config *pgx.ConnConfig) error, error)
- func ConnectPostgres(ctx context.Context, poolConfig *pgxpool.Config) (*pgx.Conn, error)
- func IsCode(err error, code string) bool
- func Retry[T any](ctx context.Context, log logrus.FieldLogger, f func() (T, error)) (T, error)
- func RetryIdempotent[T any](ctx context.Context, log logrus.FieldLogger, f func() (T, error)) (T, error)
- func RetryTx(ctx context.Context, log logrus.FieldLogger, db interface{ ... }, ...) error
- func SetupAndMigrate(ctx context.Context, log logrus.FieldLogger, db interface{ ... }, ...) error
- func TryEnsureDatabase(ctx context.Context, poolConfig *pgxpool.Config, log logrus.FieldLogger)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AzureBeforeConnect ¶
func AzureBeforeConnect(log logrus.FieldLogger) (func(ctx context.Context, config *pgx.ConnConfig) error, error)
AzureBeforeConnect will return a pgx BeforeConnect function suitable for Azure AD authentication. The returned function will set the password of the connection to a token for the relevant scope.
func ConnectPostgres ¶
ConnectPostgres will open a single connection to the "postgres" database in the database cluster specified in poolConfig.
func Retry ¶
Retry runs the closure potentially more than once, retrying quickly on serialization or deadlock errors, and backing off more on other retryable errors. It will not retry on network errors or other ambiguous errors after any data has been sent. It will retry unique constraint violation and exclusion constraint violations, so the closure should not rely on those for normal behavior.
func RetryIdempotent ¶
func RetryIdempotent[T any](ctx context.Context, log logrus.FieldLogger, f func() (T, error)) (T, error)
RetryIdempotent runs the closure potentially more than once, retrying quickly on serialization or deadlock errors, and backing off more on other errors. It assumes that f is idempotent, so it will retry even in ambiguous situations. It will retry unique constraint violation and exclusion constraint violations, so the closure should not rely on those for normal behavior.
func RetryTx ¶
func RetryTx( ctx context.Context, log logrus.FieldLogger, db interface { BeginTx(context.Context, pgx.TxOptions) (pgx.Tx, error) }, txOptions pgx.TxOptions, isIdempotent bool, f func(tx pgx.Tx) error, ) error
RetryTx runs a closure like Retry or RetryIdempotent, wrapped in pgx.BeginTxFunc.
func SetupAndMigrate ¶
func SetupAndMigrate( ctx context.Context, log logrus.FieldLogger, db interface { BeginTx(context.Context, pgx.TxOptions) (pgx.Tx, error) Exec(context.Context, string, ...any) (pgconn.CommandTag, error) }, tableName string, schemas []string, ) error
SetupAndMigrate sets up the database schema, applying the migrations in the schemas slice in order, starting from the first non-applied one. tableName is the name of a table used to hold schema version numbers.
func TryEnsureDatabase ¶
TryEnsureDatabase will connect to the "postgres" database and attempt to create the database named in the pool's configuration.
Types ¶
This section is empty.