Documentation ¶
Index ¶
- Constants
- func GetDataStructDests(data interface{}) ([]interface{}, error)
- func GetDataStructFields(data interface{}) ([]string, error)
- func GetDataStructValues(data interface{}) []driver.Value
- func GetFields(v interface{}) (res []interface{}, errRet error)
- func GetFieldsName(v interface{}) (res string, errRet error)
- func GetFieldsNameArray(v interface{}) (res []string, errRet error)
- func IsDbConnError(err error) bool
- func IsTimeoutError(err error) bool
- func MysqlEscapeString(source string) string
- type CommonDbConf
- type DbConnectConf
- type DbWrap
- func NewDbWrapped(host string, db *sql.DB, mysqlClient *MysqlClient, timeout time.Duration) *DbWrap
- func NewDbWrappedRetry(host string, db *sql.DB, mysqlClient *MysqlClient, timeout time.Duration, ...) *DbWrap
- func NewDbWrappedRetryProxy(host string, db *sql.DB, mysqlClient *MysqlClient, timeout time.Duration, ...) *DbWrap
- func (db *DbWrap) Close() error
- func (db *DbWrap) Exec(query string, args ...interface{}) (r sql.Result, err error)
- func (db *DbWrap) ExecContext(ctx context.Context, query string, args ...interface{}) (r sql.Result, err error)
- func (db *DbWrap) ExecTransaction(transactionExec TransactionExec) (r sql.Result, err error)
- func (db *DbWrap) Query(query string, args ...interface{}) (rs *sql.Rows, err error)
- func (db *DbWrap) QueryRow(query string, args ...interface{}) *Row
- type MysqlClient
- func (c *MysqlClient) Add(tableName string, d interface{}, ondupUpdate bool) error
- func (c *MysqlClient) AddEscapeAutoIncr(tableName string, d interface{}, ondupUpdate bool, atuoincrkey string) (int64, error)
- func (c *MysqlClient) AddEscapeAutoIncrAndRetLastId(tableName string, d interface{}, atuoincrkey string) (int64, error)
- func (c *MysqlClient) Close()
- func (c *MysqlClient) Delete(tableName string, condition map[string]interface{}) (int64, error)
- func (c *MysqlClient) ExecTransaction(transactionExec TransactionExec) (int64, error)
- func (c *MysqlClient) Execute(sql string, args ...interface{}) (int64, error)
- func (c *MysqlClient) GetCount(query string, args ...interface{}) (int64, error)
- func (c *MysqlClient) GetReadDbRandom() (*DbWrap, error)
- func (c *MysqlClient) GetWriteDbs() *DbWrap
- func (c *MysqlClient) InsertOrUpdateOnDup(tableName string, d interface{}, primaryKeys []string, updateFields []string, ...) (int64, error)
- func (c *MysqlClient) Query(dataType interface{}, query string, args ...interface{}) (interface{}, error)
- func (c *MysqlClient) QueryList(dataType interface{}, query string, args ...interface{}) ([]interface{}, error)
- func (c *MysqlClient) Start() error
- func (c *MysqlClient) Update(tableName string, d interface{}, primaryKeys map[string]interface{}, ...) error
- type Row
- type SqlCondition
- func (c *SqlCondition) BuildShardWhereSql(shardKey string) (string, string, []interface{})
- func (c *SqlCondition) BuildWhereSql() (string, []interface{})
- func (c *SqlCondition) Valid(isGet bool) error
- func (c *SqlCondition) WithCondition(key, compare string, value interface{}) *SqlCondition
- func (c *SqlCondition) WithLimit(limit int64) *SqlCondition
- func (c *SqlCondition) WithOffset(offset int64) *SqlCondition
- func (c *SqlCondition) WithOrder(key string, isdesc bool) *SqlCondition
- func (c *SqlCondition) WithTablePrefix(tablePrefix string) *SqlCondition
- type TransactionExec
Constants ¶
View Source
const ( PcMysqlReadFail = "mysql_read_fail" PcMysqlReadAllFail = "mysql_read_all_fail" PcMysqlWriteAllFail = "mysql_write_all_fail" PcMysqlWriteFail = "mysql_write_fail" PcMysqlRead = "mysql_read" PcMysqlWrite = "mysql_write" PcMysqlTransaction = "mysql_transaction" )
View Source
const (
PcTransactionInsertDup = "transaction_insert_dup"
)
Variables ¶
This section is empty.
Functions ¶
func GetDataStructDests ¶
func GetDataStructDests(data interface{}) ([]interface{}, error)
func GetDataStructFields ¶
func GetDataStructValues ¶
func GetFieldsName ¶
func GetFieldsNameArray ¶
func IsDbConnError ¶
func IsTimeoutError ¶
func MysqlEscapeString ¶
Types ¶
type CommonDbConf ¶
type CommonDbConf struct { DbName string ConnTime string // connect timeout ReadTime string // read timeout WriteTime string // write timeout MaxOpen int // connect pool MaxIdle int // max idle connect MaxLifeTime int64 // connect life time Master *DbConnectConf Slave *DbConnectConf // contains filtered or unexported fields }
type DbConnectConf ¶
type DbConnectConf struct { Addrs []string User string Pass string CharSet string // default utf8mb4 ClientFoundRows bool // 对于update操作,若更改的字段值跟原来值相同,当clientFoundRows为false时,sql执行结果会返回0;当clientFoundRows为true,sql执行结果返回1 IsProxy bool EnableSqlSafeUpdates bool // (safe update mode),该模式不允许没有带WHERE条件的更新语句 }
type DbWrap ¶
func NewDbWrapped ¶
func NewDbWrappedRetry ¶
func NewDbWrappedRetryProxy ¶
func (*DbWrap) ExecContext ¶
func (*DbWrap) ExecTransaction ¶
func (db *DbWrap) ExecTransaction(transactionExec TransactionExec) (r sql.Result, err error)
type MysqlClient ¶
type MysqlClient struct { DbConfig *CommonDbConf `inject:"mysqlDbConfig" canNil:"true"` DbConf *ini.File `inject:"mysqlDbConf" canNil:"true"` DbConfPath string `inject:"mysqlDbConfPath" canNil:"true"` DataBase string `inject:"mysqlDatabase" canNil:"true"` // contains filtered or unexported fields }
func (*MysqlClient) Add ¶
func (c *MysqlClient) Add(tableName string, d interface{}, ondupUpdate bool) error
d must be a struct pointer
func (*MysqlClient) AddEscapeAutoIncr ¶
func (*MysqlClient) AddEscapeAutoIncrAndRetLastId ¶
func (c *MysqlClient) AddEscapeAutoIncrAndRetLastId(tableName string, d interface{}, atuoincrkey string) (int64, error)
AddEscapeAutoIncrAndRetLastId执行纯插入操作(若数据已存在,则返回失败),其会跳过由atuoincrkey指定的自增列,若执行成功,返回所插入的行id
func (*MysqlClient) Close ¶
func (c *MysqlClient) Close()
func (*MysqlClient) Delete ¶
func (c *MysqlClient) Delete(tableName string, condition map[string]interface{}) (int64, error)
condition value supports limit kinds of slice:[]int64,[]string,[]interface
func (*MysqlClient) ExecTransaction ¶
func (c *MysqlClient) ExecTransaction(transactionExec TransactionExec) (int64, error)
func (*MysqlClient) Execute ¶
func (c *MysqlClient) Execute(sql string, args ...interface{}) (int64, error)
func (*MysqlClient) GetCount ¶
func (c *MysqlClient) GetCount(query string, args ...interface{}) (int64, error)
func (*MysqlClient) GetReadDbRandom ¶
func (c *MysqlClient) GetReadDbRandom() (*DbWrap, error)
func (*MysqlClient) GetWriteDbs ¶
func (c *MysqlClient) GetWriteDbs() *DbWrap
func (*MysqlClient) InsertOrUpdateOnDup ¶
func (*MysqlClient) Query ¶
func (c *MysqlClient) Query(dataType interface{}, query string, args ...interface{}) (interface{}, error)
no data return nil,nil
func (*MysqlClient) QueryList ¶
func (c *MysqlClient) QueryList(dataType interface{}, query string, args ...interface{}) ([]interface{}, error)
func (*MysqlClient) Start ¶
func (c *MysqlClient) Start() error
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row is the result of calling QueryRow to select a single row.
type SqlCondition ¶
type SqlCondition struct {
// contains filtered or unexported fields
}
func NewSqlCondition ¶
func NewSqlCondition() *SqlCondition
func (*SqlCondition) BuildShardWhereSql ¶
func (c *SqlCondition) BuildShardWhereSql(shardKey string) (string, string, []interface{})
Need to call WithTablePrefix() first returns: @tableName string tableName @sqlStr string contains all contents after(include) WHERE @vars []interface varsHolder
func (*SqlCondition) BuildWhereSql ¶
func (c *SqlCondition) BuildWhereSql() (string, []interface{})
returns: @sqlStr string contains all contents after(include) WHERE @vars []interface varsHolder
func (*SqlCondition) Valid ¶
func (c *SqlCondition) Valid(isGet bool) error
Valid SqlCondition,use before buildSql
func (*SqlCondition) WithCondition ¶
func (c *SqlCondition) WithCondition(key, compare string, value interface{}) *SqlCondition
func (*SqlCondition) WithLimit ¶
func (c *SqlCondition) WithLimit(limit int64) *SqlCondition
func (*SqlCondition) WithOffset ¶
func (c *SqlCondition) WithOffset(offset int64) *SqlCondition
func (*SqlCondition) WithOrder ¶
func (c *SqlCondition) WithOrder(key string, isdesc bool) *SqlCondition
func (*SqlCondition) WithTablePrefix ¶
func (c *SqlCondition) WithTablePrefix(tablePrefix string) *SqlCondition
Click to show internal directories.
Click to hide internal directories.