postgres

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package postgres is a thin database resource adapter.

It uses database/sql (or any Pinger) via injection — the ShiftLock module does not require pgx. Fencing is advertised only when a Fencer is supplied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ID          resource.ResourceID
	DB          Pinger // typically *sql.DB
	DisplayName string
	Schema      SchemaVersioner
	Fencer      Fencer
	Drainer     Drainer
	// PingTimeout bounds Health ping; zero uses 3s.
	PingTimeout time.Duration
}

Config configures the adapter.

type Drainer

type Drainer interface {
	Drain(ctx context.Context) error
	Ready(ctx context.Context) error
}

Drainer optionally supports connection/drain readiness.

type Fencer

type Fencer interface {
	Check(ctx context.Context, token uint64) error
}

Fencer optionally enforces fencing tokens on mutations. When nil, Capabilities.SupportsFencing is false.

type Pinger

type Pinger interface {
	PingContext(ctx context.Context) error
}

Pinger is the minimal health dependency (sql.DB satisfies it).

func OpenSQL

func OpenSQL(db *sql.DB) Pinger

OpenSQL is a helper documenting that callers open *sql.DB themselves. ShiftLock does not open connections or parse DSNs containing secrets.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource implements resource.Resource for PostgreSQL (or any SQL DB).

func New

func New(cfg Config) (*Resource, error)

New validates config and returns a Resource.

func (*Resource) Capabilities

func (r *Resource) Capabilities() resource.ResourceCapabilities

Capabilities never advertises fencing unless a Fencer is configured.

func (*Resource) CheckFence

func (r *Resource) CheckFence(ctx context.Context, token uint64) error

CheckFence validates a fencing token when a Fencer is configured.

func (*Resource) Describe

func (r *Resource) Describe() resource.Description

Describe implements resource.Resource.

func (*Resource) Drain

func (r *Resource) Drain(ctx context.Context) error

Drain marks the resource as draining. If a Drainer is set, it is invoked.

func (*Resource) Health

Health pings the database and reports connectivity.

func (*Resource) ID

func (r *Resource) ID() resource.ResourceID

ID implements resource.Resource.

func (*Resource) Kind

func (r *Resource) Kind() resource.Kind

Kind implements resource.Resource.

func (*Resource) Ready

func (r *Resource) Ready(ctx context.Context) error

Ready reports whether the resource may accept work.

func (*Resource) SchemaVersion

func (r *Resource) SchemaVersion(ctx context.Context) (string, error)

SchemaVersion returns the hooked schema version, if configured.

func (*Resource) Snapshot

func (r *Resource) Snapshot(ctx context.Context) (map[string]string, error)

Snapshot returns a sanitized operational snapshot (no credentials).

type SchemaVersioner

type SchemaVersioner interface {
	SchemaVersion(ctx context.Context) (string, error)
}

SchemaVersioner optionally reports an application schema version.

Jump to

Keyboard shortcuts

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