db

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package db manages database connectivity, migrations, and sqlc-generated queries.

Package db manages database connectivity, migrations, and sqlc-generated queries.

Index

Constants

This section is empty.

Variables

View Source
var MigrationFS embed.FS

MigrationFS holds the embedded SQL migration files. It is populated during init() from the migrations package.

Functions

func Connect

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

Connect creates and validates a pgxpool connection pool. The pool is configured with the provided Config and verified with a ping.

func Migrate

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

Migrate runs all pending goose migrations against the given pool. It wraps the pgxpool with the stdlib adapter that goose requires.

func MigrateDown

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

MigrateDown rolls back the most recent migration batch.

func MigrationVersion

func MigrationVersion(ctx context.Context, pool *pgxpool.Pool) (int64, error)

MigrationVersion returns the current schema version as reported by goose.

func Ping

func Ping(ctx context.Context, pool *pgxpool.Pool, timeout time.Duration) error

Ping verifies that the database is reachable within the given timeout.

Types

type Config

type Config struct {
	// URL is the full PostgreSQL connection string.
	URL             string
	MaxConns        int32
	MinConns        int32
	MaxConnLifetime time.Duration
	MaxConnIdleTime time.Duration
	HealthTimeout   time.Duration
}

Config holds database connection configuration.

func DefaultConfig

func DefaultConfig(url string) Config

DefaultConfig returns a Config with sensible defaults for the given URL.

type Pool

type Pool = pgxpool.Pool

Pool is an alias for pgxpool.Pool, re-exported for use by other packages.

Directories

Path Synopsis
Package adapters bridges the domain repository interfaces (auth, tickets, projects) to the sqlc-generated query layer.
Package adapters bridges the domain repository interfaces (auth, tickets, projects) to the sqlc-generated query layer.

Jump to

Keyboard shortcuts

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