sql

package module
v0.0.0-...-be3661f Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2017 License: MIT Imports: 9 Imported by: 0

README

go-x-sql

Improved sql package for go

TODO

No prepared statements?

No. They cause more problems than they're worth. See http://go-database-sql.org/prepared.html#avoiding-prepared-statements and http://go-database-sql.org/prepared.html#prepared-statements-in-transactions for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows       = sql.ErrNoRows
	ErrRowsAffected = errors.New("Affected unexpected number of rows")
)
View Source
var (
	Must     = must
	MustInt  = mustInt
	MustBool = mustBool

	CheckDest = checkDest
)
View Source
var (
	DbNameConventionCamelCase_Capitalized   = func(str string) string { return str }
	DbNameConventionCamelCase_uncapitalized = func(str string) string { return uncapitalize(str) }
	DbNameConvention_under_score            = func(str string) string { return camelCaseTo_under_score(str) }
	DbNameConventionUPPERCASE               = func(str string) string { return toUPPERCASE(str) }
	DbNameConventionUPPER_CASE_UNDER_SCORE  = func(str string) string { return toUPPERCASE(camelCaseTo_under_score(str)) }
)

Functions

func IsDuplicateEntryError

func IsDuplicateEntryError(err error) bool

Types

type API

type API interface {
	Select(dest interface{}, query string, args ...interface{}) error
	SelectOne(dest interface{}, query string, args ...interface{}) error
	SelectOneMaybe(dest interface{}, query string, args ...interface{}) (bool, error)
	InsertAndGetId(query string, args ...interface{}) (id int64, err error)
	InsertIgnoreId(query string, args ...interface{}) error
	InsertIgnoreDuplicate(query string, args ...interface{}) (bool, error)
	Update(query string, args ...interface{}) (rowsAffected int64, err error)
	UpdateOne(query string, args ...interface{}) error
	UpdateNum(expectedRowsAffected int64, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) error
	MustExec(query string, args ...interface{})
}

type Db

type Db interface {
	API
	SetDatabase(db string) error
	Transact(TxFn) error
}

func Connect

func Connect(driverName, dataSourceString string, dbNamesMapper DbNameConventionMapper) (Db, error)

func MustConnect

func MustConnect(driverName, dataSourceString string, dbNamesMapper DbNameConventionMapper) Db

type DbNameConventionMapper

type DbNameConventionMapper func(goCamelCaseName string) (dbColumnName string)

DbNameConventionMapper is a function that takes a go struct field name and returns its corresponding database column name.

type Tx

type Tx interface {
	API
}

type TxFn

type TxFn func(tx Tx) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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