store

package
v0.6.1000-dev.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package store owns PostgreSQL access: the pgx pool, goose migrations, and sqlc-generated typed queries. All SQL lives here; no other package builds SQL strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, databaseURL string) error

Migrate runs all pending goose migrations from the embedded FS. Safe to run concurrently within a process (migrateMu) and across processes/instances (a Postgres session advisory lock held for the whole run): waiters block until the leader finishes, then observe an up-to-date schema and no-op. This matters at first boot — api, git and worker replicas all start with migrateOnStart — and for test binaries sharing one database. Locking lives here, not in goose, because goose's own lock does not cover the version-table bootstrap: on a fresh database two concurrent migrators raced through it and collided inside the first migrations.

func MigrateExtension

func MigrateExtension(ctx context.Context, databaseURL, name string, fsys fs.FS) error

MigrateExtension runs an extension's goose migrations (pkg/extension) under the extension's own version table (ent_<name>_goose_version), so the core's numbering and an extension's never collide; the SQL owns its schema (CREATE SCHEMA IF NOT EXISTS ent_<name>). Same in-process mutex as Migrate and a per-extension advisory lock, for the same reasons.

func MigrationStatus

func MigrationStatus(ctx context.Context, databaseURL string) (int64, error)

MigrationStatus returns the current goose version (diagnostics).

Types

type Store

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

Store wraps the connection pool. Domain packages depend on Store, never on pgx directly, so the tenancy helpers have one place to live.

func Connect

func Connect(ctx context.Context, databaseURL string) (*Store, error)

Connect opens a pgx pool and verifies connectivity.

func (*Store) Close

func (s *Store) Close()

Close releases the pool.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping verifies database connectivity (readyz).

func (*Store) Pool

func (s *Store) Pool() *pgxpool.Pool

Pool exposes the underlying pool for sqlc-generated code and tests.

func (*Store) Queries

func (s *Store) Queries() *storegen.Queries

Queries returns the sqlc query layer bound to the pool.

func (*Store) WithPgxTx

func (s *Store) WithPgxTx(ctx context.Context, fn func(tx pgx.Tx, q *storegen.Queries) error) error

WithPgxTx is WithTx that also hands fn the transaction itself, for a step that is not a generated query: an extension's own writes in the core's erasure (pkg/extension.ErasesAccounts).

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(q *storegen.Queries) error) error

WithTx runs fn inside a transaction, passing transaction-bound queries. Commit on nil, rollback on error or panic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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