sqldb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxConflict = errors.New("Transaction conflict")
	ErrNoRows     = errors.New("No matching rows in the database")
)

Functions

func ChkExec

func ChkExec(res sql.Result, err error, want int64, info string) error

func ChkExecDiffError

func ChkExecDiffError(res sql.Result, err, diffErr error, want int64) error

Similar to ChkExec() but returns the given "diff error" when the number of rows affected is different from the desired number. This allows the caller to distinguish between the error cases.

func ChkQueryRow

func ChkQueryRow(err error) (bool, error)

func InClause

func InClause(column string, num, start int) string

Return the IN-clause of a SQL query based on the column name, the number of its values and their starting position, e.g. "status IN ($3, $4, $5)"

Types

type Db

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

func NewDb

func NewDb(driver, info string, poolSize int) (*Db, error)

func (*Db) Close

func (d *Db) Close()

func (*Db) Exec

func (d *Db) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Db) OpenTransaction

func (d *Db) OpenTransaction() (*DbTx, error)

func (*Db) Query

func (d *Db) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*Db) QueryRow

func (d *Db) QueryRow(query string, args ...interface{}) *sql.Row

func (*Db) Transactional

func (d *Db) Transactional(callback TxFunc, args ...interface{}) error

type DbTx

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

func (*DbTx) Commit

func (t *DbTx) Commit() error

func (*DbTx) ConvertError

func (t *DbTx) ConvertError(err error) error

func (*DbTx) Discard

func (t *DbTx) Discard()

func (*DbTx) Exec

func (t *DbTx) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DbTx) Query

func (t *DbTx) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*DbTx) QueryRow

func (t *DbTx) QueryRow(query string, args ...interface{}) *sql.Row

type SqlStorage

type SqlStorage interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type TxFunc

type TxFunc func(tx *DbTx, args ...interface{}) error

Jump to

Keyboard shortcuts

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