fixsql

package module
v0.0.0-...-3a15ba3 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2014 License: MIT Imports: 2 Imported by: 0

README

fixsql

A wrapper around the go database/sql library with better error reporting

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each(rows *sql.Rows, fn func() (dest []interface{})) (num int, err error)

Each scans through all rows and calls fn to get the destinations It stopps on the first error, returning the number of succellfully scanned rows and the first error. Each makes sure the given rows are closed, so that there is no leakage

func Exec

func Exec(x Execer, query string, args ...interface{}) (res sql.Result, err error)

runs *database/sql.DB.Exec() and returns the result The returned errors are typed, so that an error caused by a closed database returns an error of type ConnectionClosed and every other error is of type InvalidStatement

func MustOpen

func MustOpen(driverName, dataSourceName string) (db *sql.DB)

func Open

func Open(driverName, dataSourceName string) (db *sql.DB, err error)

Open runs database/sql.Open and returns it result. The returned errors are typed and a Ping is run, so that an error of type UnknownDriver is returned, if the given driverName is not registered and an error of type ConnectionError is returned, if a connection could not be established (Ping fails)

func Prepare

func Prepare(p Preparer, query string) (st *sql.Stmt, err error)

runs *database/sql.DB.Prepare() and returns the result The returned errors are typed, so that an error caused by a closed database returns an error of type ConnectionClosed and every other error is of type InvalidStatement

func Query

func Query(q Queryer, query string, args ...interface{}) (rows *sql.Rows, err error)

runs *database/sql.DB.Query() and returns the result The returned errors are typed, so that an error caused by a closed database returns an error of type ConnectionClosed and every other error is of type InvalidStatement

func QueryEach

func QueryEach(q Queryer, fn func() (dest []interface{}), query string, args ...interface{}) (num int, err error)

runs a query and iterates through each result

func Transaction

func Transaction(db *sql.DB, fns ...func(DB) error) error

Transaction creates a transaction and calls every given function on it. If a function returns an error the transaction is rolled back and the error is returned. If every function did return without error, the transaction is committed

Types

type ConnectionClosed

type ConnectionClosed struct{}

func (ConnectionClosed) Error

func (ce ConnectionClosed) Error() string

type ConnectionError

type ConnectionError string

func (ConnectionError) Error

func (ce ConnectionError) Error() string

type DB

type DB interface {
	Preparer
	Queryer
	Execer
}

type Execer

type Execer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

type InvalidStatement

type InvalidStatement string

func (InvalidStatement) Error

func (i InvalidStatement) Error() string

type Preparer

type Preparer interface {
	Prepare(query string) (*sql.Stmt, error)
}

type Queryer

type Queryer interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

type ScanError

type ScanError string

func (ScanError) Error

func (s ScanError) Error() string

type UnknownDriver

type UnknownDriver string

func (UnknownDriver) Error

func (u UnknownDriver) Error() string

Jump to

Keyboard shortcuts

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