pgm

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package pgm implements a Postgres module.

Index

Constants

View Source
const (
	BeginIsoLevelSerializable    = BeginIsoLevel(pgx.Serializable)
	BeginIsoLevelRepeatableRead  = BeginIsoLevel(pgx.RepeatableRead)
	BeginIsoLevelReadCommitted   = BeginIsoLevel(pgx.ReadCommitted)
	BeginIsoLevelReadUncommitted = BeginIsoLevel(pgx.ReadUncommitted)
)

Known BeginIsoLevel values.

View Source
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

func NewSingletonInjector(pg RawPG) injectz.Injector

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.

func Wrap2

func Wrap2[T1 any, T2 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, error),
	options ...BeginOption) (T1, T2, error)

Wrap2 wraps a function that returns (T1, T2, error) in a transaction, retrying it if needed.

func Wrap3

func Wrap3[T1 any, T2 any, T3 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, T3, error),
	options ...BeginOption) (T1, T2, T3, error)

Wrap3 wraps a function that returns (T1, T2, T3, 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

type MigrationsConfig struct {
	TableName string
	FS        embed.FS
}

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).

func MustGet

func MustGet(ctx context.Context) PG

MustGet extracts, panics if not found.

type PGConfig

type PGConfig struct {
	PostgresURL string `env:"PG_POSTGRES_URL,required" validate:"required,url"`
}

PGConfig describes the module configuration.

func (*PGConfig) Config

func (c *PGConfig) Config()

Config implements the cfgm.Config interface.

func (*PGConfig) GetPGConfig

func (c *PGConfig) GetPGConfig() *PGConfig

GetPGConfig implements the PGConfigMixin interface.

func (*PGConfig) ToEnv added in v0.3.0

func (c *PGConfig) ToEnv(prefix string) map[string]string

ToEnv converts the config to an env map.

type PGConfigMixin

type PGConfigMixin interface {
	cfgm.Config
	GetPGConfig() *PGConfig
}

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

func NewPGFromPool(pool *pgxpool.Pool) RawPG

NewPGFromPool initializes a new RawPG using the given *pgxpool.Pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL