Documentation
¶
Overview ¶
Package datastore owns the Postgres pool, transactions, and health checks.
Index ¶
- Constants
- func Deref[T any](p *T) T
- func MapErr(err error, store string, notFound, duplicate error) error
- func Ptr[T any](v T) *T
- func TextPtr(t pgtype.Text) *string
- func TimePtr(t pgtype.Timestamptz) *time.Time
- func UserUUID(raw string) string
- func Wrap(store, op string, err error) error
- type Backend
- type ConnectionInfo
- type Executor
- type Options
- type Postgres
- func (p *Postgres) Close() error
- func (p *Postgres) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (p *Postgres) HealthCheck(ctx context.Context) error
- func (p *Postgres) Pool() *pgxpool.Pool
- func (p *Postgres) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (p *Postgres) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (p *Postgres) TestConnection(ctx context.Context) (*ConnectionInfo, error)
- func (p *Postgres) WithTx(ctx context.Context, fn func(Executor) error) error
- type Store
Constants ¶
View Source
const ( PgSearchPath = "public,internal,reference" PgTimezone = "UTC" )
Variables ¶
This section is empty.
Functions ¶
func Deref ¶
func Deref[T any](p *T) T
Deref returns the pointed value or its zero value when p is nil.
func TimePtr ¶
func TimePtr(t pgtype.Timestamptz) *time.Time
TimePtr converts an invalid timestamptz to nil.
Types ¶
type ConnectionInfo ¶
type ConnectionInfo struct {
Host string
Port uint16
Database string
User string
ServerVersion string
ServerVersionNum int64
Latency time.Duration
Stats *pgxpool.Stat
}
ConnectionInfo contains connection details and pool stats.
type Executor ¶
type Executor interface {
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}
Executor is the query surface for a pool or transaction.
type Options ¶
type Options struct {
// DSN is the connection string (postgresql:// or postgres://).
DSN string
// MaxConnections caps pool size; 0 keeps pgx/DSN default.
MaxConnections int32
// MinConnections keeps warm idle; 0 keeps pgx/DSN default.
MinConnections int32
// MaxConnLifetime bounds reuse; 0 keeps pgx/DSN default.
MaxConnLifetime time.Duration
// MaxConnIdleTime closes idle conns; 0 keeps pgx/DSN default.
MaxConnIdleTime time.Duration
}
Options configures the Postgres backend. Explicit pool values override DSN values.
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres is a pgx/v5 pool-backed Store.
func (*Postgres) HealthCheck ¶
HealthCheck reports whether the pool can reach the server.
func (*Postgres) TestConnection ¶
func (p *Postgres) TestConnection(ctx context.Context) (*ConnectionInfo, error)
TestConnection queries the server and returns connection details.
Click to show internal directories.
Click to hide internal directories.