db

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

README

qdb

qdb is an SQL database wrapper that uses query structs for interacting with the underlying database. Any errors that a query produces are wrapped with the specific SQL query and arguments, making inspection and debugging easier.

Testing

qdb allows you to mock a database that responds to named queries with specific values. See the mockdb pacakge.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows      = sql.ErrNoRows
	ErrTxDone      = sql.ErrTxDone
	ErrAlreadyInTx = fmt.Errorf("tx: already in transaction")
)

Functions

func ExpectRowsAffected

func ExpectRowsAffected(res Result, countExpected int64, errIfNot error) (bool, error)

ExpectRowsAffected returns whether RowsAffected() succeeded, and an error if the count was not as expected.

Types

type DB

type DB interface {
	Query(ctx context.Context, query *Query) (Rows, error)
	QueryRow(ctx context.Context, query *Query) Row
	Exec(ctx context.Context, query *Query) (Result, error)
	Begin(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	Ping(ctx context.Context) error
}

func New

func New(driver string, uri string) (DB, error)

type Query

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

func NewQuery

func NewQuery(name string, query string, args ...interface{}) *Query

func (*Query) Name added in v1.1.0

func (q *Query) Name() string

func (*Query) String

func (q *Query) String() string

type QueryError

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

QueryError describes an error that occurred while processing the result of an SQL query, whether during query time or scan time.

func (*QueryError) Error

func (qErr *QueryError) Error() string

Error implements the error interface

func (*QueryError) QueryArgs

func (qErr *QueryError) QueryArgs() []interface{}

QueryArgs exposes the wrapped query arguments

func (*QueryError) QueryBody

func (qErr *QueryError) QueryBody() string

QueryBody exposes the wrapped query body

func (*QueryError) String

func (qErr *QueryError) String() string

String implements the Stringer interface. Simply returns Error().

func (*QueryError) Unwrap

func (qErr *QueryError) Unwrap() error

Unwrap implements the Wrapper interface

type Result

type Result sql.Result

type Row

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

type Rows

type Rows interface {
	io.Closer
	Scan(dest ...interface{}) error
	Next() bool
	Err() error
	Columns() ([]string, error)
}

type Tx

type Tx interface {
	DB
	Commit() error
	Rollback() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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