sqlxchain

package module
v0.0.0-...-2b8956e Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2017 License: MIT Imports: 2 Imported by: 0

README

sqlxchain

A thin wrapper around sqlx for command chaining, as in the following simple example:

db, _ = sqlxchain.New("mysql", dns)

var now int64
var id int64

err := db.Context().Begin().
    Get(&now, "SELECT UNIX_TIMESTAMP()").
    Get(&id, "SELECT id FROM employee WHERE is_terrible=1 LIMIT 1").
    Exec("UPDATE employee SET terminated=? WHERE id=?", now, id).
    Commit().
    Err()

The error is propagated through each call. Once an error occurs, no other action is performed. If there was an error before Commit gets called, then Commit will perform a rollback.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbContext

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

func (*DbContext) Begin

func (d *DbContext) Begin() *DbContext

func (*DbContext) Commit

func (d *DbContext) Commit() *DbContext

func (*DbContext) Err

func (d *DbContext) Err() error

func (*DbContext) Exec

func (d *DbContext) Exec(query string, args ...interface{}) *DbContext

func (*DbContext) Get

func (d *DbContext) Get(
	dest interface{}, query string, args ...interface{}) *DbContext

func (*DbContext) LastInsertId

func (d *DbContext) LastInsertId(id *int64) *DbContext

func (*DbContext) LogErr

func (d *DbContext) LogErr(msg string, args ...interface{}) *DbContext

func (*DbContext) RowsAffected

func (d *DbContext) RowsAffected(n *int64) *DbContext

func (*DbContext) Select

func (d *DbContext) Select(
	dest interface{}, query string, args ...interface{}) *DbContext

type ErrorConvertFunc

type ErrorConvertFunc func(err error) error

type ErrorLogFunc

type ErrorLogFunc func(err error, format string, v ...interface{})

type SqlxChain

type SqlxChain struct {
	Db *sqlx.DB
	// contains filtered or unexported fields
}

SqlxChain is a thin wrapper around a sqlx.DB.

func New

func New(driver, dns string) (*SqlxChain, error)

func (*SqlxChain) Context

func (sc *SqlxChain) Context() *DbContext

func (*SqlxChain) ErrorConverter

func (sc *SqlxChain) ErrorConverter(f ErrorConvertFunc)

func (*SqlxChain) ErrorLogger

func (sc *SqlxChain) ErrorLogger(f ErrorLogFunc)

Jump to

Keyboard shortcuts

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