postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package postgres is the PostgreSQL storage backend on pgx in database/sql mode.

Why

Phase 4 of the plan of record promises the same storage contract on four backends, and PostgreSQL is the one the timing gate runs on: Clear on 100k queued rows must finish under a second (decision record 0012). This package supplies the Dialect that sqlcommon needs and nothing else: $n placeholders, FOR UPDATE row locks, ON CONFLICT upserts, and TIMESTAMPTZ columns. IsUniqueViolation maps driver errors to storage.ErrConflict.

All statement logic, migrations, and sealing live in sqlcommon; the contract is proven by storagetest, run against a real server through `make test-storage` (see `make testdb-up`).

References

Index

Constants

This section is empty.

Variables

View Source
var Dialect = sqlcommon.Dialect{
	Name:              "postgres",
	Dollar:            true,
	ForUpdate:         "FOR UPDATE",
	Upsert:            sqlcommon.UpsertOnConflict,
	Migrations:        sqlcommon.MustSub(migrationFS, "migrations"),
	InsertIgnore:      sqlcommon.InsertIgnoreOnConflict,
	IsUniqueViolation: IsUniqueViolation,
}

Dialect is the PostgreSQL dialect.

View Source
var ErrDSNRequired = errors.New("postgres: DSN is required")

ErrDSNRequired is returned by Open for an empty DSN.

Functions

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is a PostgreSQL unique violation.

Types

type Options

type Options struct {
	SkipMigrate bool
	Pool        sqlcommon.Pool
	// Keyring seals the secret columns (decision record 0013); nil keeps
	// them in plaintext.
	Keyring *crypt.Keyring
}

Options tune Open.

type Store

type Store struct{ *sqlcommon.Store }

Store is the PostgreSQL backend.

func Open

func Open(ctx context.Context, dsn string, o Options) (*Store, error)

Open connects with a pgx DSN or URL and migrates the schema. The DSN is parsed before any connection attempt, so a malformed one fails fast.

Jump to

Keyboard shortcuts

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