stdxgit.sr.ht/~pingoo/stdx/sqlitex Index | Files

package sqlitex

import "git.sr.ht/~pingoo/stdx/sqlitex"

Index

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func Open

func Open(file string, options *DBOptions) (db *DB, err error)

func (*DB) Close

func (db *DB) Close() (err error)

func (*DB) Exec

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

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (*DB) Get

func (db *DB) Get(ctx context.Context, dest any, query string, args ...any) error

Get a single record. Any placeholder parameters are replaced with supplied args. An `ErrNoRows` error is returned if the result set is empty.

func (*DB) Query

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

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func (*DB) Select

func (db *DB) Select(ctx context.Context, dest any, query string, args ...any) error

Select an array of records. Any placeholder parameters are replaced with supplied args.

func (*DB) Transaction

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

type DBOptions

type DBOptions struct {
	BusyTimeout int64
}

type Queryer

type Queryer interface {
	Get(ctx context.Context, dest any, query string, args ...any) error
	Select(ctx context.Context, dest any, query string, args ...any) error
	Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
}

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Transaction is wrapper of `sqlx.Tx` which implements `Tx`

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits the transaction.

func (*Tx) Exec

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

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (*Tx) Get

func (tx *Tx) Get(ctx context.Context, dest any, query string, args ...any) error

Get a single record. Any placeholder parameters are replaced with supplied args. An `ErrNoRows` error is returned if the result set is empty.

func (*Tx) Query

func (tx *Tx) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback aborts the transaction.

func (*Tx) Select

func (tx *Tx) Select(ctx context.Context, dest any, query string, args ...any) error

Select an array of records. Any placeholder parameters are replaced with supplied args.

Source Files

db.go

Version
v0.0.0-20240218134121-094174641f6e (latest)
Published
Feb 18, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
4 months ago

Tools for package owners.