Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultLogger() func(e *Engin)
- func GetErr(err Error, args ...interface{}) error
- func If(condition bool, trueVal, falseVal interface{}) interface{}
- func StructToMap(obj interface{}) map[string]interface{}
- type BindType
- type Binder
- func (s *Binder) BindParse(prefix string) error
- func (o *Binder) GetBindAll() []Data
- func (o *Binder) GetBindFields() []string
- func (o *Binder) GetBindName() string
- func (o *Binder) GetBindOrigin() interface{}
- func (o *Binder) GetBindPrefix() string
- func (o *Binder) GetBindResult() interface{}
- func (o *Binder) GetBindResultSlice() reflect.Value
- func (o *Binder) GetBindType() BindType
- func (o *Binder) ResetBindResultSlice()
- func (o *Binder) SetBindAll(arg []Data)
- func (o *Binder) SetBindFields(arg []string)
- func (o *Binder) SetBindName(arg string)
- func (o *Binder) SetBindOrigin(arg interface{})
- func (o *Binder) SetBindPrefix(arg string)
- func (o *Binder) SetBindResult(arg interface{})
- func (o *Binder) SetBindResultSlice(arg reflect.Value)
- func (o *Binder) SetBindType(arg BindType)
- type BuilderClickhouse
- type BuilderDefault
- func (b *BuilderDefault) BuildData(operType string) (string, string, string)
- func (b *BuilderDefault) BuildData2(operType string) (string, string, string)
- func (b *BuilderDefault) BuildDistinct() (dis string)
- func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []interface{}, err error)
- func (b *BuilderDefault) BuildFields() string
- func (b *BuilderDefault) BuildGroup() string
- func (b *BuilderDefault) BuildHaving() string
- func (b *BuilderDefault) BuildJoin() (s string, err error)
- func (b *BuilderDefault) BuildLimit() string
- func (b *BuilderDefault) BuildOffset() string
- func (b *BuilderDefault) BuildOrder() string
- func (b *BuilderDefault) BuildQuery() (sqlStr string, args []interface{}, err error)
- func (b *BuilderDefault) BuildTable() string
- func (b *BuilderDefault) BuildWhere() (where string, err error)
- func (b *BuilderDefault) GetOperator() []string
- func (b *BuilderDefault) GetPlaceholder() (phstr string)
- func (b *BuilderDefault) SetDriver(dr string) *BuilderDefault
- type BuilderDriver
- type BuilderMsSql
- type BuilderMysql
- type BuilderOracle
- func (b *BuilderOracle) BuildData(operType string) (string, string, string)
- func (b *BuilderOracle) BuildData2(operType string) (string, string, string)
- func (b *BuilderOracle) BuildDistinct() (dis string)
- func (b *BuilderOracle) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
- func (b *BuilderOracle) BuildExecuteOra(operType string) (sqlStr string, args []interface{}, err error)
- func (b *BuilderOracle) BuildFields() string
- func (b *BuilderOracle) BuildGroup() string
- func (b *BuilderOracle) BuildHaving() string
- func (b *BuilderOracle) BuildJoin() (s string, err error)
- func (b *BuilderOracle) BuildLimit() string
- func (b *BuilderOracle) BuildOffset() string
- func (b *BuilderOracle) BuildOrder() string
- func (b *BuilderOracle) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
- func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err error)
- func (b *BuilderOracle) BuildTable() string
- func (b *BuilderOracle) BuildWhere() (where string, err error)
- func (b *BuilderOracle) GetOperator() []string
- func (b *BuilderOracle) GetPlaceholder() (phstr string)
- func (b *BuilderOracle) SetDriver(dr string) *BuilderOracle
- type BuilderPostgres
- type BuilderSqlite3
- type Config
- type ConfigCluster
- type Data
- type Engin
- func (c *Engin) GetDriver() string
- func (c *Engin) GetExecuteDB() *sql.DB
- func (c *Engin) GetLogger() ILogger
- func (c *Engin) GetPrefix() string
- func (c *Engin) GetQueryDB() *sql.DB
- func (c *Engin) IgnoreName(arg string)
- func (c *Engin) NewOrm() IOrm
- func (c *Engin) NewSession() ISession
- func (c *Engin) Ping() error
- func (c *Engin) SetPrefix(pre string)
- func (c *Engin) TagName(arg string)
- func (c *Engin) Use(closers ...func(e *Engin))
- type Err
- type Error
- type IBinder
- type IBuilder
- type IEngin
- type ILogger
- type IOrm
- type IOrmApi
- type IOrmExecute
- type IOrmQuery
- type IOrmSession
- type ISession
- type Lang
- type LogLevel
- type LogOption
- type Logger
- type Map
- type Orm
- func (dba *Orm) AddFields(fields ...string) IOrm
- func (dba *Orm) Avg(avg string) (interface{}, error)
- func (dba *Orm) BuildSql(operType ...string) (a string, b []interface{}, err error)
- func (dba *Orm) Chunk(limit int, callback func([]Data) error) (err error)
- func (dba *Orm) ClearBindValues()
- func (dba *Orm) Count(args ...string) (int64, error)
- func (dba *Orm) CrossJoin(args ...interface{}) IOrm
- func (dba *Orm) Data(data interface{}) IOrm
- func (dba *Orm) Decrement(args ...interface{}) (int64, error)
- func (dba *Orm) Delete() (int64, error)
- func (dba *Orm) Distinct() IOrm
- func (dba *Orm) ExtraCols(args ...string) IOrm
- func (dba *Orm) Fields(fields ...string) IOrm
- func (dba *Orm) First() (result Data, err error)
- func (dba *Orm) Force() IOrm
- func (dba *Orm) Get() (result []Data, err error)
- func (dba *Orm) GetBindValues() []interface{}
- func (o *Orm) GetData() interface{}
- func (o *Orm) GetDistinct() bool
- func (dba *Orm) GetDriver() string
- func (dba *Orm) GetExtraCols() []string
- func (o *Orm) GetFields() []string
- func (dba *Orm) GetForce() bool
- func (o *Orm) GetGroup() string
- func (o *Orm) GetHaving() string
- func (dba *Orm) GetISession() ISession
- func (o *Orm) GetJoin() [][]interface{}
- func (o *Orm) GetLimit() int
- func (o *Orm) GetOffset() int
- func (o *Orm) GetOrder() string
- func (dba *Orm) GetPessimisticLock() string
- func (o *Orm) GetTable() string
- func (o *Orm) GetWhere() []interface{}
- func (dba *Orm) Group(group string) IOrm
- func (dba *Orm) GroupBy(group string) IOrm
- func (dba *Orm) Having(having string) IOrm
- func (dba *Orm) Hello()
- func (dba *Orm) Increment(args ...interface{}) (int64, error)
- func (dba *Orm) Insert(data ...interface{}) (int64, error)
- func (dba *Orm) InsertGetId(data ...interface{}) (int64, error)
- func (dba *Orm) Join(joinType string, args ...interface{}) IOrm
- func (dba *Orm) LeftJoin(args ...interface{}) IOrm
- func (dba *Orm) Limit(limit int) IOrm
- func (dba *Orm) LockForUpdate() *Orm
- func (dba *Orm) Loop(limit int, callback func([]Data) error) (err error)
- func (dba *Orm) Max(max string) (interface{}, error)
- func (dba *Orm) Min(min string) (interface{}, error)
- func (dba *Orm) Offset(offset int) IOrm
- func (dba *Orm) OrWhere(args ...interface{}) IOrm
- func (dba *Orm) OrWhereBetween(needle string, hystack []interface{}) IOrm
- func (dba *Orm) OrWhereIn(needle string, hystack []interface{}) IOrm
- func (dba *Orm) OrWhereNotBetween(needle string, hystack []interface{}) IOrm
- func (dba *Orm) OrWhereNotIn(needle string, hystack []interface{}) IOrm
- func (dba *Orm) OrWhereNotNull(arg string) IOrm
- func (dba *Orm) OrWhereNull(arg string) IOrm
- func (dba *Orm) Order(order string) IOrm
- func (dba *Orm) OrderBy(order string) IOrm
- func (dba *Orm) Page(page int) IOrm
- func (dba *Orm) Paginate() (res Data, err error)
- func (dba *Orm) Pluck(field string, fieldKey ...string) (v interface{}, err error)
- func (dba *Orm) Reset() IOrm
- func (dba *Orm) ResetExtraCols() IOrm
- func (dba *Orm) ResetUnion() IOrm
- func (dba *Orm) ResetWhere() IOrm
- func (dba *Orm) RightJoin(args ...interface{}) IOrm
- func (dba *Orm) Select() error
- func (dba *Orm) SetBindValues(v ...interface{})
- func (dba *Orm) SetISession(is ISession)
- func (o *Orm) SetWhere(arg []interface{})
- func (dba *Orm) SharedLock() *Orm
- func (dba *Orm) Sum(sum string) (interface{}, error)
- func (dba *Orm) Table(tab interface{}) IOrm
- func (s *Orm) Transaction(closers ...func(db IOrm) error) (err error)
- func (dba *Orm) Update(data ...interface{}) (int64, error)
- func (dba *Orm) Value(field string) (v interface{}, err error)
- func (dba *Orm) Where(args ...interface{}) IOrm
- func (dba *Orm) WhereBetween(needle string, hystack []interface{}) IOrm
- func (dba *Orm) WhereIn(needle string, hystack []interface{}) IOrm
- func (dba *Orm) WhereNotBetween(needle string, hystack []interface{}) IOrm
- func (dba *Orm) WhereNotIn(needle string, hystack []interface{}) IOrm
- func (dba *Orm) WhereNotNull(arg string) IOrm
- func (dba *Orm) WhereNull(arg string) IOrm
- type OrmApi
- type Session
- func (s *Session) Begin() (err error)
- func (s *Session) Bind(tab interface{}) ISession
- func (s *Session) Close()
- func (s *Session) Commit() (err error)
- func (s *Session) Execute(sqlstring string, args ...interface{}) (rowsAffected int64, err error)
- func (s *Session) GetErr() error
- func (s *Session) GetIBinder() IBinder
- func (s *Session) GetIEngin() IEngin
- func (s *Session) GetTableName() (string, error)
- func (s *Session) GetTransaction() bool
- func (s *Session) GetUnion() interface{}
- func (s *Session) LastInsertId() int64
- func (s *Session) LastSql() string
- func (s *Session) Query(sqlstring string, args ...interface{}) (result []Data, err error)
- func (s *Session) ResetBinderResult()
- func (s *Session) Rollback() (err error)
- func (s *Session) SetIBinder(ib IBinder)
- func (s *Session) SetIEngin(ie IEngin)
- func (s *Session) SetTransaction(b bool)
- func (s *Session) SetUnion(u interface{})
- func (s *Session) Transaction(closers ...func(ses ISession) error) (err error)
Constants ¶
const ( VERSION_TEXT = "\ngolang orm of gorose's version: " VERSION_NO = "v1.0.0x" VERSION = VERSION_TEXT + VERSION_NO + GOROSE_IMG )
const (
DriverOracle = "oci8" // 默认驱动
)
const GOROSE_IMG = `` /* 710-byte string literal not displayed */
Variables ¶
var BindString = map[BindType]string{ OBJECT_STRUCT: "OBJECT_STRUCT", OBJECT_STRUCT_SLICE: "OBJECT_STRUCT_SLICE", OBJECT_MAP: "OBJECT_MAP", OBJECT_MAP_SLICE: "OBJECT_MAP_SLICE", OBJECT_STRING: "OBJECT_STRING", OBJECT_MAP_T: "OBJECT_MAP_T", OBJECT_MAP_SLICE_T: "OBJECT_MAP_SLICE_T", OBJECT_NIL: "OBJECT_NIL", }
var IGNORE = "-"
var TAGNAME = "gorose"
Functions ¶
func DefaultLogger ¶
func DefaultLogger() func(e *Engin)
func If ¶
func If(condition bool, trueVal, falseVal interface{}) interface{}
If : ternary operator (三元运算) condition:比较运算 trueVal:运算结果为真时的值 falseVal:运算结果为假时的值 return: 由于不知道传入值的类型, 所有, 必须在接收结果时, 指定对应的值类型
func StructToMap ¶
func StructToMap(obj interface{}) map[string]interface{}
Types ¶
type BindType ¶
type BindType int
const ( OBJECT_STRUCT BindType = iota // 结构体 一条数据 (struct) OBJECT_STRUCT_SLICE // 结构体 多条数据 ([]struct) OBJECT_MAP // map 一条数据 (map[string]interface{}) OBJECT_MAP_SLICE // map 多条数据 ([]map[string]interface{}) OBJECT_STRING // 非结构体 表名字符串 ("users") OBJECT_MAP_T // map 一条数据 (map[string]t.T) OBJECT_MAP_SLICE_T // map 多条数据 ([]map[string]t.T) OBJECT_NIL // 默认没有传入任何绑定对象,一般用于query直接返回 )
type Binder ¶
type Binder struct {
// Bind是指传入的对象 [slice]map,[slice]struct
// 传入的原始对象
BindOrigin interface{}
//BindOriginTableName []string
// 解析出来的对象名字, 或者指定的method(TableName)获取到的名字
BindName string
// 一条结果的反射对象
BindResult interface{}
// 多条
BindResultSlice reflect.Value
// 传入结构体解析出来的字段
BindFields []string
// 传入的对象类型判定
BindType BindType
// 出入传入得是非slice对象, 则只需要取一条, 取多了也是浪费
BindLimit int
BindPrefix string
// 多条map结果,传入的是string table时
BindAll []Data
}
func (*Binder) GetBindAll ¶
func (*Binder) GetBindFields ¶
func (*Binder) GetBindName ¶
func (*Binder) GetBindOrigin ¶
func (o *Binder) GetBindOrigin() interface{}
func (*Binder) GetBindPrefix ¶
func (*Binder) GetBindResult ¶
func (o *Binder) GetBindResult() interface{}
func (*Binder) GetBindResultSlice ¶
func (*Binder) GetBindType ¶
func (*Binder) ResetBindResultSlice ¶
func (o *Binder) ResetBindResultSlice()
func (*Binder) SetBindAll ¶
func (*Binder) SetBindFields ¶
func (*Binder) SetBindName ¶
func (*Binder) SetBindOrigin ¶
func (o *Binder) SetBindOrigin(arg interface{})
func (*Binder) SetBindPrefix ¶
func (*Binder) SetBindResult ¶
func (o *Binder) SetBindResult(arg interface{})
func (*Binder) SetBindResultSlice ¶
func (*Binder) SetBindType ¶
type BuilderClickhouse ¶
type BuilderClickhouse struct {
// contains filtered or unexported fields
}
func (*BuilderClickhouse) BuildExecute ¶
func (b *BuilderClickhouse) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderClickhouse) BuildQuery ¶
func (b *BuilderClickhouse) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
BuildQuery : build query sql string
type BuilderDefault ¶
type BuilderDefault struct {
IOrm
// contains filtered or unexported fields
}
func NewBuilderDefault ¶
func NewBuilderDefault(o IOrm) *BuilderDefault
func (*BuilderDefault) BuildData ¶
func (b *BuilderDefault) BuildData(operType string) (string, string, string)
BuildData : build inert or update data
func (*BuilderDefault) BuildData2 ¶
func (b *BuilderDefault) BuildData2(operType string) (string, string, string)
func (*BuilderDefault) BuildDistinct ¶
func (b *BuilderDefault) BuildDistinct() (dis string)
func (*BuilderDefault) BuildExecute ¶
func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute query string
func (*BuilderDefault) BuildFields ¶
func (b *BuilderDefault) BuildFields() string
func (*BuilderDefault) BuildGroup ¶
func (b *BuilderDefault) BuildGroup() string
func (*BuilderDefault) BuildHaving ¶
func (b *BuilderDefault) BuildHaving() string
func (*BuilderDefault) BuildJoin ¶
func (b *BuilderDefault) BuildJoin() (s string, err error)
func (*BuilderDefault) BuildLimit ¶
func (b *BuilderDefault) BuildLimit() string
func (*BuilderDefault) BuildOffset ¶
func (b *BuilderDefault) BuildOffset() string
func (*BuilderDefault) BuildOrder ¶
func (b *BuilderDefault) BuildOrder() string
func (*BuilderDefault) BuildQuery ¶
func (b *BuilderDefault) BuildQuery() (sqlStr string, args []interface{}, err error)
func (*BuilderDefault) BuildTable ¶
func (b *BuilderDefault) BuildTable() string
func (*BuilderDefault) BuildWhere ¶
func (b *BuilderDefault) BuildWhere() (where string, err error)
func (*BuilderDefault) GetOperator ¶
func (b *BuilderDefault) GetOperator() []string
func (*BuilderDefault) GetPlaceholder ¶
func (b *BuilderDefault) GetPlaceholder() (phstr string)
GetPlaceholder 获取占位符
func (*BuilderDefault) SetDriver ¶
func (b *BuilderDefault) SetDriver(dr string) *BuilderDefault
SetDriver 设置驱动, 方便获取占位符使用
type BuilderDriver ¶
type BuilderDriver struct {
// contains filtered or unexported fields
}
func NewBuilderDriver ¶
func NewBuilderDriver() *BuilderDriver
func (*BuilderDriver) Getter ¶
func (b *BuilderDriver) Getter(driver string) (ib IBuilder)
func (*BuilderDriver) Register ¶
func (b *BuilderDriver) Register(driver string, val IBuilder)
type BuilderMsSql ¶
type BuilderMsSql struct {
// contains filtered or unexported fields
}
func (*BuilderMsSql) BuildExecute ¶
func (b *BuilderMsSql) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderMsSql) BuildQuery ¶
func (b *BuilderMsSql) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
BuildQuery : build query sql string
type BuilderMysql ¶
type BuilderMysql struct {
// contains filtered or unexported fields
}
func (*BuilderMysql) BuildExecute ¶
func (b *BuilderMysql) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderMysql) BuildQuery ¶
func (b *BuilderMysql) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
BuildQuery : build query sql string
type BuilderOracle ¶
type BuilderOracle struct {
BuilderDefault
}
func NewBuilderOracle ¶
func NewBuilderOracle(o IOrm) *BuilderOracle
func (*BuilderOracle) BuildData ¶
func (b *BuilderOracle) BuildData(operType string) (string, string, string)
func (*BuilderOracle) BuildData2 ¶
func (b *BuilderOracle) BuildData2(operType string) (string, string, string)
func (*BuilderOracle) BuildDistinct ¶
func (b *BuilderOracle) BuildDistinct() (dis string)
func (*BuilderOracle) BuildExecute ¶
func (b *BuilderOracle) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderOracle) BuildExecuteOra ¶
func (b *BuilderOracle) BuildExecuteOra(operType string) (sqlStr string, args []interface{}, err error)
func (*BuilderOracle) BuildFields ¶
func (b *BuilderOracle) BuildFields() string
func (*BuilderOracle) BuildGroup ¶
func (b *BuilderOracle) BuildGroup() string
func (*BuilderOracle) BuildHaving ¶
func (b *BuilderOracle) BuildHaving() string
func (*BuilderOracle) BuildJoin ¶
func (b *BuilderOracle) BuildJoin() (s string, err error)
func (*BuilderOracle) BuildLimit ¶
func (b *BuilderOracle) BuildLimit() string
func (*BuilderOracle) BuildOffset ¶
func (b *BuilderOracle) BuildOffset() string
func (*BuilderOracle) BuildOrder ¶
func (b *BuilderOracle) BuildOrder() string
func (*BuilderOracle) BuildQuery ¶
func (b *BuilderOracle) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
实现接口 BuildQuery : build query sql string
func (*BuilderOracle) BuildQueryOra ¶
func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err error)
func (*BuilderOracle) BuildTable ¶
func (b *BuilderOracle) BuildTable() string
func (*BuilderOracle) BuildWhere ¶
func (b *BuilderOracle) BuildWhere() (where string, err error)
func (*BuilderOracle) GetOperator ¶
func (b *BuilderOracle) GetOperator() []string
func (*BuilderOracle) GetPlaceholder ¶
func (b *BuilderOracle) GetPlaceholder() (phstr string)
GetPlaceholder 获取占位符
func (*BuilderOracle) SetDriver ¶
func (b *BuilderOracle) SetDriver(dr string) *BuilderOracle
SetDriver 设置驱动, 方便获取占位符使用
type BuilderPostgres ¶
type BuilderPostgres struct {
// contains filtered or unexported fields
}
func (*BuilderPostgres) BuildExecute ¶
func (b *BuilderPostgres) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderPostgres) BuildQuery ¶
func (b *BuilderPostgres) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
BuildQuery : build query sql string
type BuilderSqlite3 ¶
type BuilderSqlite3 struct {
// contains filtered or unexported fields
}
func (*BuilderSqlite3) BuildExecute ¶
func (b *BuilderSqlite3) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
BuildExecut : build execute sql string
func (*BuilderSqlite3) BuildQuery ¶
func (b *BuilderSqlite3) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
BuildQuery : build query sql string
type Config ¶
type Config struct {
Driver string // 驱动: mysql/sqlite3/oracle/mssql/postgres/clickhouse, 如果集群配置了驱动, 这里可以省略
// mysql 示例:
// root:root@tcp(localhost:3306)/test?charset=utf8&parseTime=true
Dsn string // 数据库链接
SetMaxOpenConns int // (连接池)最大打开的连接数,默认值为0表示不限制
SetMaxIdleConns int // (连接池)闲置的连接数, 默认0
Prefix string // 表前缀, 如果集群配置了前缀, 这里可以省略
}
type ConfigCluster ¶
type Engin ¶
type Engin struct {
// contains filtered or unexported fields
}
func (*Engin) GetExecuteDB ¶
GetExecuteDB : get a master db for using execute operation GetExecuteDB : 获取一个主库用来做查询之外的操作
func (*Engin) GetQueryDB ¶
GetQueryDB : get a slave db for using query operation GetQueryDB : 获取一个从库用来做查询操作
func (*Engin) NewOrm ¶
NewOrm 获取orm实例 这是一个语法糖, 为了方便使用(engin.NewOrm())添加的 添加后会让engin和 orm 耦合, 如果不想耦合, 就删掉此方法 删掉这个方法后,可以使用 gorose.NewOrm(gorose.NewSession(gorose.IEngin)) 通过 gorose.ISession 依赖注入的方式, 达到解耦的目的
func (*Engin) NewSession ¶
NewSession 获取session实例 这是一个语法糖, 为了方便使用(engin.NewSession())添加的 添加后会让engin和session耦合, 如果不想耦合, 就删掉此方法 删掉这个方法后,可以使用 gorose.NewSession(gorose.IEngin) 通过 gorose.IEngin 依赖注入的方式, 达到解耦的目的
type IBinder ¶
type IBinder interface {
SetBindOrigin(arg interface{})
GetBindOrigin() interface{}
SetBindName(arg string)
GetBindName() string
SetBindResult(arg interface{})
GetBindResult() interface{}
SetBindResultSlice(arg reflect.Value)
GetBindResultSlice() reflect.Value
SetBindFields(arg []string)
GetBindFields() []string
SetBindType(arg BindType)
GetBindType() BindType
//SetBindLimit(arg int)
//GetBindLimit() int
BindParse(prefix string) error
SetBindPrefix(arg string)
GetBindPrefix() string
ResetBindResultSlice()
SetBindAll(arg []Data)
GetBindAll() []Data
}
type IBuilder ¶
type IBuilder interface {
BuildQuery(orm IOrm) (sqlStr string, args []interface{}, err error)
BuildExecute(orm IOrm, operType string) (sqlStr string, args []interface{}, err error)
}
func NewBuilder ¶
type IOrm ¶
type IOrm interface {
IOrmApi
IOrmQuery
IOrmExecute
IOrmSession
//ISession
Hello()
BuildSql(operType ...string) (string, []interface{}, error)
Table(tab interface{}) IOrm
// fields=select
Fields(fields ...string) IOrm
AddFields(fields ...string) IOrm
// distinct 方法允许你强制查询返回不重复的结果集:
Distinct() IOrm
Data(data interface{}) IOrm
// groupBy, orderBy, having
Group(group string) IOrm
GroupBy(group string) IOrm
Having(having string) IOrm
Order(order string) IOrm
OrderBy(order string) IOrm
Limit(limit int) IOrm
Offset(offset int) IOrm
Page(page int) IOrm
// joinType: inner,left,right,cross
Join(joinType string, args ...interface{}) IOrm
LeftJoin(args ...interface{}) IOrm
RightJoin(args ...interface{}) IOrm
CrossJoin(args ...interface{}) IOrm
// `Where`,`OrWhere`,`WhereNull / WhereNotNull`,`WhereIn / WhereNotIn / OrWhereIn / OrWhereNotIn`,`WhereBetween / WhereBetwee / OrWhereBetween / OrWhereNotBetween`
Where(args ...interface{}) IOrm
OrWhere(args ...interface{}) IOrm
WhereNull(arg string) IOrm
OrWhereNull(arg string) IOrm
WhereNotNull(arg string) IOrm
OrWhereNotNull(arg string) IOrm
WhereIn(needle string, hystack []interface{}) IOrm
OrWhereIn(needle string, hystack []interface{}) IOrm
WhereNotIn(needle string, hystack []interface{}) IOrm
OrWhereNotIn(needle string, hystack []interface{}) IOrm
WhereBetween(needle string, hystack []interface{}) IOrm
OrWhereBetween(needle string, hystack []interface{}) IOrm
WhereNotBetween(needle string, hystack []interface{}) IOrm
OrWhereNotBetween(needle string, hystack []interface{}) IOrm
// truncate
//Truncate()
GetDriver() string
//GetIBinder() IBinder
SetBindValues(v ...interface{})
GetBindValues() []interface{}
ClearBindValues()
Transaction(closers ...func(db IOrm) error) (err error)
Reset() IOrm
ResetWhere() IOrm
GetISession() ISession
// sharedLock(lock in share mode) 不会阻塞其它事务读取被锁定行记录的值
SharedLock() *Orm
// 此外你还可以使用 lockForUpdate 方法。“for update”锁避免选择行被其它共享锁修改或删除:
// 会阻塞其他锁定性读对锁定行的读取(非锁定性读仍然可以读取这些记录,lock in share mode 和 for update 都是锁定性读)
LockForUpdate() *Orm
ResetUnion() IOrm
}
type IOrmApi ¶
type IOrmApi interface {
GetTable() string
GetFields() []string
SetWhere(arg []interface{})
GetWhere() []interface{}
GetOrder() string
GetLimit() int
GetOffset() int
GetJoin() [][]interface{}
GetDistinct() bool
GetGroup() string
GetHaving() string
GetData() interface{}
ExtraCols(args ...string) IOrm
ResetExtraCols() IOrm
GetExtraCols() []string
GetPessimisticLock() string
}
type IOrmExecute ¶
type IOrmExecute interface {
GetForce() bool
// insert,insertGetId
Insert(data ...interface{}) (int64, error)
InsertGetId(data ...interface{}) (int64, error)
Update(data ...interface{}) (int64, error)
// increment,decrement
// 在操作过程中你还可以指定额外的列进行更新:
Increment(args ...interface{}) (int64, error)
Decrement(args ...interface{}) (int64, error)
// delete
Delete() (int64, error)
//LastInsertId() int64
Force() IOrm
}
type IOrmQuery ¶
type IOrmQuery interface {
// 获取数据, 依据传入的绑定对象, 选择查询一条或多条数据并绑定到传入对象上
// 当绑定对象传入的是string类型时, 返回多条结果集, 需要使用 Get() 来获取最终结果
Select() error
// 获取一条结果并返回, 只有当传入的table对象是字符串时生效
First() (Data, error)
// 获取多条结果并返回, 只有当传入的table对象是字符串时生效
Get() ([]Data, error)
// 如果你不需要完整的一行,可以使用 value 方法从结果中获取单个值,该方法会直接返回指定列的值:
Value(field string) (v interface{}, err error)
// 如果想要获取包含单个列值的数组,可以使用 pluck 方法
// 还可以在返回数组中为列值指定自定义键(该自定义键必须是该表的其它字段列名,否则会报错)
Pluck(field string, fieldKey ...string) (v interface{}, err error)
// 查询构建器还提供了多个聚合方法,如count, max, min, avg 和 sum,你可以在构造查询之后调用这些方法:
Count(args ...string) (int64, error)
Sum(sum string) (interface{}, error)
Avg(avg string) (interface{}, error)
Max(max string) (interface{}, error)
Min(min string) (interface{}, error)
// 分页, 返回分页需要的基本数据
Paginate() (res Data, err error)
// 组块结果集
// 如果你需要处理成千上万或者更多条数据库记录,可以考虑使用 chunk 方法,该方法一次获取结果集的一小块,
// 然后传递每一小块数据到闭包函数进行处理,该方法在编写处理大量数据库记录的 Artisan 命令的时候非常有用。
// 例如,我们可以将处理全部 users 表数据分割成一次处理 100 条记录的小组块
// 你可以通过从闭包函数中返回 err 来终止组块的运行
Chunk(limit int, callback func([]Data) error) (err error)
Loop(limit int, callback func([]Data) error) (err error)
}
type IOrmSession ¶
type IOrmSession interface {
//Close()
//Table(bind interface{}) IOrm
//Bind(bind interface{}) ISession
Begin() (err error)
Rollback() (err error)
Commit() (err error)
//Transaction(closer ...func(session ISession) error) (err error)
Query(sqlstring string, args ...interface{}) ([]Data, error)
Execute(sqlstring string, args ...interface{}) (int64, error)
//GetMasterDriver() string
//GetSlaveDriver() string
LastInsertId() int64
LastSql() string
//SetIBinder(b IBinder)
//GetTableName() (string, error)
GetIBinder() IBinder
SetUnion(u interface{})
GetUnion() interface{}
}
type ISession ¶
type ISession interface {
Close()
//Table(bind interface{}) IOrm
Bind(bind interface{}) ISession
Begin() (err error)
Rollback() (err error)
Commit() (err error)
Transaction(closer ...func(session ISession) error) (err error)
Query(sqlstring string, args ...interface{}) ([]Data, error)
Execute(sqlstring string, args ...interface{}) (int64, error)
//GetDriver() string
GetIEngin() IEngin
LastInsertId() int64
LastSql() string
//SetIBinder(b IBinder)
GetTableName() (string, error)
SetIBinder(ib IBinder)
GetIBinder() IBinder
SetUnion(u interface{})
GetUnion() interface{}
SetTransaction(b bool)
GetTransaction() bool
//ResetBinder()
GetBindAll() []Data
GetErr() error
}
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) EnableErrorLog ¶
func (*Logger) EnableSlowLog ¶
func (*Logger) EnableSqlLog ¶
type Orm ¶
func (*Orm) AddFields ¶
AddFields : If you already have a query builder instance and you wish to add a column to its existing select clause, you may use the AddFields method:
func (*Orm) Chunk ¶
Chunk : 分块处理数据,当要处理很多数据的时候, 我不需要知道具体是多少数据, 我只需要每次取limit条数据, 然后不断的增加offset去取更多数据, 从而达到分块处理更多数据的目的 TODO 后续增加 gorotine 支持, 提高批量数据处理效率, 预计需要增加获取更多链接的支持
func (*Orm) ClearBindValues ¶
func (dba *Orm) ClearBindValues()
func (*Orm) Decrement ¶
Decrement : auto Decrement -1 default we can define step (such as 2, 3, 6 ...) if give the second params
func (*Orm) GetBindValues ¶
func (dba *Orm) GetBindValues() []interface{}
func (*Orm) GetDistinct ¶
func (*Orm) GetExtraCols ¶
func (*Orm) GetISession ¶
func (*Orm) GetPessimisticLock ¶
func (*Orm) Increment ¶
Increment : auto Increment +1 default we can define step (such as 2, 3, 6 ...) if give the second params we can use this method as decrement with the third param as "-" orm.Increment("top") , orm.Increment("top", 2, "-")=orm.Decrement("top",2)
func (*Orm) InsertGetId ¶
insertGetId : insert data and get id
func (*Orm) LockForUpdate ¶
LockForUpdate select * from xxx for update
func (*Orm) Loop ¶
Loop : 同chunk, 不过, 这个是循环的取前limit条数据, 为什么是循环取这些数据呢 因为, 我们考虑到一种情况, 那就是where条件如果刚好是要修改的值, 那么最后的修改结果因为offset的原因, 只会修改一半, 比如: DB().Where("age", 18) ===> DB().Data(gorose.Data{"age":19}).Where().Update()
func (*Orm) OrWhereBetween ¶
func (*Orm) OrWhereNotBetween ¶
func (*Orm) OrWhereNotIn ¶
func (*Orm) OrWhereNotNull ¶
func (*Orm) OrWhereNull ¶
func (*Orm) Paginate ¶
Paginate 自动分页 @param limit 每页展示数量 @param current_page 当前第几页, 从1开始 以下是laravel的Paginate返回示例
{
"total": 50,
"per_page": 15,
"current_page": 1,
"last_page": 4,
"first_page_url": "http://laravel.app?page=1",
"last_page_url": "http://laravel.app?page=4",
"next_page_url": "http://laravel.app?page=2",
"prev_page_url": null,
"path": "http://laravel.app",
"from": 1,
"to": 15,
"data":[
{
// Result Object
},
{
// Result Object
}
]
}
func (*Orm) ResetExtraCols ¶
func (*Orm) SetBindValues ¶
func (dba *Orm) SetBindValues(v ...interface{})
func (*Orm) SetISession ¶
func (*Orm) SharedLock ¶
SharedLock 共享锁 select * from xxx lock in share mode
func (*Orm) Where ¶
where 查询条件 @param args 支持0-3个参数 1个时为:slice或map 2个时为:参数1:$and|$or|字段名, 参数2: slice|slice|[real value或slice] 3个时为:参数1: 字段名, 参数2: >,<,>=,<=, <>, in, not in, between, like 等待关系连接符, 参数3为条件值
func (*Orm) WhereBetween ¶
func (*Orm) WhereNotBetween ¶
func (*Orm) WhereNotIn ¶
func (*Orm) WhereNotNull ¶
type Session ¶
func (*Session) Bind ¶
Bind : 传入绑定结果的对象, 参数一为对象, 可以是 struct, gorose.MapRow 或对应的切片
如果是做非query操作,第一个参数也可以仅仅指定为字符串表名
func (*Session) GetTableName ¶
GetTableName 获取解析后的名字, 提供给orm使用 为什么要在这里重复添加该方法, 而不是直接继承 IBinder 的方法呢? 是因为, 这里涉及到表前缀的问题, 只能通过session来传递, 所以IOrm就可以选择直接继承
func (*Session) GetTransaction ¶
GetTransaction 提供给 orm 使用的, 方便reset操作
func (*Session) LastInsertId ¶
func (*Session) SetTransaction ¶
Source Files
¶
- binder.go
- binder_interface.go
- builder.go
- builder_clickhouse.go
- builder_default.go
- builder_driver.go
- builder_interface.go
- builder_mssql.go
- builder_mysql.go
- builder_oracle.go
- builder_postgres.go
- builder_sqlite3.go
- config.go
- engin.go
- engin_interface.go
- err.go
- gorose.go
- logger.go
- logger_interface.go
- orm.go
- orm_api.go
- orm_api_interface.go
- orm_execute.go
- orm_execute_interface.go
- orm_interface.go
- orm_query.go
- orm_query_interface.go
- orm_session_interface.go
- session.go
- session_interface.go
- util.go