Documentation ¶
Index ¶
- Constants
- func GetDataStructDests(data interface{}, dbType string) ([]interface{}, map[int]int, 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) IsExistTable(tableName string) (bool, 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 TableName
- type TransactionExec
Constants ¶
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" )
const (
PcTransactionInsertDup = "transaction_insert_dup"
)
Variables ¶
This section is empty.
Functions ¶
func GetDataStructDests ¶
func GetDataStructFields ¶
func GetDataStructValues ¶
func GetFieldsName ¶
func GetFieldsNameArray ¶
func IsDbConnError ¶
func IsTimeoutError ¶
func MysqlEscapeString ¶
Types ¶
type CommonDbConf ¶
type CommonDbConf struct { DbType string // db type 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"` // 数据库类型指定 dm mysql 缺省:mysql DbType string // contains filtered or unexported fields }
func (*MysqlClient) Add ¶
func (c *MysqlClient) Add(tableName string, d interface{}, ondupUpdate bool) error
Add DM不支持该方法 推荐使用AddEscapeAutoIncr、AddEscapeAutoIncrAndRetLastId、InsertOrUpdateOnDup.
func (*MysqlClient) AddEscapeAutoIncr ¶
func (c *MysqlClient) AddEscapeAutoIncr(tableName string, d interface{}, ondupUpdate bool, atuoincrkey string) (int64, error)
AddEscapeAutoIncr DM支持该方法 插入/插入更新 ondupUpdate 插入更新,必须指定自主列名称 atuoincrkey.
func (*MysqlClient) AddEscapeAutoIncrAndRetLastId ¶
func (c *MysqlClient) AddEscapeAutoIncrAndRetLastId(tableName string, d interface{}, atuoincrkey string) (int64, error)
AddEscapeAutoIncrAndRetLastId DM支持该方法 执行纯插入操作(若数据已存在,则返回失败),其会跳过由atuoincrkey指定的自增列,若执行成功,返回所插入的行id
func (*MysqlClient) Close ¶
func (c *MysqlClient) Close()
func (*MysqlClient) Delete ¶
func (c *MysqlClient) Delete(tableName string, condition map[string]interface{}) (int64, error)
Update DM支持该方法 根据condition删除数据 .
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)
GetCount DM支持该方法 获取表中数据总数 .
func (*MysqlClient) GetReadDbRandom ¶
func (c *MysqlClient) GetReadDbRandom() (*DbWrap, error)
func (*MysqlClient) GetWriteDbs ¶
func (c *MysqlClient) GetWriteDbs() *DbWrap
func (*MysqlClient) InsertOrUpdateOnDup ¶
func (c *MysqlClient) InsertOrUpdateOnDup(tableName string, d interface{}, primaryKeys []string, updateFields []string, useSqlOnDup bool) (int64, error)
InsertOrUpdateOnDup 根据主键/插入更新 useSqlOnDup=false,根据primaryKeys更新数据。useSqlOnDup=true,主键重复则更新updateFields,否则插入新数据主键ID自增.
func (*MysqlClient) IsExistTable ¶ added in v1.7.17
func (c *MysqlClient) IsExistTable(tableName string) (bool, error)
IsExistTable DM支持该方法 判断表是否存在
func (*MysqlClient) Query ¶
func (c *MysqlClient) Query(dataType interface{}, query string, args ...interface{}) (interface{}, error)
Query DM支持该方法 获取数据,无数据返回nil,nil.
func (*MysqlClient) QueryList ¶
func (c *MysqlClient) QueryList(dataType interface{}, query string, args ...interface{}) ([]interface{}, error)
QueryList DM支持该方法 获取数据列表.
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