Documentation ¶
Overview ¶
Package pgm implements a Postgres module.
Index ¶
- Constants
- func NewInitializer(migCfg *MigrationsConfig) injectz.Initializer
- func NewSingletonInjector(pg RawPG) injectz.Injector
- func Wrap0(ctx context.Context, name string, f func(ctx context.Context) error, ...) error
- func Wrap1[T any](ctx context.Context, name string, f func(ctx context.Context) (T, error), ...) (T, error)
- func Wrap2[T1 any, T2 any](ctx context.Context, name string, f func(ctx context.Context) (T1, T2, error), ...) (T1, T2, error)
- func Wrap3[T1 any, T2 any, T3 any](ctx context.Context, name string, ...) (T1, T2, T3, error)
- type BeginAccessMode
- type BeginIsoLevel
- type BeginOption
- type MigrationsConfig
- type PG
- type PGConfig
- type PGConfigMixin
- type RawPG
Constants ¶
const ( BeginIsoLevelSerializable = BeginIsoLevel(pgx.Serializable) BeginIsoLevelRepeatableRead = BeginIsoLevel(pgx.RepeatableRead) BeginIsoLevelReadCommitted = BeginIsoLevel(pgx.ReadCommitted) BeginIsoLevelReadUncommitted = BeginIsoLevel(pgx.ReadUncommitted) )
Known BeginIsoLevel values.
const ( BeginAccessModeReadWrite = BeginAccessMode(pgx.ReadWrite) BeginAccessModeReadOnly = BeginAccessMode(pgx.ReadOnly) )
Known BeginAccessMode values.
Variables ¶
This section is empty.
Functions ¶
func NewInitializer ¶
func NewInitializer(migCfg *MigrationsConfig) injectz.Initializer
NewInitializer returns a new injectz.Initializer that applies the given migrations (if any).
func NewSingletonInjector ¶
NewSingletonInjector injects.
func Wrap0 ¶
func Wrap0( ctx context.Context, name string, f func(ctx context.Context) error, options ...BeginOption) error
Wrap0 wraps a function that returns (error) in a transaction, retrying it if needed.
func Wrap1 ¶
func Wrap1[T any]( ctx context.Context, name string, f func(ctx context.Context) (T, error), options ...BeginOption) (T, error)
Wrap1 wraps a function that returns (T, error) in a transaction, retrying it if needed.
Types ¶
type BeginAccessMode ¶
type BeginAccessMode pgx.TxAccessMode
BeginAccessMode describes an access mode.
func (BeginAccessMode) Apply ¶
func (a BeginAccessMode) Apply(o *beginOptions)
Apply implements the BeginOption interface.
type BeginIsoLevel ¶
type BeginIsoLevel pgx.TxIsoLevel
BeginIsoLevel describes an isolation level.
func (BeginIsoLevel) Apply ¶
func (i BeginIsoLevel) Apply(o *beginOptions)
Apply implements the BeginOption interface.
type BeginOption ¶
type BeginOption interface {
Apply(o *beginOptions)
}
BeginOption describes an option.
type MigrationsConfig ¶ added in v0.4.0
MigrationsConfig describes the configuration for migrations.
type PG ¶
type PG interface { Exec(name, query string, args ...any) (pgconn.CommandTag, error) Query(name, query string, args ...any) (pgx.Rows, error) QueryRow(name, query string, args ...any) pgx.Row Begin(name string, options ...BeginOption) (context.Context, func(), func() error, error) }
PG describes the module (with cached context).
type PGConfig ¶
type PGConfig struct {
PostgresURL string `env:"PG_POSTGRES_URL,required" validate:"required,url"`
}
PGConfig describes the module configuration.
func (*PGConfig) GetPGConfig ¶
GetPGConfig implements the PGConfigMixin interface.
type PGConfigMixin ¶
PGConfigMixin describes the module configuration.
type RawPG ¶
type RawPG interface { Exec(ctx context.Context, name, query string, args ...any) (pgconn.CommandTag, error) Query(ctx context.Context, name, query string, args ...any) (pgx.Rows, error) QueryRow(ctx context.Context, name, query string, args ...any) pgx.Row Begin(ctx context.Context, name string, options ...BeginOption) (context.Context, func(), func() error, error) }
RawPG describes the module.
func NewPGFromPool ¶
NewPGFromPool initializes a new RawPG using the given *pgxpool.Pool.