db

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverPostgres = "postgres"
)

Variables

View Source
var (
	ErrNotFound        = errors.New("database record not found")
	ErrLastActiveAdmin = errors.New("team must retain at least one active admin")
	// ErrCommitOutcomeUnknown means a transaction's COMMIT acknowledgement was
	// lost. Callers that would perform destructive compensation must reconcile
	// an idempotency/publication key on a fresh connection first.
	ErrCommitOutcomeUnknown = errors.New("database transaction commit outcome is unknown")
)

Functions

func DSN

func DSN(cfg config.PostgresConfig) string

DSN builds a PostgreSQL connection string from config.

func DriverFromConfig

func DriverFromConfig(cfg config.Config) string

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is a PostgreSQL UNIQUE constraint violation.

func MigrationsFSForConfig

func MigrationsFSForConfig(cfg config.Config, embedded fs.FS) (fs.FS, error)

func Open

func Open(ctx context.Context, cfg config.Config) (*pgxpool.Pool, error)

func OpenPostgres

func OpenPostgres(ctx context.Context, cfg config.PostgresConfig) (*pgxpool.Pool, error)

func OpenPostgresDSN

func OpenPostgresDSN(ctx context.Context, dsn string) (*pgxpool.Pool, error)

OpenPostgresDSN opens a pool from a raw libpq DSN with the default-team AfterConnect hook installed. Single-team test harnesses use this so their pools bind the team GUC exactly like production.

func ParseUUID

func ParseUUID(id string) (pgtype.UUID, error)

ParseUUID converts a string UUID to pgtype.UUID.

func ParseUUIDOrEmpty

func ParseUUIDOrEmpty(id string) pgtype.UUID

ParseUUIDOrEmpty converts a string UUID to pgtype.UUID, returning an invalid UUID if the string is empty or unparsable.

func RunMigrate

func RunMigrate(logger *slog.Logger, cfg config.PostgresConfig, migrationsFS fs.FS, command string, args []string) error

RunMigrate applies or rolls back database migrations. The migrationsFS should contain .sql files at its root (not in a subdirectory). Supported commands: "up", "down", "version", "force N".

func RunMigrateConfig

func RunMigrateConfig(logger *slog.Logger, cfg config.Config, migrationsFS fs.FS, command string, args []string) error

func RunMigrateTarget

func RunMigrateTarget(logger *slog.Logger, target MigrationTarget, migrationsFS fs.FS, command string, args []string) error

func SetDefaultTeamOnConnect

func SetDefaultTeamOnConnect(ctx context.Context, conn *pgx.Conn) error

SetDefaultTeamOnConnect is a pgxpool AfterConnect hook that binds the singleton team GUC (memoh.team_id) at the session level. It is exported so single-team test harnesses can install it on their own pools, matching the production connection setup.

func TextToString

func TextToString(value pgtype.Text) string

TextToString returns the string value of pgtype.Text, or "" when invalid.

func TimeFromPg

func TimeFromPg(value pgtype.Timestamptz) time.Time

TimeFromPg converts a pgtype.Timestamptz to time.Time.

Types

type MigrationStatus

type MigrationStatus struct {
	Version uint
	Dirty   bool
}

func ReadMigrationStatus

func ReadMigrationStatus(cfg config.PostgresConfig, migrationsFS fs.FS) (MigrationStatus, error)

func ReadMigrationStatusConfig

func ReadMigrationStatusConfig(cfg config.Config, migrationsFS fs.FS) (MigrationStatus, error)

func ReadMigrationStatusTarget

func ReadMigrationStatusTarget(target MigrationTarget, migrationsFS fs.FS) (MigrationStatus, error)

type MigrationTarget

type MigrationTarget struct {
	Driver string
	DSN    string
}

func MigrationTargetFromConfig

func MigrationTargetFromConfig(cfg config.Config) (MigrationTarget, error)

Directories

Path Synopsis
postgres

Jump to

Keyboard shortcuts

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