Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertInSQL(sql string) string
- func Expr(expr string, args ...interface{}) *clause.Expr
- func GetPolicyHandler(name string) (handlerFunc interface{}, ok bool)
- func IndirectType(v reflect.Type) reflect.Type
- func IsChar(c rune) bool
- func IsInsertSQL(sql string) bool
- func IsIntZero(value reflect.Value) bool
- func IsNil(val reflect.Value) bool
- func MakeMapScan(rows *sqlx.Rows) (map[string]interface{}, error)
- func ParseMapScan(rows *sqlx.Rows, mapValue map[string]interface{}) error
- func RegisterPolicyHandler(name string, handler interface{})
- func ScanAll(rows *sqlx.Rows, dest DestWrapper) error
- func SetClauseBuilder(name string, builder clause.ClauseBuilder)
- type ClusterConfig
- type Config
- type Connection
- type ConnectionEngine
- type DBConfig
- type DestWrapper
- type EngineGroup
- func (eg *EngineGroup) Begin() (*SqlDB, error)
- func (eg *EngineGroup) BeginContext(ctx context.Context) (*SqlDB, error)
- func (eg *EngineGroup) Close()
- func (eg *EngineGroup) Commit() error
- func (eg *EngineGroup) DriverName() string
- func (eg *EngineGroup) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (eg *EngineGroup) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
- func (eg *EngineGroup) Query(query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (eg *EngineGroup) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (eg *EngineGroup) QueryRow(query string, args ...interface{}) (row *sqlx.Row)
- func (eg *EngineGroup) QueryRowContext(ctx context.Context, query string, args ...interface{}) (row *sqlx.Row)
- func (eg *EngineGroup) Raw(query string, args ...interface{}) *RawSession
- func (eg *EngineGroup) RawContext(ctx context.Context, query string, args ...interface{}) *RawSession
- func (eg *EngineGroup) Rebind(query string) string
- func (eg *EngineGroup) Rollback() error
- func (eg *EngineGroup) SetPolicy(dbAlias string, policy IPolicy) *EngineGroup
- func (eg *EngineGroup) Table(table string) *Session
- func (eg *EngineGroup) TableContext(ctx context.Context, table string) *Session
- func (eg *EngineGroup) Tx(fn func(db *SqlDB) error) (err error)
- func (eg *EngineGroup) TxContext(ctx context.Context, fn func(db *SqlDB) error) (err error)
- func (eg *EngineGroup) Use(dbAlias ...string) *SqlDB
- type ExecResult
- type IPolicy
- type ISqlx
- type PolicyHandler
- type PolicyOptions
- type PolicyParams
- type RawSession
- type ReflectMapper
- type Session
- func (session *Session) AddClause(conds ...clause.Expression) *Session
- func (session *Session) AddError(err error)
- func (session *Session) Asc(columns ...string) *Session
- func (session *Session) BulkCreate(data interface{}) (lastInsertIdList []int64, err error)
- func (session *Session) BulkUpdate(data map[string]interface{}) (affected int64, err error)
- func (session *Session) Clear()
- func (session *Session) Count() (count int64, err error)
- func (session *Session) Create(data interface{}) (lastInsertId int64, err error)
- func (session *Session) Delete() (affected int64, err error)
- func (session *Session) Desc(columns ...string) *Session
- func (session *Session) Distinct(columns ...string) *Session
- func (session *Session) Exist() (bool, error)
- func (session *Session) Find(dest interface{}) error
- func (session *Session) First(dest interface{}) error
- func (session *Session) GroupBy(name string) *Session
- func (session *Session) Having(query interface{}, args ...interface{}) *Session
- func (session *Session) Hint(query string) *Session
- func (session *Session) Join(condition string, args ...interface{}) *Session
- func (session *Session) Limit(limit int) *Session
- func (session *Session) Master() *Session
- func (session *Session) Not(query interface{}, args ...interface{}) *Session
- func (session *Session) Offset(offset int) *Session
- func (session *Session) Or(query interface{}, args ...interface{}) *Session
- func (session *Session) OrderBy(order string) *Session
- func (session *Session) Query() (*sqlx.Rows, error)
- func (session *Session) QueryRow() *sqlx.Row
- func (session *Session) Select(columns ...string) *Session
- func (session *Session) SelectExpr(query string, args ...interface{}) *Session
- func (session *Session) Update(column string, value interface{}) (affected int64, err error)
- func (session *Session) Where(query interface{}, args ...interface{}) *Session
- type SqlDB
- func (db *SqlDB) Begin() (*SqlDB, error)
- func (db *SqlDB) BeginContext(ctx context.Context) (*SqlDB, error)
- func (db *SqlDB) Commit() error
- func (db *SqlDB) DriverName() string
- func (db *SqlDB) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (db *SqlDB) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
- func (db *SqlDB) Query(query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (db *SqlDB) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (db *SqlDB) QueryRow(query string, args ...interface{}) (row *sqlx.Row)
- func (db *SqlDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) (row *sqlx.Row)
- func (db *SqlDB) Raw(query string, args ...interface{}) *RawSession
- func (db *SqlDB) RawContext(ctx context.Context, query string, args ...interface{}) *RawSession
- func (db *SqlDB) Rebind(query string) string
- func (db *SqlDB) Rollback() error
- func (db *SqlDB) Table(table string) *Session
- func (db *SqlDB) TableContext(ctx context.Context, table string) *Session
- func (db *SqlDB) Tx(fn func(db *SqlDB) error) (err error)
- func (db *SqlDB) TxContext(ctx context.Context, fn func(db *SqlDB) error) (err error)
- type Statement
- func (stmt *Statement) AddClause(v clause.IClause)
- func (stmt *Statement) AddClauseIfNotExists(v clause.IClause)
- func (stmt *Statement) AddSQLVar(writer clause.Writer, vars ...interface{})
- func (stmt *Statement) Build(clauses ...string)
- func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) (conditions []clause.Expression, err error)
- func (stmt Statement) Quote(field interface{}) string
- func (stmt Statement) QuoteTo(writer clause.Writer, field interface{})
- func (stmt *Statement) ReInit()
- func (stmt *Statement) WriteByte(c byte) error
- func (stmt *Statement) WriteQuoted(value interface{}) error
- func (stmt *Statement) WriteString(str string) (int, error)
- type StatementModifier
Constants ¶
View Source
const DefaultDBAlias = "default"
Variables ¶
View Source
var ( ErrRecordNotFound = errors.New("record not found") ErrMissingWhereClause = errors.New("missing WHERE clause while deleting") )
Functions ¶
func ConvertInSQL ¶
func GetPolicyHandler ¶
func IsInsertSQL ¶
func RegisterPolicyHandler ¶
func RegisterPolicyHandler(name string, handler interface{})
func SetClauseBuilder ¶
func SetClauseBuilder(name string, builder clause.ClauseBuilder)
Types ¶
type ClusterConfig ¶
type ClusterConfig struct { Driver string Master *Config Slaves []*Config Policy *PolicyOptions }
type Connection ¶
type ConnectionEngine ¶
type ConnectionEngine struct { Dialector dialects.Dialector // contains filtered or unexported fields }
func (*ConnectionEngine) Master ¶
func (engine *ConnectionEngine) Master() *Connection
func (*ConnectionEngine) Slave ¶
func (engine *ConnectionEngine) Slave() *Connection
func (*ConnectionEngine) Slaves ¶
func (engine *ConnectionEngine) Slaves() []*Connection
type DestWrapper ¶
type EngineGroup ¶
type EngineGroup struct {
// contains filtered or unexported fields
}
func NewDBEngineGroup ¶
func NewDBEngineGroup(conf DBConfig, showSQL bool) (engineGroup *EngineGroup, err error)
func OpenDBEngine ¶
func OpenDBEngine(conf DBConfig, showSQL bool) (*EngineGroup, error)
func OpenSingleDBEngine ¶
func OpenSingleDBEngine(conf *Config, showSQL bool) (*EngineGroup, error)
func (*EngineGroup) Begin ¶
func (eg *EngineGroup) Begin() (*SqlDB, error)
func (*EngineGroup) BeginContext ¶
func (eg *EngineGroup) BeginContext(ctx context.Context) (*SqlDB, error)
func (*EngineGroup) Close ¶
func (eg *EngineGroup) Close()
func (*EngineGroup) Commit ¶
func (eg *EngineGroup) Commit() error
func (*EngineGroup) DriverName ¶
func (eg *EngineGroup) DriverName() string
func (*EngineGroup) Exec ¶
func (eg *EngineGroup) Exec(query string, args ...interface{}) (result sql.Result, err error)
func (*EngineGroup) ExecContext ¶
func (*EngineGroup) Query ¶
func (eg *EngineGroup) Query(query string, args ...interface{}) (rows *sqlx.Rows, err error)
func (*EngineGroup) QueryContext ¶
func (*EngineGroup) QueryRow ¶
func (eg *EngineGroup) QueryRow(query string, args ...interface{}) (row *sqlx.Row)
func (*EngineGroup) QueryRowContext ¶
func (*EngineGroup) Raw ¶
func (eg *EngineGroup) Raw(query string, args ...interface{}) *RawSession
func (*EngineGroup) RawContext ¶
func (eg *EngineGroup) RawContext(ctx context.Context, query string, args ...interface{}) *RawSession
func (*EngineGroup) Rebind ¶
func (eg *EngineGroup) Rebind(query string) string
func (*EngineGroup) Rollback ¶
func (eg *EngineGroup) Rollback() error
func (*EngineGroup) SetPolicy ¶
func (eg *EngineGroup) SetPolicy(dbAlias string, policy IPolicy) *EngineGroup
func (*EngineGroup) Table ¶
func (eg *EngineGroup) Table(table string) *Session
func (*EngineGroup) TableContext ¶
func (eg *EngineGroup) TableContext(ctx context.Context, table string) *Session
func (*EngineGroup) Use ¶
func (eg *EngineGroup) Use(dbAlias ...string) *SqlDB
type ExecResult ¶
type ExecResult struct {
// contains filtered or unexported fields
}
type IPolicy ¶
type IPolicy interface {
Slave(engine *ConnectionEngine) *Connection
}
type ISqlx ¶
type ISqlx interface { Queryx(query string, args ...interface{}) (*sqlx.Rows, error) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) QueryRowx(query string, args ...interface{}) *sqlx.Row QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row Exec(query string, args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) Rebind(query string) string DriverName() string }
type PolicyHandler ¶
type PolicyHandler func(engine *ConnectionEngine) *Connection
func WeightRoundRobinPolicy ¶
func WeightRoundRobinPolicy(params PolicyParams) PolicyHandler
权重轮询访问负载策略
func (PolicyHandler) Slave ¶
func (handler PolicyHandler) Slave(engine *ConnectionEngine) *Connection
type PolicyOptions ¶
type PolicyOptions struct { Mode string Params interface{} }
type PolicyParams ¶
type PolicyParams struct {
Weights []int
}
type RawSession ¶
type RawSession struct {
// contains filtered or unexported fields
}
func (*RawSession) Fetch ¶
func (raw *RawSession) Fetch(dest interface{}) error
func (*RawSession) Master ¶
func (raw *RawSession) Master() *RawSession
func (*RawSession) QueryRow ¶
func (raw *RawSession) QueryRow() (row *sqlx.Row)
type ReflectMapper ¶
type ReflectMapper struct {
// contains filtered or unexported fields
}
func NewReflectMapper ¶
func NewReflectMapper(tagName string) *ReflectMapper
func NewReflectMapperFunc ¶
func NewReflectMapperFunc(tagName string, f func(string) string) *ReflectMapper
func (*ReflectMapper) FieldByName ¶
type Session ¶
type Session struct { Error error // contains filtered or unexported fields }
func (*Session) BulkCreate ¶
批量创建,返回表自增ID列表; 值可以map或struct组成的slice或array
func (*Session) BulkUpdate ¶
批量修改多个字段,返回受影响的行数
func (*Session) SelectExpr ¶
type SqlDB ¶
type SqlDB struct {
// contains filtered or unexported fields
}
func NewSqlDB ¶
func NewSqlDB(engine *ConnectionEngine, logging bool) *SqlDB
func (*SqlDB) DriverName ¶
func (*SqlDB) ExecContext ¶
func (*SqlDB) QueryContext ¶
func (*SqlDB) QueryRowContext ¶
func (*SqlDB) Raw ¶
func (db *SqlDB) Raw(query string, args ...interface{}) *RawSession
func (*SqlDB) RawContext ¶
func (db *SqlDB) RawContext(ctx context.Context, query string, args ...interface{}) *RawSession
func (*SqlDB) TableContext ¶
type Statement ¶
type Statement struct { Dialector dialects.Dialector Tables []clause.Table Clauses map[string]clause.Clause SQL strings.Builder SQLVars []interface{} NamedVars []sql.NamedArg Hint string // 用于指定数据库中间件的命令,比如 /*+TDDL:slave()*/ }
func (*Statement) AddClauseIfNotExists ¶
如果子句不存在则添加
func (*Statement) BuildCondition ¶
func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) (conditions []clause.Expression, err error)
构建表达式
func (*Statement) WriteQuoted ¶
type StatementModifier ¶
type StatementModifier interface {
ModifyStatement(*Statement)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.