sqlx

package
v0.0.0-...-7c1bd55 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBCONFIG_FILE  = faygo.CONFIG_DIR + "sqlx.ini"
	DATABASE_DIR   = "database/"
	DEFAULTDB_NAME = "default"
)

default constant

Variables

This section is empty.

Functions

func Callback

func Callback(fn func(DBTX) error, tx ...*sqlx.Tx) error

Callback uses the `default` database for non-transactional operations.

func CallbackByName

func CallbackByName(dbName string, fn func(DBTX) error, tx ...*sqlx.Tx) error

CallbackByName uses the specified database for non-transactional operations.

func DB

func DB(name ...string) (*sqlx.DB, bool)

DB is similar to MustDB, but safe.

func List

func List() map[string]*sqlx.DB

List gets the list of database engines

func MustDB

func MustDB(name ...string) *sqlx.DB

MustDB g the specified database engine, or the default DB if no name is specified.

func TransactCallback

func TransactCallback(fn func(*sqlx.Tx) error, tx ...*sqlx.Tx) (err error)

TransactCallback uses the default database for transactional operations. note: if an error is returned, the rollback method should be invoked outside the function.

func TransactCallbackByName

func TransactCallbackByName(dbName string, fn func(*sqlx.Tx) error, tx ...*sqlx.Tx) (err error)

TransactCallbackByName uses the `specified` database for transactional operations. note: if an error is returned, the rollback method should be invoked outside the function.

Types

type DBConfig

type DBConfig struct {
	Name         string `ini:"-"`
	Enable       bool   `ini:"enable"`
	Driver       string `ini:"driver"` // driver: mssql | odbc(mssql) | mysql | mymysql | postgres | sqlite3 | oci8 | goracle
	Connstring   string `ini:"connstring"`
	MaxOpenConns int    `ini:"max_open_conns"`
	MaxIdleConns int    `ini:"max_idle_conns"`
	ShowSql      bool   `ini:"show_sql"`
	ColumnSnake  bool   `ini:"column_snake"` // the column name uses the snake style or remains unchanged
	StructTag    string `ini:"struct_tag"`   // default is 'db'
}

DBConfig is database connection config

func Config

func Config(name ...string) (DBConfig, bool)

Config is similar to MustConfig, but safe.

func MustConfig

func MustConfig(name ...string) DBConfig

MustConfig gets the configuration information for the specified database, or returns the default if no name is specified.

type DBService

type DBService struct {
	Default *sqlx.DB            // the default database engine
	List    map[string]*sqlx.DB // database engine list
}

DBService is a database engine object.

type DBTX

type DBTX interface {
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
	DriverName() string
	Get(dest interface{}, query string, args ...interface{}) error
	MustExec(query string, args ...interface{}) sql.Result
	NamedExec(query string, arg interface{}) (sql.Result, error)
	NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
	Preparex(query string) (*sqlx.Stmt, error)
	QueryRowx(query string, args ...interface{}) *sqlx.Row
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	Rebind(query string) string
	Select(dest interface{}, query string, args ...interface{}) error

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

DBTX contains all the exportable methods of * sqlx.TX

Jump to

Keyboard shortcuts

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