package pg

import "golazy.dev/pg"

Package pg contains PostgreSQL helpers shared by concrete GoLazy PostgreSQL backends and applications.

Most GoLazy applications install the conventional pool and migration wiring with:

lazy add postgres

Applications with custom lifecycle requirements can open and attach the application-owned pool directly:

pool, err := pg.OpenEnv(ctx)
if err != nil {
	return err
}
defer pool.Close()
ctx = pg.WithPool(ctx, pool)

Backend packages such as pgauth, pgmigrate, pgjobs, and other pg/* implementations can then share that pool with pg.FromContext.

Functions

func AddonDefinition

AddonDefinition returns a copy of the named definition from this module's embedded lazyaddon.toml manifest. Add-on packages use it to keep runtime registration aligned with the distribution manifest.

func AddonDefinition(id string) (lazyaddon.Definition, bool)

func FromContext

FromContext returns the PostgreSQL pool carried by ctx.

func FromContext(ctx context.Context) (*pgxpool.Pool, bool)

func Open

Open creates a pgx pool for databaseURL.

func Open(ctx context.Context, databaseURL string) (*pgxpool.Pool, error)

func OpenEnv

OpenEnv creates a pgx pool from the first non-empty environment variable in names. If names is empty, DATABASE_URL is used.

func OpenEnv(ctx context.Context, names ...string) (*pgxpool.Pool, error)

func WithPool

WithPool returns a context carrying pool.

func WithPool(ctx context.Context, pool *pgxpool.Pool) context.Context

Directories

PathSynopsis
pg/addon/postgresPackage postgres registers the base PostgreSQL add-on for GoLazy apps.
pg/addon/postgres/jobsPackage jobs registers the PostgreSQL-backed jobs add-on for GoLazy apps.
pg/pgauthPackage pgauth provides a PostgreSQL-backed lazyauth.Authenticator.
pg/pgfilesPackage pgfiles implements a PostgreSQL repository for golazy.dev/lazyfiles.
pg/pgjobsPackage pgjobs implements a PostgreSQL backend for golazy.dev/lazyjobs.
pg/pgmediaPackage pgmedia implements a PostgreSQL repository for golazy.dev/lazymedia.
pg/pgmigratePackage pgmigrate implements PostgreSQL migrations for golazy.dev/lazymigrate.
pg/pgstoragePackage pgstorage implements a PostgreSQL object store for golazy.dev/lazystorage.
pg/withpgPackage withpg starts embedded PostgreSQL servers for local development and integration tests.
pg/withpg/cmd/withpg