db

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoConnection = errors.New("database connection not initialized")
	ErrNoRows       = sql.ErrNoRows
)

Common errors

Functions

func ChangeConfig added in v0.1.2

func ChangeConfig(db *DB, c Config)

func QueryRow added in v0.1.2

func QueryRow[T any](ctx context.Context, db *DB, query string, scanner SingleRowScanner[T], args ...any) (T, error)

func QueryRows added in v0.1.2

func QueryRows[T any](ctx context.Context, db *DB, query string, scanner Scanner[T], args ...any) ([]T, error)

Types

type Config added in v0.1.2

type Config struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

Config represents database configuration

func DefaultConfig added in v0.1.2

func DefaultConfig() Config

DefaultConfig provides sensible defaults for database configuration

type DB added in v0.1.2

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB wraps sql.DB to provide additional functionality

func New added in v0.1.2

func New(source boiler.IOWithAuth) (*DB, error)

New creates a new database connection

func (*DB) Exec added in v0.1.2

func (db *DB) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a query that doesn't return rows (INSERT, UPDATE, DELETE)

func (*DB) Health added in v0.1.2

func (db *DB) Health(ctx context.Context) error

Health performs a health check on the database

func (*DB) Transaction added in v0.1.2

func (db *DB) Transaction(ctx context.Context, fn func(*sql.Tx) error) error

type Scanner added in v0.1.2

type Scanner[T any] func(*sql.Rows) (T, error)

type SingleRowScanner added in v0.1.2

type SingleRowScanner[T any] func(*sql.Row) (T, error)

Jump to

Keyboard shortcuts

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