sqlxdb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sqlxdb provides sqlx + PostgreSQL (pgx stdlib driver) helpers:

  • Connect with pool settings
  • WithTx for transactional work

Migrations are not handled here; use goose, atlas, or your tool of choice.

Usage:

db, err := sqlxdb.Connect(sqlxdb.Config{URL: os.Getenv("DATABASE_URL")})
if err != nil { ... }
defer db.Close()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg Config) (*sqlx.DB, error)

Connect opens a *sqlx.DB using driver name "pgx".

func WithTx

func WithTx(ctx context.Context, db *sqlx.DB, fn func(*sqlx.Tx) error) error

WithTx runs fn inside a transaction. Commits on nil error, rolls back otherwise.

Types

type Config

type Config struct {
	URL string

	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

Config holds database connection settings for PostgreSQL via pgx stdlib driver.

Jump to

Keyboard shortcuts

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