Documentation
¶
Index ¶
- Variables
- func FormatRows(rows *sql.Rows, handler RowFormat)
- func ToMap(rows *sql.Rows) ([]map[string]string, error)
- type ExecResult
- type Group
- func (g *Group) BatchInsert(table string, rows []map[string]interface{}) (result *ExecResult, err error)
- func (g *Group) Begin() (trans *Transaction, err error)
- func (g *Group) BeginTx(ctx context.Context, opts *sql.TxOptions) (trans *Transaction, err error)
- func (g *Group) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
- func (g *Group) Find(query *Query, useMaster bool) (rows *sql.Rows, err error)
- func (g *Group) GetBadPool(isMaster bool) (list []int)
- func (g *Group) GetMaster() (index int, mPoll *Pool)
- func (g *Group) GetSlave() (index int, mPoll *Pool)
- func (g *Group) Insert(table string, columns map[string]interface{}) (result *ExecResult, err error)
- func (g *Group) MasterExec(handler func(mPool *Pool) (interface{}, error)) (result interface{}, err error)
- func (g *Group) SelectPool(isMaster bool) (index int, mPool *Pool)
- func (g *Group) SlaveQuery(handler func(mPool *Pool) (interface{}, error)) (result interface{}, err error)
- func (g *Group) UpdateAll(table string, set map[string]interface{}, where map[string]interface{}) (result *ExecResult, err error)
- type GroupOption
- type Pool
- func (p *Pool) BatchInsert(table string, rows *[]map[string]interface{}) (result *ExecResult, err error)
- func (p *Pool) Begin() (trans *Transaction, err error)
- func (p *Pool) BeginTx(ctx context.Context, opts *sql.TxOptions) (trans *Transaction, err error)
- func (p *Pool) Db() *sql.DB
- func (p *Pool) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
- func (p *Pool) Execute(sqlStr string, args ...interface{}) (result *ExecResult, err error)
- func (p *Pool) Find(query *Query) (*sql.Rows, error)
- func (p *Pool) Insert(table string, columns *map[string]interface{}) (result *ExecResult, err error)
- func (p *Pool) Query(sqlStr string, args ...interface{}) (rows *sql.Rows, err error)
- func (p *Pool) UpdateAll(table string, set map[string]interface{}, where map[string]interface{}) (result *ExecResult, err error)
- type PoolOption
- type Query
- func (q *Query) From(table string) *Query
- func (q *Query) Group(fields ...string) *Query
- func (q *Query) Having(having string) *Query
- func (q *Query) Limit(offset int64, limit int64) *Query
- func (q *Query) Offset(offset int64) *Query
- func (q *Query) Order(orders ...string) *Query
- func (q *Query) Query(pool *Pool) (*sql.Rows, error)
- func (q *Query) QueryByGroup(group *Group, useMaster bool) (*sql.Rows, error)
- func (q *Query) Select(columns ...string) *Query
- func (q *Query) Where(where map[string]interface{}) *Query
- type RowFormat
- type Transaction
- func (t *Transaction) BatchInsert(table string, rows *[]map[string]interface{}) (result *ExecResult, err error)
- func (t *Transaction) Commit() error
- func (t *Transaction) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
- func (t *Transaction) Execute(sqlStr string, args ...interface{}) (sql.Result, error)
- func (t *Transaction) Find(query *Query) (*sql.Rows, error)
- func (t *Transaction) Insert(table string, columns *map[string]interface{}) (result *ExecResult, err error)
- func (t *Transaction) Query(sqlStr string, args ...interface{}) (*sql.Rows, error)
- func (t *Transaction) Rollback() error
- func (t *Transaction) UpdateAll(table string, set map[string]interface{}, where map[string]interface{}) (result *ExecResult, err error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoMasterConn = errors.New("mysql group: no master connection available") ErrNoSlaveConn = errors.New("mysql group: no slave connection available") )
View Source
var ( AcquireQuery = func() *Query { return queryPool.Get().(*Query) } ReleaseQuery = func(query *Query) { query = query.reset() queryPool.Put(query) } )
Functions ¶
func FormatRows ¶
Types ¶
type ExecResult ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func NewGroup ¶
func NewGroup(groupOption *GroupOption) *Group
func (*Group) BatchInsert ¶
func (g *Group) BatchInsert(table string, rows []map[string]interface{}) (result *ExecResult, err error)
func (*Group) Begin ¶
func (g *Group) Begin() (trans *Transaction, err error)
func (*Group) DeleteAll ¶
func (g *Group) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
func (*Group) GetBadPool ¶
func (*Group) Insert ¶
func (g *Group) Insert(table string, columns map[string]interface{}) (result *ExecResult, err error)
func (*Group) MasterExec ¶
func (*Group) SlaveQuery ¶
type GroupOption ¶
type GroupOption struct { Masters []PoolOption `yaml:"masters" json:"masters"` Slaves []PoolOption `yaml:"slaves" json:"slaves"` //单位s RetryInterval int64 `yaml:"retryInterval" json:"retryInterval"` }
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func NewPool ¶
func NewPool(option *PoolOption) (*Pool, error)
func (*Pool) BatchInsert ¶
func (p *Pool) BatchInsert(table string, rows *[]map[string]interface{}) (result *ExecResult, err error)
func (*Pool) Begin ¶
func (p *Pool) Begin() (trans *Transaction, err error)
func (*Pool) DeleteAll ¶
func (p *Pool) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
func (*Pool) Execute ¶
func (p *Pool) Execute(sqlStr string, args ...interface{}) (result *ExecResult, err error)
func (*Pool) Insert ¶
func (p *Pool) Insert(table string, columns *map[string]interface{}) (result *ExecResult, err error)
type PoolOption ¶
type PoolOption struct { //格式:"userName:password@schema(host:port)/dbName",如:root:123456@tcp(127.0.0.1:3306)/test Dsn string `yaml:"dsn" json:"dsn"` //单位s MaxConnLifetime int `yaml:"maxConnLifetime" json:"maxConnLifetime"` MaxOpenConns int `yaml:"maxOpenConns" json:"maxOpenConns"` MaxIdleConns int `yaml:"maxIdleConns" json:"maxIdleConns"` }
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) QueryByGroup ¶
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func (*Transaction) BatchInsert ¶
func (t *Transaction) BatchInsert(table string, rows *[]map[string]interface{}) (result *ExecResult, err error)
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
func (*Transaction) DeleteAll ¶
func (t *Transaction) DeleteAll(table string, where map[string]interface{}) (result *ExecResult, err error)
func (*Transaction) Execute ¶
func (t *Transaction) Execute(sqlStr string, args ...interface{}) (sql.Result, error)
func (*Transaction) Insert ¶
func (t *Transaction) Insert(table string, columns *map[string]interface{}) (result *ExecResult, err error)
func (*Transaction) Query ¶
func (t *Transaction) Query(sqlStr string, args ...interface{}) (*sql.Rows, error)
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
func (*Transaction) UpdateAll ¶
func (t *Transaction) UpdateAll(table string, set map[string]interface{}, where map[string]interface{}) (result *ExecResult, err error)
Click to show internal directories.
Click to hide internal directories.