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 ¶
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.
ConnMaxIdleTime time.Duration // Maximum amount of time a connection may be idle.
}
Config holds database configuration settings.
type Querier ¶
type Querier interface {
// ExecContext executes a query without returning any rows.
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
// QueryContext executes a query that returns rows, typically a SELECT.
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
// QueryRowContext executes a query that is expected to return at most one row.
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
Querier represents a database query executor (either *sql.DB or *sql.Tx).
type TxManager ¶
type TxManager interface {
// WithTx executes the function within a database transaction.
// If a transaction is already present in the context, it reuses it.
WithTx(ctx context.Context, fn func(ctx context.Context) error) error
}
TxManager manages database transactions.
func NewTxManager ¶
NewTxManager creates a new TxManager for the given database.
Click to show internal directories.
Click to hide internal directories.