db

package
v0.0.0-...-347e25e Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context) error

Load initializes the database connection.

Types

type Provider

type Provider interface {
	PrepareContext(ctx context.Context, query string) (Stmt, error)
	ExecContext(ctx context.Context, query string, args ...any) (Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) Row
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
}

Provider is an interface that wraps the standard sql.DB interface.

var (
	// Connection - Initialized database connection.
	Connection Provider

	// ErrNoRows decouples dependency on sql package.
	ErrNoRows = sql.ErrNoRows
)

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Row

type Row interface {
	Scan(dest ...any) error
	Err() error
}

func NewRowWrap

func NewRowWrap(r *sql.Row) Row

type Rows

type Rows interface {
	Next() bool
	Scan(dest ...any) error
	Err() error
	Close() error
}

func NewRowsWrap

func NewRowsWrap(r *sql.Rows) Rows

type Stmt

type Stmt interface {
	QueryContext(ctx context.Context, args ...any) (Rows, error)
	QueryRowContext(ctx context.Context, args ...any) Row
	ExecContext(ctx context.Context, args ...any) (Result, error)
	Close() error
}

type Tx

type Tx interface {
	StmtContext(ctx context.Context, query string) (Stmt, error)
	Commit() error
	Rollback() error
}

Jump to

Keyboard shortcuts

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