database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 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.

Types

type Config

type Config struct {
	Driver             string
	ConnectionString   string
	MaxOpenConnections int
	MaxIdleConnections int
	ConnMaxLifetime    time.Duration
}

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