Documentation
¶
Index ¶
- Constants
- Variables
- func Callback(fn func(DbOrTx) error, tx ...*sqlx.Tx) error
- func CallbackByName(dbName string, fn func(DbOrTx) error, tx ...*sqlx.Tx) error
- func DB(name ...string) (*sqlx.DB, bool)
- func List() map[string]*sqlx.DB
- func MustDB(name ...string) *sqlx.DB
- func TransactCallback(fn func(*sqlx.Tx) error, tx ...*sqlx.Tx) (err error)
- func TransactCallbackByName(dbName string, fn func(*sqlx.Tx) error, tx ...*sqlx.Tx) (err error)
- type DBConfig
- type DBService
- type DbOrTx
Constants ¶
View Source
const ( DATABASE_DIR = "database/" DEFAULTDB_NAME = "default" )
default constant
Variables ¶
Functions ¶
func Callback ¶
Callback uses the `default` database for non-transactional operations.
func CallbackByName ¶
CallbackByName uses the specified database for non-transactional operations.
func MustDB ¶
MustDB g the specified database engine, or the default DB if no name is specified.
func TransactCallback ¶
TransactCallback uses the default database for transactional operations.
Types ¶
type DBConfig ¶
type DBConfig struct {
Name string `ini:"-"`
Enable bool `ini:"enable" comment:"Enable the config section"`
Driver string `ini:"driver" comment:"mssql | odbc(mssql) | mysql | mymysql | postgres | sqlite3 | oci8 | goracle"`
Connstring string `ini:"connstring" comment:"Connect String"`
MaxOpenConns int `ini:"max_open_conns"`
MaxIdleConns int `ini:"max_idle_conns"`
ColumnSnake bool `ini:"column_snake" comment:"The column name uses the snake style or remains unchanged"`
StructTag string `ini:"struct_tag" comment:"default is 'db'"`
}
DBConfig is database connection config
func Config ¶
Config is similar to MustConfig, but safe.
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 DbOrTx ¶
type DbOrTx 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
}
DbOrTx contains all the exportable methods of *sqlx.DB
Source Files
¶
- config.go
- helper.go
- service.go
Click to show internal directories.
Click to hide internal directories.