Documentation ¶
Overview ¶
Package orm
Package orm ¶
Package orm ¶
Package orm ¶
Package orm ¶
Package orm ¶
Package orm ¶
Package orm ¶
Package orm
Index ¶
- Variables
- func CloseVerify()
- func InitNotReadyLastInsertID(db ...int)
- func SetGlobalVerify(v Verify)
- func Struct2Map(raw interface{}, excludeKey ...string) map[string]interface{}
- func TransSession(ctx context.Context, sqlDB db.Executor, ...) (err error)
- type BaseQuery
- type DB
- type GroupBy
- type Having
- type Limit
- type ORM
- func (orm *ORM) ClearCache() *ORM
- func (orm *ORM) Clone(ctx context.Context) *ORM
- func (orm *ORM) Count(clearCache bool) (c int64, err error)
- func (orm *ORM) CustomSQL(sql string) *ORM
- func (orm *ORM) DeleteByWhere(where map[string]interface{}) (affected int64, err error)
- func (orm *ORM) Distinct(b bool) *ORM
- func (orm *ORM) ExecuteSQL(customSQL string) (affectedRow int64, err error)
- func (orm *ORM) Exist() (b bool, err error)
- func (orm *ORM) FetchData(dataType interface{}, flat bool, fetch func(row interface{}) bool) (err error)
- func (orm *ORM) GetBaseExecutor() (conn db.BaseExecutor, isTx bool)
- func (orm *ORM) GetExecutor() db.Executor
- func (orm *ORM) GetTx() db.Tx
- func (orm *ORM) GroupBy(cols ...string) *ORM
- func (orm *ORM) Having(col string, value interface{}) *ORM
- func (orm *ORM) HavingSome(where Having) *ORM
- func (orm *ORM) InsertMany(data []interface{}, trans bool) (affected int64, insertIDs []int64, err error)
- func (orm *ORM) InsertManySameClos(data []interface{}, cols []string, batchSize int, trans bool) (affected int64, err error)
- func (orm *ORM) InsertOne(data interface{}) (insertID int64, err error)
- func (orm *ORM) KeepQuery(b bool) *ORM
- func (orm *ORM) Limit(size uint) *ORM
- func (orm *ORM) Logger(logger log.Log)
- func (orm *ORM) OracleMergeUnionAll(all bool) *ORM
- func (orm *ORM) Order(cols ...string) *ORM
- func (orm *ORM) OverLimit(over, size uint) *ORM
- func (orm *ORM) Page(pageNo, pageSize uint) *ORM
- func (orm *ORM) PageData(result interface{}, flat bool, pageNo, pageSize uint) (pg *Paging, err error)
- func (orm *ORM) PrimaryKey(k string) *ORM
- func (orm *ORM) Query(pair ...interface{}) *ORM
- func (orm *ORM) ReplaceMany(data []interface{}, trans bool) (affected int64, insertIds []int64, err error)
- func (orm *ORM) ReplaceManySameClos(data []interface{}, cols []string, batchSize int, trans bool) (affected int64, err error)
- func (orm *ORM) ReplaceOne(data interface{}) (affected int64, err error)
- func (orm *ORM) SQLServerExcludePK(exclude bool) *ORM
- func (orm *ORM) SaveMany(data []interface{}, trans bool) (affected int64, err error)
- func (orm *ORM) Select(cols ...string) *ORM
- func (orm *ORM) SelectColLinkStr(s string) *ORM
- func (orm *ORM) SelectForUpdate(b bool) *ORM
- func (orm *ORM) SetDefLimit(n uint) *ORM
- func (orm *ORM) ToData(result interface{}, flat bool) (err error)
- func (orm *ORM) ToSQL(flat bool) string
- func (orm *ORM) UniqueKeys(uniqueKey ...string) *ORM
- func (orm *ORM) UpdateByWhere(update map[string]interface{}, where Where) (affected int64, err error)
- func (orm *ORM) UpdateMany(data []interface{}, trans bool) (affected int64, err error)
- func (orm *ORM) UpdateOne(data interface{}) (affected int64, err error)
- func (orm *ORM) UpsertMany(data []interface{}, trans bool) (affected int64, insertIDs []int64, err error)
- func (orm *ORM) UpsertManySameClos(data []interface{}, cols []string, batchSize int, trans bool) (affected int64, err error)
- func (orm *ORM) UpsertOne(data interface{}) (insertID int64, err error)
- func (orm *ORM) Where(col string, value interface{}) *ORM
- func (orm *ORM) Wheres(where Where) *ORM
- type Order
- type Paging
- type Reference
- type Select
- type Tx
- type Verify
- type Where
Constants ¶
This section is empty.
Variables ¶
var ErrBetweenValueMatch = errors.New("[between]: the parameter array length is required to be 2")
var ErrClient = fmt.Errorf("executor and tx are all nil")
var ErrCustomSQL = errors.New("custom sql does not allow this operation")
var ErrDBFunc = errors.New("this method is not currently supported in the current database")
var ErrDBType = errors.New("the current database type is not currently supported")
var ErrFetchType = errors.New("[fetch]: datatype is not a pointer, int string map struct is required")
var ErrMapKeyType = errors.New("map's key type must be \"String\"")
var ErrParams = errors.New("when \"flat=false\", the value of the map can only be interface{}")
var ErrTargetNotSettable = errors.New("[scanner]: target is not settable! a pointer is required")
var ErrTooFewColumn = errors.New("too few columns")
var ErrTooManyColumn = errors.New("too many columns")
Functions ¶
func CloseVerify ¶ added in v1.8.30
func CloseVerify()
func InitNotReadyLastInsertID ¶ added in v1.5.0
func InitNotReadyLastInsertID(db ...int)
InitNotReadyLastInsertID 初始化方法 LastInsertID 没有实现的数据库类型,会覆盖默认设置
func SetGlobalVerify ¶
func SetGlobalVerify(v Verify)
func Struct2Map ¶
Types ¶
type BaseQuery ¶
type BaseQuery struct { // 用户自定义sql CustomSQL string PrivateKey string RefConf *Reference // 字段别名链接字符串,SelectRaw 为false有效 SelectColLinkStr string // true:使用原始字段名;false:使用别名 SelectRaw bool TableName string Distinct bool SelectForUpdate bool Select Select Order Order Limit Limit Where Where GroupBy GroupBy Having Having // contains filtered or unexported fields }
BaseQuery # 为内置符号,标志为原始字段,不进行任何处理,仅在以下数据有效: Select Order GroupBy Where Having
type ORM ¶
type ORM struct { // 查询配置数据 Q *databaseQuery // contains filtered or unexported fields }
ORM # 为内置符号,标志为原始字段,不进行任何处理,仅在以下数据有效: Select Order GroupBy Where Having
func NewORMWithTx ¶
func (*ORM) ClearCache ¶
func (*ORM) DeleteByWhere ¶
func (*ORM) ExecuteSQL ¶ added in v1.5.0
func (*ORM) GetBaseExecutor ¶ added in v1.10.21
func (orm *ORM) GetBaseExecutor() (conn db.BaseExecutor, isTx bool)
GetBaseExecutor 获取原始的数据库链接或Tx conn 按需断言
func (*ORM) GetExecutor ¶ added in v1.10.21
GetExecutor 获取原始的数据库链接
func (*ORM) HavingSome ¶
func (*ORM) InsertMany ¶
func (orm *ORM) InsertMany(data []interface{}, trans bool) (affected int64, insertIDs []int64, err error)
InsertMany 每条数据字段不一致或者想获取每条数据的主键,使用此方法
func (*ORM) InsertManySameClos ¶
func (orm *ORM) InsertManySameClos(data []interface{}, cols []string, batchSize int, trans bool) (affected int64, err error)
InsertManySameClos 字段一致使用此方法 data 需要处理的数据集合,数据格式为:map、*struct、struct,字段不在 cols 的被赋值null cols 需要处理的字段集合 batchSize 单次并发数量 trans 是否使用事务
func (*ORM) OracleMergeUnionAll ¶ added in v1.5.0
OracleMergeUnionAll oracle merge union 类型,默认是 true
func (*ORM) PrimaryKey ¶
func (*ORM) ReplaceMany ¶
func (orm *ORM) ReplaceMany(data []interface{}, trans bool) (affected int64, insertIds []int64, err error)
ReplaceMany 每条数据字段不一致或者想获取每条数据的主键,使用此方法
func (*ORM) ReplaceManySameClos ¶
func (orm *ORM) ReplaceManySameClos(data []interface{}, cols []string, batchSize int, trans bool) (affected int64, err error)
ReplaceManySameClos data 需要处理的数据集合,数据格式为:map、*struct、struct,字段不在 cols 的被赋值null cols 需要处理的字段集合 batchSize 单次并发数量 trans 是否使用事务
func (*ORM) ReplaceOne ¶
func (*ORM) SQLServerExcludePK ¶ added in v1.5.0
SQLServerExcludePK sql server 排除主键
func (*ORM) SaveMany ¶
SaveMany data 需要处理的数据集合,数据格式为:map、*struct、struct,字段不在 cols 的被赋值null cols 需要处理的字段集合 batchSize 单次并发数量 trans 是否使用事务
func (*ORM) Select ¶
Select 参数:* 主表所有字段;tag.* tag对应表所有字段;tag1.tag2.* tag1表的tag2的所有字段;以此类推 *0 等价 * 只考虑主表,不展开子表 *1 对应层级的表展开一层(主表+一级关联表,二级以下联表不算) *2 对应层级的表展开二层(主表+一级关联表+二级关联表,三级以下联表不算) *n 对应层级的表展开n层(主表+1级关联表+2级关联表+...+n级关联表,n+1级以下联表不算) 上述法则同样适用于tag.*1,此时的主表为tag,以此类推 tag1.tag2.*1,主表为tag1.tag2 字段排除:优先级最高 -name:删除name字段;-* 移除主表字段; -tag.name:删除tag表对应的name字段;-tag.*:删除整个tag表所有字段 排除字段也支持 *n 语法,-*n *n与- 均不可与 # 混用
func (*ORM) SelectColLinkStr ¶
func (*ORM) SelectForUpdate ¶
func (*ORM) SetDefLimit ¶ added in v1.8.10
SetDefLimit 修改默认limit
func (*ORM) UniqueKeys ¶ added in v1.5.0
UniqueKeys 设置新的唯一键,用于 upsert
func (*ORM) UpdateByWhere ¶
func (*ORM) UpdateMany ¶
UpdateMany 主键,id 不能为空,为空将更新失败
func (*ORM) UpsertMany ¶
func (orm *ORM) UpsertMany(data []interface{}, trans bool) (affected int64, insertIDs []int64, err error)
UpsertMany 每条数据字段不一致或者想获取每条数据的主键,使用此方法
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
func NewReference ¶
func (*Reference) AddTableDef ¶
AddTableDef 添加表定义