storage

package
v0.9.6 Latest Latest
Warning

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

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

Documentation

Overview

Package storage owns the Postgres connection pool and runs migrations.

In the new arch the catalog "domain repos" that used to live here moved out: each `app/X.Store` constructs its own sqlc-backed queries via `gen.New(pool)` against the pool surfaced by Storage.Pool(). Storage's remaining job is composition-root plumbing — open, ping, hand out the pool, close.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolOption added in v0.9.3

type PoolOption func(*poolSettings)

PoolOption tunes the connection pool. A zero/negative value is ignored, so callers can pass config knobs directly and unset ones keep the defaults.

func WithMaxConns added in v0.9.3

func WithMaxConns(n int) PoolOption

WithMaxConns overrides the pool's maximum connections (ignored if n <= 0).

func WithMinConns added in v0.9.3

func WithMinConns(n int) PoolOption

WithMinConns overrides the pool's warm-floor connections (ignored if n <= 0). A higher floor keeps connections pre-established, so bursty load never pays cold-connection (dial + DNS) latency on the request path.

type Storage

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

Storage is the data-access handle the composition root passes around.

func Open

func Open(ctx context.Context, dsn string, opts ...PoolOption) (*Storage, error)

Open opens a connection pool, runs pending migrations, and returns a ready-to-use *Storage. The returned Storage must be closed with Close when no longer needed. Pool sizing defaults to MaxConns 10 / MinConns 2; pass WithMaxConns / WithMinConns to override.

func WrapPool

func WrapPool(pool *pgxpool.Pool) *Storage

WrapPool wraps an existing *pgxpool.Pool into a *Storage without opening a new pool or running migrations. Intended for tests that supply their own pool. The returned Storage must NOT be closed — the caller owns the pool's lifetime.

func (*Storage) Close

func (s *Storage) Close()

Close releases the connection pool.

func (*Storage) Ping

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

Ping checks database connectivity.

func (*Storage) Pool

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

Pool returns the underlying pgxpool. Composition-root use only — domain code reaches Postgres via its own typed Store packages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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