Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyOptions(qr *xorm.Session, opts []QueryOption) *xorm.Session
- func CalcPage(pageno, pagesize, total int) (int, int)
- func ClusterInsertMulti(xi xorm.Interface, objs []IResetTable, reset, trunc bool) (total int64, err error)
- func CreateTableLike(engine *xorm.Engine, curr, orig string) (bool, error)
- func ExecTx(engine *xorm.Engine, modify ModifyFunc) error
- func FindTables(engine *xorm.Engine, prefix string, fullName bool) []string
- func GetColumns(v any, alias string, cols []string) []string
- func GetIndirectType(v any) (rt reflect.Type)
- func GetNullString(data utils.NullString) (word string)
- func GetPrimarykey(engine *xorm.Engine, m any) *schemas.Column
- func JoinQuery(engine *xorm.Engine, query *xorm.Session, table, fkey string, ...) (*xorm.Session, []string)
- func MoveEdge(query *xorm.Session, table string, base, offset int) error
- func NegativeOffset(offset, pagesize, total int) int
- func NewNullString(word string) utils.NullString
- func Qprintf(engine *xorm.Engine, format string, args ...any) string
- func QuoteColumns(cols []string, sep string, quote func(string) string) string
- func RebuildNestedByDepth(query *xorm.Session, table string) error
- func UpdateSlice[T any](dataCh <-chan T, size int, batch func(lst []T) error) (err error)
- type BeanFunc
- type ClusterMixin
- func GetClusterMixinFor(kind, prefix string, engine *xorm.Engine) *ClusterMixin
- func NewClusterDaily(t time.Time) *ClusterMixin
- func NewClusterHourly(t time.Time) *ClusterMixin
- func NewClusterMixin(kind string, t time.Time) *ClusterMixin
- func NewClusterMonthly(t time.Time) *ClusterMixin
- func NewClusterQuarterly(t time.Time) *ClusterMixin
- func NewClusterWeekly(t time.Time) *ClusterMixin
- type ClusterQuery
- func (q *ClusterQuery) AddFilter(filter QueryOption) *ClusterQuery
- func (q *ClusterQuery) ClearFilters() *ClusterQuery
- func (q *ClusterQuery) ClusterCount(bean ...any) (int64, error)
- func (q *ClusterQuery) Count(bean ...any) (int64, error)
- func (q *ClusterQuery) FindAndCount(rowsSlicePtr any, condiBean ...any) (int64, error)
- func (q *ClusterQuery) FindPage(pageno, pagesize int, rowsSlicePtr any, condiBean ...any) (int64, error)
- func (q *ClusterQuery) GetQuery() *xorm.Session
- func (q *ClusterQuery) GetTable() string
- func (q ClusterQuery) Quote(value string) string
- type ForeignTable
- type IResetTable
- type ITableComment
- type ITableName
- type LeftJoinQuery
- func (q *LeftJoinQuery) AddFilter(filter QueryOption) *LeftJoinQuery
- func (q *LeftJoinQuery) AddLeftJoin(foreign ITableName, pkey, fkey, alias string) *LeftJoinQuery
- func (q *LeftJoinQuery) ClearFilters() *LeftJoinQuery
- func (q *LeftJoinQuery) Count(bean ...any) (int64, error)
- func (q *LeftJoinQuery) FindAndCount(rowsSlicePtr any, condiBean ...any) (int64, error)
- func (q *LeftJoinQuery) FindPage(pageno, pagesize int, rowsSlicePtr any, condiBean ...any) (int64, error)
- func (q *LeftJoinQuery) GetQuery() *xorm.Session
- func (q *LeftJoinQuery) LeftJoin(foreign ITableName, fkey string) *LeftJoinQuery
- func (q *LeftJoinQuery) Quote(value string) string
- type ModifyFunc
- type NestedMixin
- func (n *NestedMixin) AddToParent(parent *NestedMixin, query *xorm.Session, table string) (err error)
- func (n *NestedMixin) AncestorsFilter(backward bool) QueryOption
- func (n *NestedMixin) ChildrenFilter(rank int, depthFirst bool) QueryOption
- func (n *NestedMixin) CountChildren() int
- func (n *NestedMixin) GetDepth() int
- func (n *NestedMixin) IsLeaf() bool
- type NestedRow
- type QueryOption
- func WithLimit(limit int, offset ...int) QueryOption
- func WithOrderBy(column string, desc bool) QueryOption
- func WithPage(pageno, pagesize int) QueryOption
- func WithRange(col string, args ...any) QueryOption
- func WithTable(tableOrBean any, cols ...string) QueryOption
- func WithWhere(cond string, args ...any) QueryOption
- type RowChannel
- func (r *RowChannel) Update(eng *xorm.Engine, proc BeanFunc, consume func(val any), col string, ...) error
- func (r *RowChannel) UpdateAll(eng *xorm.Engine, consume func(val any), opts ...QueryOption) error
- func (r *RowChannel) UpdateIndex(eng *xorm.Engine, consume func(val any), col string, opts ...QueryOption) error
- type RowIterator
- func (r *RowIterator) FindAll(eng *xorm.Engine, proc BeanFunc, opts ...QueryOption) (count int64, err error)
- func (r *RowIterator) FindCount(eng *xorm.Engine, proc BeanFunc, opts ...QueryOption) (count int64, err error)
- func (r *RowIterator) FindIndex(eng *xorm.Engine, proc BeanFunc, col string, opts ...QueryOption) (count int64, err error)
- func (r RowIterator) IsEnough(n int) bool
- func (r RowIterator) IterBean(qr *xorm.Session, proc BeanFunc, opts []QueryOption) (count int64, err error)
- func (r RowIterator) IterCol(qr *xorm.Session, proc BeanFunc, col string, opts []QueryOption) (count int64, err error)
- type SqlJoin
- type TimeMixin
Constants ¶
const ( MaxReadSize = 3000 // 一次读取最大行数 MaxWriteSize = 200 // 一次写入最大行数 )
Variables ¶
var NestedEdgeOffset = 2
Functions ¶
func ApplyOptions ¶ added in v1.6.0
func ApplyOptions(qr *xorm.Session, opts []QueryOption) *xorm.Session
ApplyOptions 使用查询条件
func ClusterInsertMulti ¶
func ClusterInsertMulti(xi xorm.Interface, objs []IResetTable, reset, trunc bool) (total int64, err error)
ClusterInsertMulti 写入多行到分布式表中
func CreateTableLike ¶
CreateTableLike 复制表结构,只用于MySQL
func FindTables ¶
FindTables 找出符合前缀的表名
func GetIndirectType ¶
func GetNullString ¶
func GetNullString(data utils.NullString) (word string)
func GetPrimarykey ¶
GetPrimarykey 获取Model的主键
func JoinQuery ¶
func JoinQuery(engine *xorm.Engine, query *xorm.Session, table, fkey string, foreign ForeignTable, ) (*xorm.Session, []string)
JoinQuery 联表查询
func NewNullString ¶
func NewNullString(word string) utils.NullString
NewNullString string 与 NullString 相互转换
func QuoteColumns ¶
QuoteColumns 盲转义,认为字段名以小写字母开头
func RebuildNestedByDepth ¶
RebuildNestedByDepth 按照深度重建,即用之前比它深度小且最近的一个作为父节点
Types ¶
type ClusterMixin ¶
type ClusterMixin struct { Date time.Time Suffixes sort.StringSlice TableNamePrefix string Kind, Format string }
ClusterMixin 按月分表
func GetClusterMixinFor ¶
func GetClusterMixinFor(kind, prefix string, engine *xorm.Engine) *ClusterMixin
func NewClusterDaily ¶
func NewClusterDaily(t time.Time) *ClusterMixin
func NewClusterHourly ¶
func NewClusterHourly(t time.Time) *ClusterMixin
func NewClusterMixin ¶
func NewClusterMixin(kind string, t time.Time) *ClusterMixin
func NewClusterMonthly ¶
func NewClusterMonthly(t time.Time) *ClusterMixin
func NewClusterQuarterly ¶
func NewClusterQuarterly(t time.Time) *ClusterMixin
func NewClusterWeekly ¶
func NewClusterWeekly(t time.Time) *ClusterMixin
func (ClusterMixin) GetSuffix ¶
func (m ClusterMixin) GetSuffix() string
func (*ClusterMixin) Move ¶
func (m *ClusterMixin) Move(n int) *ClusterMixin
func (*ClusterMixin) Next ¶
func (m *ClusterMixin) Next() bool
func (*ClusterMixin) Prev ¶
func (m *ClusterMixin) Prev() bool
func (*ClusterMixin) SetTime ¶
func (m *ClusterMixin) SetTime(t time.Time, toFirst bool) *ClusterMixin
type ClusterQuery ¶
type ClusterQuery struct { *ClusterMixin *xorm.Session // contains filtered or unexported fields }
ClusterQuery 分布式查询
func NewClusterQuery ¶
func NewClusterQuery(engine *xorm.Engine, cluster *ClusterMixin) *ClusterQuery
func (*ClusterQuery) AddFilter ¶
func (q *ClusterQuery) AddFilter(filter QueryOption) *ClusterQuery
func (*ClusterQuery) ClearFilters ¶
func (q *ClusterQuery) ClearFilters() *ClusterQuery
func (*ClusterQuery) ClusterCount ¶
func (q *ClusterQuery) ClusterCount(bean ...any) (int64, error)
ClusterCount 分布式计数,查询全部表
func (*ClusterQuery) Count ¶
func (q *ClusterQuery) Count(bean ...any) (int64, error)
Count 计数,只查询当前表
func (*ClusterQuery) FindAndCount ¶
func (q *ClusterQuery) FindAndCount(rowsSlicePtr any, condiBean ...any) (int64, error)
FindAndCount 计数和获取结果集,只查询当前表
func (*ClusterQuery) FindPage ¶ added in v1.6.0
func (q *ClusterQuery) FindPage(pageno, pagesize int, rowsSlicePtr any, condiBean ...any, ) (int64, error)
FindPage 分布式计数和翻页,查询全部表,但只获取部分结果集
func (*ClusterQuery) GetQuery ¶
func (q *ClusterQuery) GetQuery() *xorm.Session
GetQuery 重新构建当前查询,因为每次 COUNT 和 FIND 等操作会释放查询(只有主表名还保留着)
func (ClusterQuery) Quote ¶
func (q ClusterQuery) Quote(value string) string
type ForeignTable ¶
type ForeignTable struct { Join SqlJoin Table ITableName Alias string Index string }
ForeignTable 关联表
func (ForeignTable) TableName ¶
func (f ForeignTable) TableName() string
TableName 表名和别名,通常用于 FROM 或 Join 之后
type IResetTable ¶
type IResetTable interface { ResetTable(curr string, trunc bool) error ITableName }
IResetTable 创建或清空表
type LeftJoinQuery ¶
type LeftJoinQuery struct { Native ITableName ForeignKeys []string Foreigns map[string]ForeignTable *xorm.Session // contains filtered or unexported fields }
LeftJoinQuery Left Join 联表查询
func NewLeftJoinQuery ¶
func NewLeftJoinQuery(engine *xorm.Engine, native ITableName) *LeftJoinQuery
NewLeftJoinQuery native 为最左侧的主表,查询其所有字段
func (*LeftJoinQuery) AddFilter ¶
func (q *LeftJoinQuery) AddFilter(filter QueryOption) *LeftJoinQuery
func (*LeftJoinQuery) AddLeftJoin ¶
func (q *LeftJoinQuery) AddLeftJoin(foreign ITableName, pkey, fkey, alias string) *LeftJoinQuery
AddLeftJoin 添加次序要和 struct 定义一致
func (*LeftJoinQuery) ClearFilters ¶
func (q *LeftJoinQuery) ClearFilters() *LeftJoinQuery
func (*LeftJoinQuery) Count ¶
func (q *LeftJoinQuery) Count(bean ...any) (int64, error)
Count 计数,由于左联接数量只跟主表有关,这里不去 Join
func (*LeftJoinQuery) FindAndCount ¶
func (q *LeftJoinQuery) FindAndCount( rowsSlicePtr any, condiBean ...any, ) (int64, error)
FindAndCount 计数和获取结果集
func (*LeftJoinQuery) FindPage ¶ added in v1.6.0
func (q *LeftJoinQuery) FindPage(pageno, pagesize int, rowsSlicePtr any, condiBean ...any, ) (int64, error)
FindPage 计数和翻页,只获取部分结果集
func (*LeftJoinQuery) GetQuery ¶
func (q *LeftJoinQuery) GetQuery() *xorm.Session
GetQuery 重新构建当前查询,因为每次 COUNT 和 FIND 等操作会释放查询(只有主表名还保留着)
func (*LeftJoinQuery) LeftJoin ¶
func (q *LeftJoinQuery) LeftJoin(foreign ITableName, fkey string) *LeftJoinQuery
LeftJoin foreign 为副表,只查询其部分字段,读取字段的 json tag 作为字段名
func (*LeftJoinQuery) Quote ¶
func (q *LeftJoinQuery) Quote(value string) string
type NestedMixin ¶
type NestedMixin struct { Lft int `json:"lft" xorm:"notnull default 0 comment('左边界') INT(10)"` // 左边界 Rgt int `json:"rgt" xorm:"notnull default 0 comment('右边界') index INT(10)"` // 右边界 Depth int `json:"depth" xorm:"notnull default 1 comment('高度') index TINYINT(3)"` // 高度 }
NestedMixin 嵌套集合树
func (*NestedMixin) AddToParent ¶
func (n *NestedMixin) AddToParent(parent *NestedMixin, query *xorm.Session, table string) (err error)
AddToParent 添加到父节点最末
func (*NestedMixin) AncestorsFilter ¶
func (n *NestedMixin) AncestorsFilter(backward bool) QueryOption
AncestorsFilter 找出所有直系祖先节点
func (*NestedMixin) ChildrenFilter ¶
func (n *NestedMixin) ChildrenFilter(rank int, depthFirst bool) QueryOption
ChildrenFilter 找出所有子孙节点
func (*NestedMixin) CountChildren ¶
func (n *NestedMixin) CountChildren() int
CountChildren 有多少个子孙节点
func (*NestedMixin) GetDepth ¶
func (n *NestedMixin) GetDepth() int
type NestedRow ¶
type NestedRow struct { Id int `json:"id" xorm:"notnull pk autoincr INT(10)"` ParentIdNihility996 int `json:"-" xorm:"-"` // 阻止对象被混入其他 Model 的特殊字段 *NestedMixin `json:",inline" xorm:"extends"` }
type QueryOption ¶ added in v1.6.0
QueryOption 查询条件
func WithLimit ¶ added in v1.6.0
func WithLimit(limit int, offset ...int) QueryOption
WithLimit 限定最大行数
func WithOrderBy ¶ added in v1.6.0
func WithOrderBy(column string, desc bool) QueryOption
WithOrderBy 限定排序
func WithTable ¶ added in v1.6.0
func WithTable(tableOrBean any, cols ...string) QueryOption
WithTable 限定数据表和字段
func WithWhere ¶ added in v1.6.0
func WithWhere(cond string, args ...any) QueryOption
WithWhere where查询
type RowChannel ¶ added in v1.6.1
type RowChannel struct { *RowIterator // contains filtered or unexported fields }
RowChannel 队列异步操作
func NewRowChannel ¶ added in v1.6.1
func NewRowChannel(iter *RowIterator) *RowChannel
NewRowChannel 创建迭代查询
func (*RowChannel) Update ¶ added in v1.6.1
func (r *RowChannel) Update(eng *xorm.Engine, proc BeanFunc, consume func(val any), col string, opts []QueryOption, ) error
Update 通用队列生产和消费
func (*RowChannel) UpdateAll ¶ added in v1.6.1
func (r *RowChannel) UpdateAll(eng *xorm.Engine, consume func(val any), opts ...QueryOption, ) error
UpdateAll 消费每行字典
func (*RowChannel) UpdateIndex ¶ added in v1.6.1
func (r *RowChannel) UpdateIndex(eng *xorm.Engine, consume func(val any), col string, opts ...QueryOption, ) error
UpdateIndex 消费主键列表
type RowIterator ¶ added in v1.6.1
type RowIterator struct { Bean any // contains filtered or unexported fields }
RowIterator 迭代查询
func NewRowIterator ¶ added in v1.6.1
func NewRowIterator(bean any, order string, desc bool, size, msec int) *RowIterator
NewRowIterator 创建迭代查询
func (*RowIterator) FindAll ¶ added in v1.6.1
func (r *RowIterator) FindAll(eng *xorm.Engine, proc BeanFunc, opts ...QueryOption, ) (count int64, err error)
FindAll 迭代查询每行,后累计总行数
func (*RowIterator) FindCount ¶ added in v1.6.1
func (r *RowIterator) FindCount(eng *xorm.Engine, proc BeanFunc, opts ...QueryOption, ) (count int64, err error)
FindCount 迭代查询,先查询总行数
func (*RowIterator) FindIndex ¶ added in v1.6.1
func (r *RowIterator) FindIndex(eng *xorm.Engine, proc BeanFunc, col string, opts ...QueryOption, ) (count int64, err error)
FindIndex 迭代查询主键列表,后累计总行数
func (RowIterator) IsEnough ¶ added in v1.6.1
func (r RowIterator) IsEnough(n int) bool
IsEnough 没有更多行需要查询了
func (RowIterator) IterBean ¶ added in v1.6.1
func (r RowIterator) IterBean(qr *xorm.Session, proc BeanFunc, opts []QueryOption, ) (count int64, err error)
IterBean 迭代查询对象
func (RowIterator) IterCol ¶ added in v1.6.1
func (r RowIterator) IterCol(qr *xorm.Session, proc BeanFunc, col string, opts []QueryOption, ) (count int64, err error)
IterCol 迭代查询主键
type SqlJoin ¶ added in v1.7.5
type SqlJoin int
SqlJoin 数据表联接
func SqlJoinString ¶ added in v1.7.5
SqlJoinString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func SqlJoinValues ¶ added in v1.7.5
func SqlJoinValues() []SqlJoin
SqlJoinValues returns all values of the enum
func (SqlJoin) IsASqlJoin ¶ added in v1.7.5
IsASqlJoin returns "true" if the value is listed in the enum definition. "false" otherwise
func (SqlJoin) MarshalText ¶ added in v1.7.5
MarshalText implements the encoding.TextMarshaler interface for SqlJoin
func (*SqlJoin) UnmarshalText ¶ added in v1.7.5
UnmarshalText implements the encoding.TextUnmarshaler interface for SqlJoin
type TimeMixin ¶
type TimeMixin struct { CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"` // 创建时间 UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"` // 更新时间 DeletedAt time.Time `json:"deleted_at" xorm:"deleted comment('删除时间') index TIMESTAMP"` // 删除时间 }
TimeMixin 时间相关的三个典型字段