Documentation
¶
Index ¶
- Constants
- Variables
- func FormatRows(rows *sql.Rows, handler RowFormat)
- func SqlDelete(args *[]interface{}, table string, condition Condition) (sql string)
- func SqlDeleteByObj(args *[]interface{}, obj interface{}) (sqlStr string, err error)
- func SqlDeleteByWhere(args *[]interface{}, table string, where Where) (sql string)
- func SqlFindOneObj(args *[]interface{}, condition Condition, obj interface{}) (sql string, err error)
- func SqlInsert(args *[]interface{}, table string, rows ...map[string]interface{}) (sql string)
- func SqlInsertObjs(args *[]interface{}, rows interface{}) (sql string, err error)
- func SqlUpdate(args *[]interface{}, table string, set map[string]interface{}, ...) (sql string)
- func SqlUpdateByObj(args *[]interface{}, obj interface{}) (sqlStr string, err error)
- func SqlUpdateByWhere(args *[]interface{}, table string, set map[string]interface{}, where Where) (sql string)
- func ToMap(rows *sql.Rows) ([]map[string]string, error)
- func ToObj(rows *sql.Rows, obj interface{}) error
- func ToObjList(rows *sql.Rows, obj interface{}) (interface{}, error)
- type Condition
- type Group
- type GroupOption
- type Pool
- type PoolOption
- type Query
- type RowFormat
- type Where
- type WhereCondition
Constants ¶
View Source
const ( Or = `OR` And = `AND` )
Variables ¶
View Source
var ( ErrInvalidRowsTypes = errors.New(`only *struct or []*struct types are supported`) ErrNotFoundField = errors.New(`failed to match the field from the struct to the database. Please configure the borm tag correctly`) ErrNotFoundPrimaryField = errors.New(`failed to found primary field. Please configure the primary on borm tag correctly`) ErrInvalidTypes = errors.New(`only *struct types are supported`) ErrInvalidFieldTypes = errors.New(`only bool(1 is true, other is false),string、float64、float32、int、uint、int8、uint8、int16、uint16、int32、uint32、int64 and uint64 types are supported`) )
View Source
var ( ErrNoMasterConn = errors.New("mysql group: no master connection available") ErrNoSlaveConn = errors.New("mysql group: no slave connection available") )
Functions ¶
func FormatRows ¶
func SqlDeleteByObj ¶
func SqlDeleteByWhere ¶
func SqlFindOneObj ¶
func SqlInsertObjs ¶
func SqlUpdateByObj ¶
func SqlUpdateByWhere ¶
Types ¶
type Group ¶
type Group interface {
BadPool(isMaster bool) (list []int)
Query(useMaster bool, sqlStr string, args ...interface{}) (rows []map[string]string, err error)
Exec(sqlStr string, args ...interface{}) (result sql.Result, err error)
InsertObj(obj interface{}) (result sql.Result, err error)
DeleteObj(obj interface{}) (result sql.Result, err error)
UpdateObj(obj interface{}) (result sql.Result, err error)
Find(query Query, useMaster bool) (rows []map[string]string, err error)
FindAll(query Query, obj interface{}, useMaster bool) (objList interface{}, err error)
FindOne(table string, condition Condition, useMaster bool) (row map[string]string, err error)
FindOneObj(condition Condition, useMaster bool, obj interface{}) (err error)
Insert(table string, rows ...map[string]interface{}) (result sql.Result, err error)
DeleteAll(table string, condition Condition) (result sql.Result, err error)
UpdateAll(table string, set map[string]interface{}, condition Condition) (result sql.Result, err error)
Begin() (*sql.Tx, error)
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}
func NewMysqlGroup ¶
func NewMysqlGroup(groupOption *GroupOption) (Group, error)
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 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 interface {
Select(columns ...string) Query
From(table string) Query
Where(condition Condition) Query
AndWhere(condition Condition) Query
OrWhere(condition Condition) Query
Group(fields ...string) Query
Having(having string) Query
Order(orders ...string) Query
Offset(offset int64) Query
Limit(limit int64) Query
Sql(arguments *[]interface{}) (sql string)
Close()
}
func NewMysqlQuery ¶
func NewMysqlQuery() Query
type Where ¶
type Where []WhereCondition
type WhereCondition ¶
type WhereCondition struct {
// contains filtered or unexported fields
}
func AndWhere ¶
func AndWhere(condition Condition) WhereCondition
func OrWhere ¶
func OrWhere(condition Condition) WhereCondition
Source Files
¶
Click to show internal directories.
Click to hide internal directories.