database

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (result sql.Result, err error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Transaction, error)
	Conn(ctx context.Context) (*sql.Conn, error)
	Close() error
}

func NewPrepared

func NewPrepared[T Transaction](db Wrapped[T]) Interface

NewPrepared creates a new Interface that wraps the given database and uses a prepare cache to reduce the number of prepare calls. The cache is only used when calling ExecContext and QueryContext methods on the main instance or in a transaction.

type Transaction

type Transaction interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (result sql.Result, err error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
	Commit() error
	Rollback() error
}

type Wrapped

type Wrapped[T Transaction] interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (result sql.Result, err error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (T, error)
	Conn(ctx context.Context) (*sql.Conn, error)
	Close() error
}

Jump to

Keyboard shortcuts

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