Documentation
¶
Overview ¶
Package db manages database connectivity, migrations, and sqlc-generated queries.
Package db manages database connectivity, migrations, and sqlc-generated queries.
Index ¶
- Variables
- func Connect(ctx context.Context, cfg Config) (*pgxpool.Pool, error)
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- func MigrateDown(ctx context.Context, pool *pgxpool.Pool) error
- func MigrationVersion(ctx context.Context, pool *pgxpool.Pool) (int64, error)
- func Ping(ctx context.Context, pool *pgxpool.Pool, timeout time.Duration) error
- type Config
- type Pool
Constants ¶
This section is empty.
Variables ¶
var MigrationFS embed.FS
MigrationFS holds the embedded SQL migration files. It is populated during init() from the migrations package.
Functions ¶
func Connect ¶
Connect creates and validates a pgxpool connection pool. The pool is configured with the provided Config and verified with a ping.
func Migrate ¶
Migrate runs all pending goose migrations against the given pool. It wraps the pgxpool with the stdlib adapter that goose requires.
func MigrateDown ¶
MigrateDown rolls back the most recent migration batch.
func MigrationVersion ¶
MigrationVersion returns the current schema version as reported by goose.
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 ¶
DefaultConfig returns a Config with sensible defaults for the given URL.