Documentation
¶
Index ¶
- Constants
- Variables
- func GetConn(config DBConfig) *db.DB
- func PrintErrorSql(err error, sql string, args ...interface{})
- func PrintSlowConn(driverName, host, dbName string, consume int64)
- func PrintSlowSql(host, dbName string, consume int64, sql string, args ...interface{})
- type DBClient
- func (client *DBClient) CloseConn()
- func (client *DBClient) CloseStmt(stmt *db.Stmt)
- func (client *DBClient) Exec(sql string, args ...interface{}) (result int64, err error)
- func (client *DBClient) GetStmt(sql string) (stmt *db.Stmt, err error)
- func (client *DBClient) GetTxStmt(tx *db.Tx, sql string) (stmt *db.Stmt, err error)
- func (client *DBClient) QueryAggregate(sql string, args ...interface{}) (aggregate int64, err error)
- func (client *DBClient) QueryDBInfo() *db.Rows
- func (client *DBClient) QueryList(orm ORMBase, sql string, args ...interface{}) (rows *db.Rows, err error)
- func (client *DBClient) QueryMetaData(tabName string) *db.Rows
- func (client *DBClient) QueryRow(orm ORMBase, sql string, args ...interface{}) (row *db.Row, err error)
- func (client *DBClient) TxBegin() (tx *db.Tx, err error)
- func (client *DBClient) TxCommit(tx *db.Tx) bool
- func (client *DBClient) TxExec(tx *db.Tx, sql string, args ...interface{}) (result int64, err error)
- func (client *DBClient) TxQueryAggregate(tx *db.Tx, sql string, args ...interface{}) (aggregate int64, err error)
- func (client *DBClient) TxQueryList(tx *db.Tx, orm ORMBase, sql string, args ...interface{}) (rows *db.Rows, err error)
- func (client *DBClient) TxQueryRow(tx *db.Tx, orm ORMBase, sql string, args ...interface{}) (row *db.Row, err error)
- func (client *DBClient) TxRollback(tx *db.Tx)
- type DBConfig
- type ORMBase
- type ORMColumn
- type ORMGenerator
- type ORMTable
- type WeTestTab1
- func (weTestTab1 *WeTestTab1) BatchInsert(client *DBClient, idSet, returnIds bool) ([]int64, error)
- func (weTestTab1 *WeTestTab1) DeleteWeTestTab1ById(client *DBClient) (int64, error)
- func (weTestTab1 *WeTestTab1) Insert(client *DBClient, idSet bool) (int64, error)
- func (weTestTab1 *WeTestTab1) RowToStruct(row *db.Row) error
- func (weTestTab1 *WeTestTab1) RowsToStruct(rows *db.Rows) error
- func (weTestTab1 *WeTestTab1) UpdateWeTestTab1ById(client *DBClient) (int64, error)
- type WeTestTab2
- func (weTestTab2 *WeTestTab2) BatchInsert(client *DBClient, idSet, returnIds bool) ([]int64, error)
- func (weTestTab2 *WeTestTab2) DeleteWeTestTab2ById(client *DBClient) (int64, error)
- func (weTestTab2 *WeTestTab2) Insert(client *DBClient, idSet bool) (int64, error)
- func (weTestTab2 *WeTestTab2) RowToStruct(row *db.Row) error
- func (weTestTab2 *WeTestTab2) RowsToStruct(rows *db.Rows) error
- func (weTestTab2 *WeTestTab2) UpdateWeTestTab2ById(client *DBClient) (int64, error)
Constants ¶
View Source
const ( MySQL = "MySQL" SlowSqlTimeoutMillisecond = 2000 ConnDBTimeoutMillisecond = 2000 )
Variables ¶
View Source
var DBGoTypes = map[string]string{
"TINYINT": "int64",
"SMALLINT": "int64",
"MEDIUMINT": "int64",
"INT": "int64",
"BIGINT": "int64",
"DECIMAL": "float64",
"FLOAT": "float64",
"DOUBLE": "float64",
"NUMERIC": "float64",
"CHAR": "string",
"VARCHAR": "string",
"BINARY": "string",
"VARBINARY": "string",
"BLOB": "string",
"TINYTEXT": "string",
"TEXT": "string",
"MEDIUMTEXT": "string",
"LONGTEXT": "string",
"ENUM": "string",
"SET": "string",
"DATE": "time.Time",
"DATETIME": "time.Time",
"TIMESTAMP": "time.Time",
}
View Source
var ORMTabsCols []ORMTable
Functions ¶
func PrintErrorSql ¶
func PrintSlowConn ¶
func PrintSlowSql ¶
Types ¶
type DBClient ¶
func TestDbClient ¶
func TestDbClient() *DBClient
func (*DBClient) QueryAggregate ¶
func (client *DBClient) QueryAggregate(sql string, args ...interface{}) (aggregate int64, err error)
Database aggregate function, eg: SUM(*),COUNT(*) etc.
func (*DBClient) QueryDBInfo ¶
Get database information
func (*DBClient) QueryList ¶
func (client *DBClient) QueryList(orm ORMBase, sql string, args ...interface{}) (rows *db.Rows, err error)
Get database table multiple rows data
func (*DBClient) QueryMetaData ¶
Get database table metadata
func (*DBClient) QueryRow ¶
func (client *DBClient) QueryRow(orm ORMBase, sql string, args ...interface{}) (row *db.Row, err error)
Get database table a row data
func (*DBClient) TxExec ¶
func (client *DBClient) TxExec(tx *db.Tx, sql string, args ...interface{}) (result int64, err error)
Modify database table info or data,transaction
func (*DBClient) TxQueryAggregate ¶
func (client *DBClient) TxQueryAggregate(tx *db.Tx, sql string, args ...interface{}) (aggregate int64, err error)
Database aggregate function, eg: SUM(*),COUNT(*) etc,transaction
func (*DBClient) TxQueryList ¶
func (client *DBClient) TxQueryList(tx *db.Tx, orm ORMBase, sql string, args ...interface{}) (rows *db.Rows, err error)
Get database table multiple rows data,transaction
func (*DBClient) TxQueryRow ¶
func (client *DBClient) TxQueryRow(tx *db.Tx, orm ORMBase, sql string, args ...interface{}) (row *db.Row, err error)
Get database table a row data,transaction
func (*DBClient) TxRollback ¶
Rollback the transaction
type DBConfig ¶
type DBConfig struct {
DbHost string
DbUser string
DbPass string
DbName string
// if false, local default UTC +0
IsLocalTime bool
}
MySQL database connect configuration
type ORMGenerator ¶
func NewORMGenerator ¶
func NewORMGenerator(client *DBClient) *ORMGenerator
func (*ORMGenerator) DefaultGenerator ¶
func (orm *ORMGenerator) DefaultGenerator(tabName []string)
func (*ORMGenerator) ORMBuilder ¶
func (orm *ORMGenerator) ORMBuilder(tabNames []string)
type WeTestTab1 ¶
type WeTestTab1 struct {
Id int64 `column:"id"` // The primary key id
Name string `column:"name"` // The user name
Gender int64 `column:"gender"` // The user gerder, 1:male 2:female 0:default
Birthday time.Time `column:"birthday"` // The user birthday, eg: 2018-04-16
Stature float64 `column:"stature"` // The user stature, eg: 172.22cm
Weight float64 `column:"weight"` // The user weight, eg: 21.77kg
CreatedTime time.Time `column:"created_time"` // created time
ModifiedTime time.Time `column:"modified_time"` // record time
IsDeleted int64 `column:"is_deleted"` // Logic to delete(0:normal 1:deleted)
WeTestTab1s []WeTestTab1 // This value is used for batch queries and inserts.
}
test table1
func (*WeTestTab1) BatchInsert ¶
func (weTestTab1 *WeTestTab1) BatchInsert(client *DBClient, idSet, returnIds bool) ([]int64, error)
func (*WeTestTab1) DeleteWeTestTab1ById ¶
func (weTestTab1 *WeTestTab1) DeleteWeTestTab1ById(client *DBClient) (int64, error)
func (*WeTestTab1) Insert ¶
func (weTestTab1 *WeTestTab1) Insert(client *DBClient, idSet bool) (int64, error)
func (*WeTestTab1) RowToStruct ¶
func (weTestTab1 *WeTestTab1) RowToStruct(row *db.Row) error
func (*WeTestTab1) RowsToStruct ¶
func (weTestTab1 *WeTestTab1) RowsToStruct(rows *db.Rows) error
func (*WeTestTab1) UpdateWeTestTab1ById ¶
func (weTestTab1 *WeTestTab1) UpdateWeTestTab1ById(client *DBClient) (int64, error)
type WeTestTab2 ¶
type WeTestTab2 struct {
Id int64 `column:"id"` // The primary key id
UserId int64 `column:"user_id"` // The user id
AreaCode int64 `column:"area_code"` // The user area code
Phone int64 `column:"phone"` // The user phone
Email string `column:"email"` // The user email
Postcode int64 `column:"postcode"` // The user postcode
AdministrationCode int64 `column:"administration_code"` // The user administration code
Address string `column:"address"` // The user address
CreatedTime time.Time `column:"created_time"` // created time
ModifiedTime time.Time `column:"modified_time"` // modified time
IsDeleted int64 `column:"is_deleted"` // Logic to delete(0:normal 1:deleted)
WeTestTab2s []WeTestTab2 // This value is used for batch queries and inserts.
}
test table2
func (*WeTestTab2) BatchInsert ¶
func (weTestTab2 *WeTestTab2) BatchInsert(client *DBClient, idSet, returnIds bool) ([]int64, error)
func (*WeTestTab2) DeleteWeTestTab2ById ¶
func (weTestTab2 *WeTestTab2) DeleteWeTestTab2ById(client *DBClient) (int64, error)
func (*WeTestTab2) Insert ¶
func (weTestTab2 *WeTestTab2) Insert(client *DBClient, idSet bool) (int64, error)
func (*WeTestTab2) RowToStruct ¶
func (weTestTab2 *WeTestTab2) RowToStruct(row *db.Row) error
func (*WeTestTab2) RowsToStruct ¶
func (weTestTab2 *WeTestTab2) RowsToStruct(rows *db.Rows) error
func (*WeTestTab2) UpdateWeTestTab2ById ¶
func (weTestTab2 *WeTestTab2) UpdateWeTestTab2ById(client *DBClient) (int64, error)
Click to show internal directories.
Click to hide internal directories.