database

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package database provides database connection management and utilities.

Package database provides database connection management and utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

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

Connect establishes a database connection with the given configuration. It sets connection pool settings and verifies the connection with a ping.

Types

type Config

type Config struct {
	Driver             string        // Database driver name (e.g., "postgres", "mysql").
	ConnectionString   string        // Connection string for the database.
	MaxOpenConnections int           // Maximum number of open connections to the database.
	MaxIdleConnections int           // Maximum number of idle connections in the pool.
	ConnMaxLifetime    time.Duration // Maximum amount of time a connection may be reused.
}

Config holds database configuration settings.

type Querier

type Querier interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier represents a database query executor (either *sql.DB or *sql.Tx).

func GetTx

func GetTx(ctx context.Context, db *sql.DB) Querier

GetTx retrieves a transaction from context, or returns the DB connection.

type TxManager

type TxManager interface {
	WithTx(ctx context.Context, fn func(ctx context.Context) error) error
}

TxManager manages database transactions.

func NewTxManager

func NewTxManager(db *sql.DB) TxManager

NewTxManager creates a new TxManager for the given database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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