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 (o *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) ResetBinder()
- 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) GetBindValues() []interface{}
- func (b *BuilderDefault) GetOperator() []string
- func (b *BuilderDefault) GetPlaceholder() (phstr string)
- func (b *BuilderDefault) SetBindValues(bv interface{})
- 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) Clone() IBuilder
- func (b *BuilderOracle) GetOperator() []string
- func (b *BuilderOracle) GetPlaceholder() (phstr string)
- func (b *BuilderOracle) SetDriver(dr string) *BuilderOracle
- type BuilderPostgres
- func (*BuilderPostgres) AddFieldQuotes(field string) string
- func (b *BuilderPostgres) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error)
- func (b *BuilderPostgres) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error)
- func (b *BuilderPostgres) Clone() IBuilder
- 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) SetLogger(lg ILogger)
- 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 FieldQuotesDefault
- type IBinder
- type IBuilder
- type IEngin
- type IFieldQuotes
- 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) ChunkStruct(limit int, callback func() error) (err error)
- func (dba *Orm) ClearBindValues()
- func (dba *Orm) Close()
- 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 (o *Orm) GetExtraCols() []string
- func (o *Orm) GetFields() []string
- func (o *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) GetOrmApi() *OrmApi
- func (o *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) 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(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) OrWhereNotRegexp(arg string, expstr string) IOrm
- func (dba *Orm) OrWhereNull(arg string) IOrm
- func (dba *Orm) OrWhereRegexp(arg string, expstr 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(page ...int) (res Data, err error)
- func (dba *Orm) Pluck(field string, fieldKey ...string) (v interface{}, err error)
- func (dba *Orm) Pluck_bak(field string, fieldKey ...string) (v interface{}, err error)
- func (dba *Orm) Reset() IOrm
- func (dba *Orm) ResetExtraCols() IOrm
- func (dba *Orm) ResetTable() 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 (dba *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) Value_bak(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) WhereNotRegexp(arg string, expstr string) IOrm
- func (dba *Orm) WhereNull(arg string) IOrm
- func (dba *Orm) WhereRegexp(arg string, expstr 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 ... VERSION_TEXT = "\ngolang orm of gorose's version : " // VERSION_NO ... VERSION_NO = "v2.1.5" // VERSION ... VERSION = VERSION_TEXT + VERSION_NO + GOROSE_IMG )
const (
// DriverClickhouse ...
DriverClickhouse = "clickhouse"
)
const (
// DriverMsSql ...
DriverMsSql = "mssql"
)
const (
// DriverMysql ...
DriverMysql = "mysql"
)
const (
// DriverOracle ...
DriverOracle = "oci8"
)
const (
// DriverPostgres ...
DriverPostgres = "postgres"
)
const (
// DriverSqlite3 ...
DriverSqlite3 = "sqlite3"
)
const GOROSE_IMG = `` /* 497-byte string literal not displayed */
GOROSE_IMG ...
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", }
BindString ...
var IGNORE = "-"
IGNORE ...
var TAGNAME = "gorose"
TAGNAME ...
Functions ¶
Types ¶
type BindType ¶
type BindType int
BindType ...
const ( // OBJECT_STRUCT 结构体 一条数据 (struct) OBJECT_STRUCT BindType = iota // OBJECT_STRUCT_SLICE 结构体 多条数据 ([]struct) OBJECT_STRUCT_SLICE // OBJECT_MAP map 一条数据 (map[string]interface{}) OBJECT_MAP // OBJECT_MAP_SLICE map 多条数据 ([]map[string]interface{}) OBJECT_MAP_SLICE // OBJECT_STRING 非结构体 表名字符串 ("users") OBJECT_STRING // OBJECT_MAP_T map 一条数据 (map[string]t.Type) OBJECT_MAP_T // OBJECT_MAP_SLICE_T map 多条数据 ([]map[string]t.Type) OBJECT_MAP_SLICE_T // OBJECT_NIL 默认没有传入任何绑定对象,一般用于query直接返回 OBJECT_NIL )
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 }
Binder ...
func (*Binder) GetBindResultSlice ¶
GetBindResultSlice ...
func (*Binder) ResetBindResultSlice ¶
func (o *Binder) ResetBindResultSlice()
ResetBindResultSlice ...
func (*Binder) SetBindResultSlice ¶
SetBindResultSlice ...
type BuilderClickhouse ¶
type BuilderClickhouse struct { FieldQuotesDefault // contains filtered or unexported fields }
BuilderClickhouse ...
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 }
BuilderDefault 默认构造器, 其他的可以继承这个, 重写方法即可
func NewBuilderDefault ¶
func NewBuilderDefault(o IOrm, current IBuilder) *BuilderDefault
NewBuilderDefault 初始化
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)
BuildData2 ...
func (*BuilderDefault) BuildDistinct ¶
func (b *BuilderDefault) BuildDistinct() (dis string)
BuildDistinct ...
func (*BuilderDefault) BuildExecute ¶
func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []interface{}, err error)
BuilderDefault.BuildExecut : build execute query string
func (*BuilderDefault) BuildJoin ¶
func (b *BuilderDefault) BuildJoin() (s string, err error)
BuildJoin ...
func (*BuilderDefault) BuildQuery ¶
func (b *BuilderDefault) BuildQuery() (sqlStr string, args []interface{}, err error)
BuildQuery 构造query
func (*BuilderDefault) BuildWhere ¶
func (b *BuilderDefault) BuildWhere() (where string, err error)
BuildWhere ...
func (*BuilderDefault) GetBindValues ¶
func (b *BuilderDefault) GetBindValues() []interface{}
GetBindValues ...
func (*BuilderDefault) GetOperator ¶
func (b *BuilderDefault) GetOperator() []string
GetOperator ...
func (*BuilderDefault) GetPlaceholder ¶
func (b *BuilderDefault) GetPlaceholder() (phstr string)
GetPlaceholder 获取占位符
func (*BuilderDefault) SetBindValues ¶
func (b *BuilderDefault) SetBindValues(bv interface{})
SetBindValues ...
func (*BuilderDefault) SetDriver ¶
func (b *BuilderDefault) SetDriver(dr string) *BuilderDefault
SetDriver 设置驱动, 方便获取占位符使用
type BuilderDriver ¶
type BuilderDriver struct {
// contains filtered or unexported fields
}
BuilderDriver ...
func (*BuilderDriver) Register ¶
func (b *BuilderDriver) Register(driver string, val IBuilder)
Register ...
type BuilderMsSql ¶
type BuilderMsSql struct { FieldQuotesDefault // contains filtered or unexported fields }
BuilderMsSql ...
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 { FieldQuotesDefault // contains filtered or unexported fields }
BuilderMysql ...
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 { FieldQuotesDefault BuilderDefault }
BuilderOracle ...
func (*BuilderOracle) BuildData ¶
func (b *BuilderOracle) BuildData(operType string) (string, string, string)
BuildData ...
func (*BuilderOracle) BuildData2 ¶
func (b *BuilderOracle) BuildData2(operType string) (string, string, string)
BuildData2 ...
func (*BuilderOracle) BuildDistinct ¶
func (b *BuilderOracle) BuildDistinct() (dis string)
BuildDistinct ...
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)
BuildExecuteOra ...
func (*BuilderOracle) BuildJoin ¶
func (b *BuilderOracle) BuildJoin() (s string, err error)
BuildJoin ...
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)
BuildQueryOra ...
func (*BuilderOracle) BuildWhere ¶
func (b *BuilderOracle) BuildWhere() (where string, err error)
BuildWhere ...
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
}
BuilderPostgres ...
func (*BuilderPostgres) AddFieldQuotes ¶
func (*BuilderPostgres) AddFieldQuotes(field string) string
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 { FieldQuotesDefault // contains filtered or unexported fields }
BuilderSqlite3 ...
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 `json:"driver"` // 驱动: mysql/sqlite3/oracle/mssql/postgres/clickhouse, 如果集群配置了驱动, 这里可以省略 // mysql 示例: // root:root@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=true Dsn string `json:"dsn"` // 数据库链接 SetMaxOpenConns int `json:"setMaxOpenConns"` // (连接池)最大打开的连接数,默认值为0表示不限制 SetMaxIdleConns int `json:"setMaxIdleConns"` // (连接池)闲置的连接数, 默认0 Prefix string `json:"prefix"` // 表前缀, 如果集群配置了前缀, 这里可以省略 }
Config ...
type ConfigCluster ¶
type ConfigCluster struct { Master []Config // 主 Slave []Config // 从 Driver string // 驱动 Prefix string // 前缀 }
ConfigCluster ...
type Engin ¶
type Engin struct {
// contains filtered or unexported fields
}
Engin ...
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 FieldQuotesDefault ¶
type FieldQuotesDefault struct { }
func (FieldQuotesDefault) AddFieldQuotes ¶
func (FieldQuotesDefault) AddFieldQuotes(field string) string
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 ResetBinder() }
IBinder 数据绑定对象接口
type IBuilder ¶
type IBuilder interface { IFieldQuotes BuildQuery(orm IOrm) (sqlStr string, args []interface{}, err error) BuildExecute(orm IOrm, operType string) (sqlStr string, args []interface{}, err error) Clone() IBuilder }
IBuilder ...
type IEngin ¶
type IEngin interface { GetExecuteDB() *sql.DB GetQueryDB() *sql.DB //EnableSqlLog(e ...bool) //IfEnableSqlLog() (e bool) //SetPrefix(pre string) GetPrefix() (pre string) //NewSession() ISession //NewOrm() IOrm SetLogger(lg ILogger) GetLogger() ILogger GetDriver() string }
IEngin ...
type IFieldQuotes ¶
IFieldQuotes 给系统关键词冲突的字段加引号,如: mysql是反引号, pg是双引号
type ILogger ¶
type ILogger interface { Sql(sqlStr string, runtime time.Duration) Slow(sqlStr string, runtime time.Duration) Error(msg string) EnableSqlLog() bool EnableErrorLog() bool EnableSlowLog() float64 }
ILogger ...
type IOrm ¶
type IOrm interface { IOrmApi IOrmQuery IOrmExecute IOrmSession //ISession Close() 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 // join(=innerJoin),leftJoin,rightJoin,crossJoin Join(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 WhereRegexp(arg string, expstr string) IOrm OrWhereRegexp(arg string, expstr string) IOrm WhereNotRegexp(arg string, expstr string) IOrm OrWhereNotRegexp(arg string, expstr 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 ResetTable() IOrm ResetWhere() IOrm GetISession() ISession GetOrmApi() *OrmApi // sharedLock(lock in share mode) 不会阻塞其它事务读取被锁定行记录的值 SharedLock() *Orm // 此外你还可以使用 lockForUpdate 方法。“for update”锁避免选择行被其它共享锁修改或删除: // 会阻塞其他锁定性读对锁定行的读取(非锁定性读仍然可以读取这些记录,lock in share mode 和 for update 都是锁定性读) LockForUpdate() *Orm }
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 }
IOrmApi ...
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 }
IOrmExecute ...
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(page ...int) (res Data, err error) // 组块结果集 // 如果你需要处理成千上万或者更多条数据库记录,可以考虑使用 chunk 方法,该方法一次获取结果集的一小块, // 然后传递每一小块数据到闭包函数进行处理,该方法在编写处理大量数据库记录的 Artisan 命令的时候非常有用。 // 例如,我们可以将处理全部 users 表数据分割成一次处理 100 条记录的小组块 // 你可以通过从闭包函数中返回 err 来终止组块的运行 Chunk(limit int, callback func([]Data) error) (err error) // 跟Chunk类似,只不过callback的是传入的结构体 ChunkStruct(limit int, callback func() error) (err error) Loop(limit int, callback func([]Data) error) (err error) }
IOrmQuery ...
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{} }
IOrmSession ...
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 }
ISession ...
type LogOption ¶
type LogOption struct { FilePath string EnableSqlLog bool // 是否记录慢查询, 默认0s, 不记录, 设置记录的时间阀值, 比如 1, 则表示超过1s的都记录 EnableSlowLog float64 EnableErrorLog bool }
LogOption ...
type Orm ¶
type TransactionHandlerFunc func(db IOrm) error Orm ...
func NewOrmBuilder ¶
func NewOrmBuilder() *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) ChunkStruct ¶
ChunkStruct : 同Chunk,只不过不用返回map, 而是绑定数据到传入的对象上 这里一定要传入绑定struct
func (*Orm) Decrement ¶
Decrement : auto Decrement -1 default we can define step (such as 2, 3, 6 ...) if give the second params
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 ¶
OrWhereBetween ...
func (*Orm) OrWhereNotBetween ¶
OrWhereNotBetween ...
func (*Orm) OrWhereNotIn ¶
OrWhereNotIn ...
func (*Orm) OrWhereNotRegexp ¶
OrWhereNotRegexp ...
func (*Orm) OrWhereRegexp ¶
OrWhereRegexp ...
func (*Orm) Paginate ¶
Paginate 自动分页 @param limit 每页展示数量 @param current_page 当前第几页, 从1开始 以下是laravel的Paginate返回示例
{ "total": 50, "per_page": 15, "current_page": 1, "lastPage": 4, "first_page_url": "http://laravel.app?page=1", "lastPage_url": "http://laravel.app?page=4", "nextPage_url": "http://laravel.app?page=2", "prevPage_url": null, "path": "http://laravel.app", "from": 1, "to": 15, "data":[ { // Result Object }, { // Result Object } ] }
func (*Orm) SharedLock ¶
SharedLock 共享锁 select * from xxx lock in share mode
func (*Orm) Transaction ¶
Transaction ...
func (*Orm) WhereBetween ¶
WhereBetween ...
func (*Orm) WhereNotBetween ¶
WhereNotBetween ...
func (*Orm) WhereNotIn ¶
WhereNotIn ...
func (*Orm) WhereNotRegexp ¶
WhereNotRegexp ...
type Session ¶
Session ...
func (*Session) Bind ¶
Bind : 传入绑定结果的对象, 参数一为对象, 可以是 struct, gorose.MapRow 或对应的切片
如果是做非query操作,第一个参数也可以仅仅指定为字符串表名
func (*Session) GetTableName ¶
GetTableName 获取解析后的名字, 提供给orm使用 为什么要在这里重复添加该方法, 而不是直接继承 IBinder 的方法呢? 是因为, 这里涉及到表前缀的问题, 只能通过session来传递, 所以IOrm就可以选择直接继承
func (*Session) GetTransaction ¶
GetTransaction 提供给 orm 使用的, 方便reset操作
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