database

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package database provides database connection management and configuration.

Package database provides database connection management and configuration.

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

Types

type Config

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

Config holds database configuration

type Querier added in v1.6.0

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 is an interface that represents a database query executor. It can be either *sql.DB or *sql.Tx

func GetTx

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

GetTx retrieves a transaction from context, or falls back to 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

Jump to

Keyboard shortcuts

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