Versions in this module Expand all Collapse all v0 v0.1.1 Mar 2, 2021 Changes in this version + const DriverClickhouse + const DriverMsSql + const DriverMysql + const DriverOracle + const DriverPostgres + const DriverSqlite3 + var BindString = map[BindType]string + var Ignore = "-" + var TagName = "orm" + func DefaultLogger() func(e *Engine) + func GetErr(err Error, args ...interface{}) error + func If(condition bool, trueVal, falseVal interface{}) interface + func InArray(needle, hystack interface{}) bool + func Max(args ...interface{}) int + func Min(args ...interface{}) int + func SetDefaultRecover(dr func(err error)) + func StructToMap(obj interface{}) map[string]interface + func WithLockContext(ctx func()) + func WithRLockContext(ctx func()) + func WithRecover(h func(), errFunc ...func(err error)) + type Api struct + type BindType int + const ObjectMap + const ObjectMapSlice + const ObjectMapSliceT + const ObjectMapT + const ObjectNil + const ObjectString + const ObjectStruct + const ObjectStructSlice + func (b BindType) String() string + type Binder struct + BindAll []Data + BindFields []string + BindLimit int + BindName string + BindOrigin interface{} + BindPrefix string + BindResult interface{} + BindResultSlice reflect.Value + BindType BindType + func NewBinder(o ...interface{}) *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 Builder struct + func NewBuilderDefault(p IOrm, current IBuilder) *Builder + func (b *Builder) BuildData(operType string) (string, string, string) + func (b *Builder) BuildData2(operType string) (string, string, string) + func (b *Builder) BuildDistinct() (dis string) + func (b *Builder) BuildExecute(operType string) (sqlStr string, args []interface{}, err error) + func (b *Builder) BuildFields() string + func (b *Builder) BuildGroup() string + func (b *Builder) BuildHaving() string + func (b *Builder) BuildJoin() (s string, err error) + func (b *Builder) BuildLimit() string + func (b *Builder) BuildOffset() string + func (b *Builder) BuildOrder() string + func (b *Builder) BuildQuery() (sqlStr string, args []interface{}, err error) + func (b *Builder) BuildTable() string + func (b *Builder) BuildWhere() (where string, err error) + func (b *Builder) GetBindValues() []interface{} + func (b *Builder) GetOperator() []string + func (b *Builder) GetPlaceholder() (phstr string) + func (b *Builder) SetBindValues(bv interface{}) + func (b *Builder) SetDriver(dr string) *Builder + type BuilderClickhouse struct + func NewBuilderClickhouse() *BuilderClickhouse + func (b *BuilderClickhouse) BuildExecute(o IOrm, operationType string) (sqlStr string, args []interface{}, err error) + func (b *BuilderClickhouse) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error) + func (b *BuilderClickhouse) Clone() IBuilder + type BuilderMsSql struct + func NewBuilderMsSql() *BuilderMsSql + func (b *BuilderMsSql) BuildExecute(o IOrm, operationType string) (sqlStr string, args []interface{}, err error) + func (b *BuilderMsSql) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error) + func (b *BuilderMsSql) Clone() IBuilder + type BuilderMysql struct + func NewBuilderMysql() *BuilderMysql + func (b *BuilderMysql) BuildExecute(o IOrm, operationType string) (sqlStr string, args []interface{}, err error) + func (b *BuilderMysql) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error) + func (b *BuilderMysql) Clone() IBuilder + type BuilderOracle struct + func NewBuilderOracle(o IOrm) *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 struct + func NewBuilderPostgres() *BuilderPostgres + func (*BuilderPostgres) AddFieldQuotes(field string) string + func (b *BuilderPostgres) BuildExecute(o IOrm, operationType 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 struct + func NewBuilderSqlite3() *BuilderSqlite3 + func (b *BuilderSqlite3) BuildExecute(o IOrm, operType string) (sqlStr string, args []interface{}, err error) + func (b *BuilderSqlite3) BuildQuery(o IOrm) (sqlStr string, args []interface{}, err error) + func (b *BuilderSqlite3) Clone() IBuilder + type Config struct + Driver string + Dsn string + Prefix string + SetMaxIdleConns int + SetMaxOpenConns int + type ConfigCluster struct + Driver string + Master []Config + Prefix string + Slave []Config + type Data map[string]interface + type Driver struct + func NewDriver() *Driver + func (b *Driver) Get(driver string) IBuilder + func (b *Driver) Register(driver string, val IBuilder) + type Engine struct + func NewEngine(conf ...interface{}) (e *Engine, err error) + func Open(conf ...interface{}) (engine *Engine, err error) + func (c *Engine) GetDriver() string + func (c *Engine) GetExecuteDB() *sql.DB + func (c *Engine) GetLogger() ILogger + func (c *Engine) GetPrefix() string + func (c *Engine) GetQueryDB() *sql.DB + func (c *Engine) IgnoreName(arg string) + func (c *Engine) Orm() IOrm + func (c *Engine) Ping() error + func (c *Engine) Session() ISession + func (c *Engine) SetLogger(lg ILogger) + func (c *Engine) SetPrefix(pre string) + func (c *Engine) TagName(arg string) + func (c *Engine) Use(closers ...func(e *Engine)) + type Err struct + func NewErr() *Err + func (e *Err) Default() map[Error]string + func (e *Err) Get(err Error) string + func (e *Err) GetLang() Lang + func (e *Err) Register(err map[Error]string) + func (e *Err) SetLang(l Lang) + type Error uint + const ErrParamsCounts + const ErrParamsFormat + const ErrParamsMissing + type FieldQuotesDefault struct + func (FieldQuotesDefault) AddFieldQuotes(field string) string + type IApi interface + ExtraCols func(args ...string) IOrm + GetData func() interface{} + GetDistinct func() bool + GetExtraCols func() []string + GetFields func() []string + GetGroup func() string + GetHaving func() string + GetJoin func() [][]interface{} + GetLimit func() int + GetOffset func() int + GetOrder func() string + GetPessimisticLock func() string + GetTable func() string + GetWhere func() [][]interface{} + ResetExtraCols func() IOrm + SetWhere func(arg [][]interface{}) + type IBinder interface + BindParse func(prefix string) error + GetBindAll func() []Data + GetBindFields func() []string + GetBindName func() string + GetBindOrigin func() interface{} + GetBindPrefix func() string + GetBindResult func() interface{} + GetBindResultSlice func() reflect.Value + GetBindType func() BindType + ResetBindResultSlice func() + ResetBinder func() + SetBindAll func(arg []Data) + SetBindFields func(arg []string) + SetBindName func(arg string) + SetBindOrigin func(arg interface{}) + SetBindPrefix func(arg string) + SetBindResult func(arg interface{}) + SetBindResultSlice func(arg reflect.Value) + SetBindType func(arg BindType) + type IBuilder interface + BuildExecute func(orm IOrm, operType string) (sqlStr string, args []interface{}, err error) + BuildQuery func(orm IOrm) (sqlStr string, args []interface{}, err error) + Clone func() IBuilder + func NewBuilder(driver string) IBuilder + type IEngine interface + GetDriver func() string + GetExecuteDB func() *sql.DB + GetLogger func() ILogger + GetPrefix func() (pre string) + GetQueryDB func() *sql.DB + SetLogger func(lg ILogger) + type IExecute interface + Decrement func(args ...interface{}) (int64, error) + Delete func() (int64, error) + Force func() IOrm + GetForce func() bool + Increment func(args ...interface{}) (int64, error) + Insert func(data ...interface{}) (int64, error) + InsertGetId func(data ...interface{}) (int64, error) + Update func(data ...interface{}) (int64, error) + type IFieldQuotes interface + AddFieldQuotes func(field string) string + type ILogger interface + EnableErrorLog func() bool + EnableSlowLog func() float64 + EnableSqlLog func() bool + Error func(msg string) + Slow func(sqlStr string, runtime time.Duration) + Sql func(sqlStr string, runtime time.Duration) + type IOrm interface + AddField func(fields ...string) IOrm + And func(args ...interface{}) IOrm + Between func(needle string, hystack []interface{}) IOrm + ClearBindValues func() + Close func() + CrossJoin func(args ...interface{}) IOrm + Data func(data interface{}) IOrm + Distinct func() IOrm + Field func(fields ...string) IOrm + GetBindValues func() []interface{} + GetDriver func() string + GetISession func() ISession + GetOrmApi func() *Api + Group func(group string) IOrm + Having func(having string) IOrm + In func(needle string, hystack []interface{}) IOrm + Join func(args ...interface{}) IOrm + LeftJoin func(args ...interface{}) IOrm + Limit func(limit int) IOrm + LockForUpdate func() *Orm + NotBetween func(needle string, hystack []interface{}) IOrm + NotIn func(needle string, hystack []interface{}) IOrm + NotNull func(arg string) IOrm + NotRegexp func(arg string, expstr string) IOrm + Null func(arg string) IOrm + Offset func(offset int) IOrm + Or func(args ...interface{}) IOrm + OrBetween func(needle string, hystack []interface{}) IOrm + OrIn func(needle string, hystack []interface{}) IOrm + OrNotBetween func(needle string, hystack []interface{}) IOrm + OrNotIn func(needle string, hystack []interface{}) IOrm + OrNotNull func(arg string) IOrm + OrNotRegexp func(arg string, expstr string) IOrm + OrNull func(arg string) IOrm + OrRegexp func(arg string, expstr string) IOrm + Order func(order string) IOrm + Page func(page int) IOrm + Regexp func(arg string, expstr string) IOrm + Reset func() IOrm + ResetTable func() IOrm + ResetWhere func() IOrm + RightJoin func(args ...interface{}) IOrm + SetBindValues func(v interface{}) + SharedLock func() *Orm + Sql func(operationType ...string) (string, []interface{}, error) + TX func(closers ...func(db IOrm) error) (err error) + Table func(tab interface{}) IOrm + Where func(args ...interface{}) IOrm + func DB() IOrm + type IOrmSession interface + Begin func() (err error) + Commit func() (err error) + Exec func(sqlStr string, args ...interface{}) (int64, error) + GetIBinder func() IBinder + GetUnion func() interface{} + LastInsertId func() int64 + LastSql func() string + Query func(sqlStr string, args ...interface{}) ([]Data, error) + Rollback func() (err error) + SetUnion func(u interface{}) + type IQuery interface + Avg func(avg string) (interface{}, error) + Chunk func(limit int, callback func([]Data) error, pointer ...interface{}) (err error) + ChunkStruct func(limit int, callback func() error, pointer ...interface{}) (err error) + Count func(args ...string) (int64, error) + Find func(pointer ...interface{}) ([]Data, error) + First func(pointer ...interface{}) (Data, error) + Loop func(limit int, callback func([]Data) error) (err error) + Max func(max string) (interface{}, error) + Min func(min string) (interface{}, error) + Paginate func(page ...int) (res Data, err error) + Pluck func(pointer interface{}, field string, fieldKey ...string) (v interface{}, err error) + Scan func(pointer ...interface{}) error + Sum func(sum string) (interface{}, error) + Value func(field string) (v interface{}, err error) + type ISession interface + Begin func() (err error) + Bind func(bind interface{}) ISession + Close func() + Commit func() (err error) + Exec func(sqlStr string, args ...interface{}) (int64, error) + GetBindAll func() []Data + GetErr func() error + GetIBinder func() IBinder + GetIEngine func() IEngine + GetTableName func() (string, error) + GetTransaction func() bool + GetUnion func() interface{} + LastInsertId func() int64 + LastSql func() string + Query func(sqlStr string, args ...interface{}) ([]Data, error) + Rollback func() (err error) + SetIBinder func(ib IBinder) + SetTransaction func(b bool) + SetUnion func(u interface{}) + TX func(closer ...func(session ISession) error) (err error) + type Lang uint + const Chinese + const ChineseTraditional + const English + func (l Lang) String() string + type LogLevel uint + const LogError + const LogSQL + const LogSlow + func (l LogLevel) String() string + type LogOption struct + EnableErrorLog bool + EnableSlowLog float64 + EnableSqlLog bool + FilePath string + type Logger struct + func NewLogger(o *LogOption) *Logger + func (l *Logger) EnableErrorLog() bool + func (l *Logger) EnableSlowLog() float64 + func (l *Logger) EnableSqlLog() bool + func (l *Logger) Error(msg string) + func (l *Logger) Slow(sqlStr string, runtime time.Duration) + func (l *Logger) Sql(sqlStr string, runtime time.Duration) + type Map t.MapStringT + type Orm struct + func NewOrm(e IEngine) *Orm + func (p *Orm) AddField(fields ...string) IOrm + func (p *Orm) And(args ...interface{}) IOrm + func (p *Orm) Avg(avg string) (interface{}, error) + func (p *Orm) Between(needle string, hyStack []interface{}) IOrm + func (p *Orm) Chunk(limit int, callback func([]Data) error, pointer ...interface{}) (err error) + func (p *Orm) ChunkStruct(limit int, callback func() error, pointer ...interface{}) (err error) + func (p *Orm) ClearBindValues() + func (p *Orm) Close() + func (p *Orm) Count(args ...string) (int64, error) + func (p *Orm) CrossJoin(args ...interface{}) IOrm + func (p *Orm) Data(data interface{}) IOrm + func (p *Orm) Decrement(args ...interface{}) (int64, error) + func (p *Orm) Delete() (int64, error) + func (p *Orm) Distinct() IOrm + func (p *Orm) ExtraCols(args ...string) IOrm + func (p *Orm) Field(fields ...string) IOrm + func (p *Orm) Find(pointer ...interface{}) (result []Data, err error) + func (p *Orm) First(pointer ...interface{}) (result Data, err error) + func (p *Orm) Force() IOrm + func (p *Orm) GetBindValues() []interface{} + func (p *Orm) GetData() interface{} + func (p *Orm) GetDistinct() bool + func (p *Orm) GetDriver() string + func (p *Orm) GetExtraCols() []string + func (p *Orm) GetFields() []string + func (p *Orm) GetForce() bool + func (p *Orm) GetGroup() string + func (p *Orm) GetHaving() string + func (p *Orm) GetISession() ISession + func (p *Orm) GetJoin() [][]interface{} + func (p *Orm) GetLimit() int + func (p *Orm) GetOffset() int + func (p *Orm) GetOrder() string + func (p *Orm) GetOrmApi() *Api + func (p *Orm) GetPessimisticLock() string + func (p *Orm) GetTable() string + func (p *Orm) GetWhere() [][]interface{} + func (p *Orm) Group(group string) IOrm + func (p *Orm) Having(having string) IOrm + func (p *Orm) In(needle string, hyStack []interface{}) IOrm + func (p *Orm) Increment(args ...interface{}) (int64, error) + func (p *Orm) Insert(data ...interface{}) (int64, error) + func (p *Orm) InsertGetId(data ...interface{}) (int64, error) + func (p *Orm) Join(args ...interface{}) IOrm + func (p *Orm) LeftJoin(args ...interface{}) IOrm + func (p *Orm) Limit(limit int) IOrm + func (p *Orm) LockForUpdate() *Orm + func (p *Orm) Loop(limit int, callback func([]Data) error) (err error) + func (p *Orm) Max(max string) (interface{}, error) + func (p *Orm) Min(min string) (interface{}, error) + func (p *Orm) NotBetween(needle string, hyStack []interface{}) IOrm + func (p *Orm) NotIn(needle string, hyStack []interface{}) IOrm + func (p *Orm) NotNull(arg string) IOrm + func (p *Orm) NotRegexp(arg string, expStr string) IOrm + func (p *Orm) Null(arg string) IOrm + func (p *Orm) Offset(offset int) IOrm + func (p *Orm) Or(args ...interface{}) IOrm + func (p *Orm) OrBetween(needle string, hyStack []interface{}) IOrm + func (p *Orm) OrIn(needle string, hyStack []interface{}) IOrm + func (p *Orm) OrNotBetween(needle string, hyStack []interface{}) IOrm + func (p *Orm) OrNotIn(needle string, hyStack []interface{}) IOrm + func (p *Orm) OrNotNull(arg string) IOrm + func (p *Orm) OrNotRegexp(arg string, expStr string) IOrm + func (p *Orm) OrNull(arg string) IOrm + func (p *Orm) OrRegexp(arg string, expStr string) IOrm + func (p *Orm) Order(order string) IOrm + func (p *Orm) Page(page int) IOrm + func (p *Orm) Paginate(page ...int) (res Data, err error) + func (p *Orm) Pluck(pointer interface{}, field string, fieldKey ...string) (v interface{}, err error) + func (p *Orm) PluckBak(pointer interface{}, field string, fieldKey ...string) (v interface{}, err error) + func (p *Orm) Regexp(arg string, expStr string) IOrm + func (p *Orm) Reset() IOrm + func (p *Orm) ResetExtraCols() IOrm + func (p *Orm) ResetTable() IOrm + func (p *Orm) ResetUnion() IOrm + func (p *Orm) ResetWhere() IOrm + func (p *Orm) RightJoin(args ...interface{}) IOrm + func (p *Orm) Scan(pointer ...interface{}) error + func (p *Orm) SetBindValues(v interface{}) + func (p *Orm) SetISession(is ISession) + func (p *Orm) SetWhere(arg [][]interface{}) + func (p *Orm) SharedLock() *Orm + func (p *Orm) Sql(operationType ...string) (a string, b []interface{}, err error) + func (p *Orm) Sum(sum string) (interface{}, error) + func (p *Orm) TX(closers ...func(db IOrm) error) (err error) + func (p *Orm) Table(tableName interface{}) IOrm + func (p *Orm) Update(data ...interface{}) (int64, error) + func (p *Orm) Value(field string) (v interface{}, err error) + func (p *Orm) ValueBak(field string, pointer ...interface{}) (v interface{}, err error) + func (p *Orm) Where(args ...interface{}) IOrm + type Session struct + func NewSession(e IEngine) *Session + func (s *Session) Begin() (err error) + func (s *Session) Bind(pointer interface{}) ISession + func (s *Session) Close() + func (s *Session) Commit() (err error) + func (s *Session) Exec(sqlStr string, args ...interface{}) (rowsAffected int64, err error) + func (s *Session) GetErr() error + func (s *Session) GetIBinder() IBinder + func (s *Session) GetIEngine() IEngine + 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(sqlStr 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) SetIEngine(ie IEngine) + func (s *Session) SetTransaction(b bool) + func (s *Session) SetUnion(u interface{}) + func (s *Session) TX(closers ...func(ses ISession) error) (err error) + type StructEngine struct + ExtraCols []string + Fields []interface{} + Result []map[string]interface{} + TagIgnoreName string + TagName string + func (s *StructEngine) AppendFields(arg interface{}) + func (s *StructEngine) AppendResult(arg map[string]interface{}) + func (s *StructEngine) GetFields() []interface{} + func (s *StructEngine) GetResult() []map[string]interface{} + func (s *StructEngine) GetStructFields(data interface{}) []interface{} + func (s *StructEngine) GetTagIgnoreName() string + func (s *StructEngine) GetTagName() string + func (s *StructEngine) SetExtraCols(args []string) *StructEngine + func (s *StructEngine) SetFields(arg []interface{}) + func (s *StructEngine) SetResult(arg []map[string]interface{}) + func (s *StructEngine) SetTagIgnoreName(arg string) *StructEngine + func (s *StructEngine) SetTagName(arg string) *StructEngine + func (s *StructEngine) StructContent2Map(data interface{}) []map[string]interface{}