Versions in this module Expand all Collapse all v1 v1.51.5 Mar 7, 2021 v1.51.4 Jan 13, 2021 v1.51.3 Jan 13, 2021 Changes in this version + const DefaultGroupName + const OPTION_ALLOWEMPTY + const OPTION_OMITEMPTY + const OrmTagForPrimary + const OrmTagForStruct + const OrmTagForUnique + var ErrNoRows = sql.ErrNoRows + func AddConfigNode(group string, node ConfigNode) + func AddDefaultConfigGroup(nodes ConfigGroup) + func AddDefaultConfigNode(node ConfigNode) + func ConvertDataForTableRecord(value interface{}) map[string]interface + func DataToMapDeep(value interface{}) map[string]interface + func FormatSqlWithArgs(sql string, args []interface{}) string + func GetDefaultGroup() string + func GetInsertOperationByOption(option int) string + func GetPrimaryKey(pointer interface{}) (string, error) + func GetPrimaryKeyCondition(primary string, where ...interface{}) (newWhereCondition []interface{}) + func GetWhereConditionOfStruct(pointer interface{}) (where string, args []interface{}, err error) + func IsConfigured() bool + func ListItemValues(list interface{}, key interface{}, subKey ...interface{}) (values []interface{}) + func ListItemValuesUnique(list interface{}, key string, subKey ...interface{}) []interface + func Register(name string, driver Driver) error + func SetConfig(config Config) + func SetConfigGroup(group string, nodes ConfigGroup) + func SetDefaultGroup(name string) + type Config map[string]ConfigGroup + type ConfigGroup []ConfigNode + func GetConfig(group string) ConfigGroup + type ConfigNode struct + Charset string + CreatedAt string + Debug bool + DeletedAt string + DryRun bool + ExecTimeout time.Duration + Host string + LinkInfo string + MaxConnLifetime time.Duration + MaxIdleConnCount int + MaxOpenConnCount int + Name string + Pass string + Port string + Prefix string + PrepareTimeout time.Duration + QueryTimeout time.Duration + Role string + TimeMaintainDisabled bool + TranTimeout time.Duration + Type string + UpdatedAt string + User string + Weight int + func (node *ConfigNode) String() string + type Core struct + DB DB + func (c *Core) BatchInsert(table string, list interface{}, batch ...int) (sql.Result, error) + func (c *Core) BatchInsertIgnore(table string, list interface{}, batch ...int) (sql.Result, error) + func (c *Core) BatchReplace(table string, list interface{}, batch ...int) (sql.Result, error) + func (c *Core) BatchSave(table string, list interface{}, batch ...int) (sql.Result, error) + func (c *Core) Begin() (*TX, error) + func (c *Core) Ctx(ctx context.Context) DB + func (c *Core) Delete(table string, condition interface{}, args ...interface{}) (result sql.Result, err error) + func (c *Core) DoBatchInsert(link Link, table string, list interface{}, option int, batch ...int) (result sql.Result, err error) + func (c *Core) DoDelete(link Link, table string, condition string, args ...interface{}) (result sql.Result, err error) + func (c *Core) DoExec(link Link, sql string, args ...interface{}) (result sql.Result, err error) + func (c *Core) DoGetAll(link Link, sql string, args ...interface{}) (result Result, err error) + func (c *Core) DoInsert(link Link, table string, data interface{}, option int, batch ...int) (result sql.Result, err error) + func (c *Core) DoPrepare(link Link, sql string) (*sql.Stmt, error) + func (c *Core) DoQuery(link Link, sql string, args ...interface{}) (rows *sql.Rows, err error) + func (c *Core) DoUpdate(link Link, table string, data interface{}, condition string, ...) (result sql.Result, err error) + func (c *Core) Exec(sql string, args ...interface{}) (result sql.Result, err error) + func (c *Core) GetAll(sql string, args ...interface{}) (Result, error) + func (c *Core) GetArray(sql string, args ...interface{}) ([]Value, error) + func (c *Core) GetCache() *gcache.Cache + func (c *Core) GetChars() (charLeft string, charRight string) + func (c *Core) GetConfig() *ConfigNode + func (c *Core) GetCount(sql string, args ...interface{}) (int, error) + func (c *Core) GetCtx() context.Context + func (c *Core) GetDebug() bool + func (c *Core) GetDryRun() bool + func (c *Core) GetGroup() string + func (c *Core) GetLogger() *glog.Logger + func (c *Core) GetMaster(schema ...string) (*sql.DB, error) + func (c *Core) GetOne(sql string, args ...interface{}) (Record, error) + func (c *Core) GetPrefix() string + func (c *Core) GetScan(pointer interface{}, sql string, args ...interface{}) error + func (c *Core) GetSchema() string + func (c *Core) GetSlave(schema ...string) (*sql.DB, error) + func (c *Core) GetStruct(pointer interface{}, sql string, args ...interface{}) error + func (c *Core) GetStructs(pointer interface{}, sql string, args ...interface{}) error + func (c *Core) GetValue(sql string, args ...interface{}) (Value, error) + func (c *Core) HandleSqlBeforeCommit(sql string) string + func (c *Core) HasTable(name string) (bool, error) + func (c *Core) Insert(table string, data interface{}, batch ...int) (sql.Result, error) + func (c *Core) InsertIgnore(table string, data interface{}, batch ...int) (sql.Result, error) + func (c *Core) MarshalJSON() ([]byte, error) + func (c *Core) Master() (*sql.DB, error) + func (c *Core) Model(table ...string) *Model + func (c *Core) PingMaster() error + func (c *Core) PingSlave() error + func (c *Core) Prepare(sql string, execOnMaster ...bool) (*sql.Stmt, error) + func (c *Core) Query(sql string, args ...interface{}) (rows *sql.Rows, err error) + func (c *Core) QuotePrefixTableName(table string) string + func (c *Core) QuoteString(s string) string + func (c *Core) QuoteWord(s string) string + func (c *Core) Replace(table string, data interface{}, batch ...int) (sql.Result, error) + func (c *Core) Save(table string, data interface{}, batch ...int) (sql.Result, error) + func (c *Core) Schema(schema string) *Schema + func (c *Core) SetDebug(debug bool) + func (c *Core) SetDryRun(enabled bool) + func (c *Core) SetLogger(logger *glog.Logger) + func (c *Core) SetMaxConnLifetime(d time.Duration) + func (c *Core) SetMaxIdleConnCount(n int) + func (c *Core) SetMaxOpenConnCount(n int) + func (c *Core) SetSchema(schema string) + func (c *Core) Slave() (*sql.DB, error) + func (c *Core) Table(table ...string) *Model + func (c *Core) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (c *Core) Tables(schema ...string) (tables []string, err error) + func (c *Core) Transaction(f func(tx *TX) error) (err error) + func (c *Core) Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) + type Counter struct + Field string + Value float64 + type DB interface + BatchInsert func(table string, list interface{}, batch ...int) (sql.Result, error) + BatchReplace func(table string, list interface{}, batch ...int) (sql.Result, error) + BatchSave func(table string, list interface{}, batch ...int) (sql.Result, error) + Begin func() (*TX, error) + Ctx func(ctx context.Context) DB + Delete func(table string, condition interface{}, args ...interface{}) (sql.Result, error) + DoBatchInsert func(link Link, table string, list interface{}, option int, batch ...int) (result sql.Result, err error) + DoDelete func(link Link, table string, condition string, args ...interface{}) (result sql.Result, err error) + DoExec func(link Link, sql string, args ...interface{}) (result sql.Result, err error) + DoGetAll func(link Link, sql string, args ...interface{}) (result Result, err error) + DoInsert func(link Link, table string, data interface{}, option int, batch ...int) (result sql.Result, err error) + DoPrepare func(link Link, sql string) (*sql.Stmt, error) + DoQuery func(link Link, sql string, args ...interface{}) (rows *sql.Rows, err error) + DoUpdate func(link Link, table string, data interface{}, condition string, ...) (result sql.Result, err error) + Exec func(sql string, args ...interface{}) (sql.Result, error) + GetAll func(sql string, args ...interface{}) (Result, error) + GetArray func(sql string, args ...interface{}) ([]Value, error) + GetCache func() *gcache.Cache + GetChars func() (charLeft string, charRight string) + GetConfig func() *ConfigNode + GetCount func(sql string, args ...interface{}) (int, error) + GetCtx func() context.Context + GetDebug func() bool + GetDryRun func() bool + GetGroup func() string + GetLogger func() *glog.Logger + GetMaster func(schema ...string) (*sql.DB, error) + GetOne func(sql string, args ...interface{}) (Record, error) + GetPrefix func() string + GetScan func(objPointer interface{}, sql string, args ...interface{}) error + GetSchema func() string + GetSlave func(schema ...string) (*sql.DB, error) + GetStruct func(objPointer interface{}, sql string, args ...interface{}) error + GetStructs func(objPointerSlice interface{}, sql string, args ...interface{}) error + GetValue func(sql string, args ...interface{}) (Value, error) + HandleSqlBeforeCommit func(link Link, sql string, args []interface{}) (string, []interface{}) + HasTable func(name string) (bool, error) + Insert func(table string, data interface{}, batch ...int) (sql.Result, error) + InsertIgnore func(table string, data interface{}, batch ...int) (sql.Result, error) + Master func() (*sql.DB, error) + Model func(table ...string) *Model + Open func(config *ConfigNode) (*sql.DB, error) + PingMaster func() error + PingSlave func() error + Prepare func(sql string, execOnMaster ...bool) (*sql.Stmt, error) + Query func(sql string, args ...interface{}) (*sql.Rows, error) + QuotePrefixTableName func(table string) string + QuoteString func(s string) string + QuoteWord func(s string) string + Replace func(table string, data interface{}, batch ...int) (sql.Result, error) + Save func(table string, data interface{}, batch ...int) (sql.Result, error) + Schema func(schema string) *Schema + SetDebug func(debug bool) + SetDryRun func(dryrun bool) + SetLogger func(logger *glog.Logger) + SetMaxConnLifetime func(d time.Duration) + SetMaxIdleConnCount func(n int) + SetMaxOpenConnCount func(n int) + SetSchema func(schema string) + Slave func() (*sql.DB, error) + Table func(table ...string) *Model + TableFields func(table string, schema ...string) (map[string]*TableField, error) + Tables func(schema ...string) (tables []string, err error) + Transaction func(f func(tx *TX) error) (err error) + Update func(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) + func Instance(name ...string) (db DB, err error) + func New(group ...string) (db DB, err error) + type Driver interface + New func(core *Core, node *ConfigNode) (DB, error) + type DriverMssql struct + func (d *DriverMssql) GetChars() (charLeft string, charRight string) + func (d *DriverMssql) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (string, []interface{}) + func (d *DriverMssql) New(core *Core, node *ConfigNode) (DB, error) + func (d *DriverMssql) Open(config *ConfigNode) (*sql.DB, error) + func (d *DriverMssql) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (d *DriverMssql) Tables(schema ...string) (tables []string, err error) + type DriverMysql struct + func (d *DriverMysql) GetChars() (charLeft string, charRight string) + func (d *DriverMysql) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (string, []interface{}) + func (d *DriverMysql) New(core *Core, node *ConfigNode) (DB, error) + func (d *DriverMysql) Open(config *ConfigNode) (*sql.DB, error) + func (d *DriverMysql) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (d *DriverMysql) Tables(schema ...string) (tables []string, err error) + type DriverOracle struct + func (d *DriverOracle) DoBatchInsert(link Link, table string, list interface{}, option int, batch ...int) (result sql.Result, err error) + func (d *DriverOracle) DoInsert(link Link, table string, data interface{}, option int, batch ...int) (result sql.Result, err error) + func (d *DriverOracle) GetChars() (charLeft string, charRight string) + func (d *DriverOracle) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (newSql string, newArgs []interface{}) + func (d *DriverOracle) New(core *Core, node *ConfigNode) (DB, error) + func (d *DriverOracle) Open(config *ConfigNode) (*sql.DB, error) + func (d *DriverOracle) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (d *DriverOracle) Tables(schema ...string) (tables []string, err error) + type DriverPgsql struct + func (d *DriverPgsql) GetChars() (charLeft string, charRight string) + func (d *DriverPgsql) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (string, []interface{}) + func (d *DriverPgsql) New(core *Core, node *ConfigNode) (DB, error) + func (d *DriverPgsql) Open(config *ConfigNode) (*sql.DB, error) + func (d *DriverPgsql) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (d *DriverPgsql) Tables(schema ...string) (tables []string, err error) + type DriverSqlite struct + func (d *DriverSqlite) GetChars() (charLeft string, charRight string) + func (d *DriverSqlite) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (string, []interface{}) + func (d *DriverSqlite) New(core *Core, node *ConfigNode) (DB, error) + func (d *DriverSqlite) Open(config *ConfigNode) (*sql.DB, error) + func (d *DriverSqlite) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) + func (d *DriverSqlite) Tables(schema ...string) (tables []string, err error) + type Link interface + Exec func(sql string, args ...interface{}) (sql.Result, error) + ExecContext func(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + Prepare func(sql string) (*sql.Stmt, error) + PrepareContext func(ctx context.Context, query string) (*sql.Stmt, error) + Query func(sql string, args ...interface{}) (*sql.Rows, error) + QueryContext func(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + type List = []Map + type Map = map[string]interface + type Model struct + func (m *Model) All(where ...interface{}) (Result, error) + func (m *Model) And(where interface{}, args ...interface{}) *Model + func (m *Model) Args(args ...interface{}) *Model + func (m *Model) Array(fieldsAndWhere ...interface{}) ([]Value, error) + func (m *Model) As(as string) *Model + func (m *Model) Batch(batch int) *Model + func (m *Model) Cache(duration time.Duration, name ...string) *Model + func (m *Model) Chunk(limit int, callback func(result Result, err error) bool) + func (m *Model) Clone() *Model + func (m *Model) Count(where ...interface{}) (int, error) + func (m *Model) Ctx(ctx context.Context) *Model + func (m *Model) DB(db DB) *Model + func (m *Model) Data(data ...interface{}) *Model + func (m *Model) Delete(where ...interface{}) (result sql.Result, err error) + func (m *Model) Fields(fieldNamesOrMapStruct ...interface{}) *Model + func (m *Model) FieldsEx(fieldNamesOrMapStruct ...interface{}) *Model + func (m *Model) FieldsExStr(fields string, prefix ...string) string + func (m *Model) FieldsStr(prefix ...string) string + func (m *Model) Filter() *Model + func (m *Model) FindAll(where ...interface{}) (Result, error) + func (m *Model) FindArray(fieldsAndWhere ...interface{}) ([]Value, error) + func (m *Model) FindCount(where ...interface{}) (int, error) + func (m *Model) FindOne(where ...interface{}) (Record, error) + func (m *Model) FindScan(pointer interface{}, where ...interface{}) error + func (m *Model) FindValue(fieldsAndWhere ...interface{}) (Value, error) + func (m *Model) ForPage(page, limit int) *Model + func (m *Model) GetFieldsExStr(fields string, prefix ...string) string + func (m *Model) GetFieldsStr(prefix ...string) string + func (m *Model) Group(groupBy string) *Model + func (m *Model) GroupBy(groupBy string) *Model + func (m *Model) HasField(field string) (bool, error) + func (m *Model) Having(having interface{}, args ...interface{}) *Model + func (m *Model) InnerJoin(table ...string) *Model + func (m *Model) Insert(data ...interface{}) (result sql.Result, err error) + func (m *Model) InsertIgnore(data ...interface{}) (result sql.Result, err error) + func (m *Model) LeftJoin(table ...string) *Model + func (m *Model) Limit(limit ...int) *Model + func (m *Model) LockShared() *Model + func (m *Model) LockUpdate() *Model + func (m *Model) Master() *Model + func (m *Model) Offset(offset int) *Model + func (m *Model) OmitEmpty() *Model + func (m *Model) One(where ...interface{}) (Record, error) + func (m *Model) Option(option int) *Model + func (m *Model) OptionOmitEmpty() *Model + func (m *Model) Or(where interface{}, args ...interface{}) *Model + func (m *Model) Order(orderBy ...string) *Model + func (m *Model) OrderBy(orderBy string) *Model + func (m *Model) Page(page, limit int) *Model + func (m *Model) Replace(data ...interface{}) (result sql.Result, err error) + func (m *Model) RightJoin(table ...string) *Model + func (m *Model) Safe(safe ...bool) *Model + func (m *Model) Save(data ...interface{}) (result sql.Result, err error) + func (m *Model) Scan(pointer interface{}, where ...interface{}) error + func (m *Model) ScanList(listPointer interface{}, attributeName string, relation ...string) (err error) + func (m *Model) Schema(schema string) *Model + func (m *Model) Select(where ...interface{}) (Result, error) + func (m *Model) Slave() *Model + func (m *Model) Struct(pointer interface{}, where ...interface{}) error + func (m *Model) Structs(pointer interface{}, where ...interface{}) error + func (m *Model) TX(tx *TX) *Model + func (m *Model) Unscoped() *Model + func (m *Model) Update(dataAndWhere ...interface{}) (result sql.Result, err error) + func (m *Model) Value(fieldsAndWhere ...interface{}) (Value, error) + func (m *Model) Where(where interface{}, args ...interface{}) *Model + func (m *Model) WherePri(where interface{}, args ...interface{}) *Model + type Raw string + type Record map[string]Value + func (r Record) GMap() *gmap.StrAnyMap + func (r Record) IsEmpty() bool + func (r Record) Json() string + func (r Record) Map() Map + func (r Record) Struct(pointer interface{}) error + func (r Record) ToJson() string + func (r Record) ToMap() Map + func (r Record) ToStruct(pointer interface{}) error + func (r Record) ToXml(rootTag ...string) string + func (r Record) Xml(rootTag ...string) string + type Result []Record + func (r Result) Array(field ...string) []Value + func (r Result) Chunk(size int) []Result + func (r Result) IsEmpty() bool + func (r Result) Json() string + func (r Result) Len() int + func (r Result) List() List + func (r Result) MapKeyInt(key string) map[int]Map + func (r Result) MapKeyStr(key string) map[string]Map + func (r Result) MapKeyUint(key string) map[uint]Map + func (r Result) MapKeyValue(key string) map[string]Value + func (r Result) RecordKeyInt(key string) map[int]Record + func (r Result) RecordKeyStr(key string) map[string]Record + func (r Result) RecordKeyUint(key string) map[uint]Record + func (r Result) ScanList(listPointer interface{}, attributeName string, relation ...string) (err error) + func (r Result) Size() int + func (r Result) Structs(pointer interface{}) (err error) + func (r Result) ToIntMap(key string) map[int]Map + func (r Result) ToIntRecord(key string) map[int]Record + func (r Result) ToJson() string + func (r Result) ToList() List + func (r Result) ToStringMap(key string) map[string]Map + func (r Result) ToStringRecord(key string) map[string]Record + func (r Result) ToStructs(pointer interface{}) (err error) + func (r Result) ToUintMap(key string) map[uint]Map + func (r Result) ToUintRecord(key string) map[uint]Record + func (r Result) ToXml(rootTag ...string) string + func (r Result) Xml(rootTag ...string) string + type Schema struct + func (s *Schema) Model(table string) *Model + func (s *Schema) Table(table string) *Model + type Sql struct + Args []interface{} + End int64 + Error error + Format string + Group string + Sql string + Start int64 + type SqlResult struct + func (r *SqlResult) LastInsertId() (int64, error) + func (r *SqlResult) MustGetAffected() int64 + func (r *SqlResult) MustGetInsertId() int64 + func (r *SqlResult) RowsAffected() (int64, error) + type TX struct + func (tx *TX) BatchInsert(table string, list interface{}, batch ...int) (sql.Result, error) + func (tx *TX) BatchInsertIgnore(table string, list interface{}, batch ...int) (sql.Result, error) + func (tx *TX) BatchReplace(table string, list interface{}, batch ...int) (sql.Result, error) + func (tx *TX) BatchSave(table string, list interface{}, batch ...int) (sql.Result, error) + func (tx *TX) Commit() error + func (tx *TX) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error) + func (tx *TX) Exec(sql string, args ...interface{}) (sql.Result, error) + func (tx *TX) GetAll(sql string, args ...interface{}) (Result, error) + func (tx *TX) GetCount(sql string, args ...interface{}) (int, error) + func (tx *TX) GetOne(sql string, args ...interface{}) (Record, error) + func (tx *TX) GetScan(objPointer interface{}, sql string, args ...interface{}) error + func (tx *TX) GetStruct(obj interface{}, sql string, args ...interface{}) error + func (tx *TX) GetStructs(objPointerSlice interface{}, sql string, args ...interface{}) error + func (tx *TX) GetValue(sql string, args ...interface{}) (Value, error) + func (tx *TX) Insert(table string, data interface{}, batch ...int) (sql.Result, error) + func (tx *TX) InsertIgnore(table string, data interface{}, batch ...int) (sql.Result, error) + func (tx *TX) Model(table ...string) *Model + func (tx *TX) Prepare(sql string) (*sql.Stmt, error) + func (tx *TX) Query(sql string, args ...interface{}) (rows *sql.Rows, err error) + func (tx *TX) Replace(table string, data interface{}, batch ...int) (sql.Result, error) + func (tx *TX) Rollback() error + func (tx *TX) Save(table string, data interface{}, batch ...int) (sql.Result, error) + func (tx *TX) Schema(schema string) *Schema + func (tx *TX) Table(table ...string) *Model + func (tx *TX) Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) + type TableField struct + Comment string + Default interface{} + Extra string + Index int + Key string + Name string + Null bool + Type string + type Value = *gvar.Var