xquery

package
v1.4.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NESTED_EDGE_OFFSET = 2

Functions

func CalcPage

func CalcPage(pageno, pagesize, total int) (int, int)

CalcPage 计算翻页

func ClusterInsertMulti

func ClusterInsertMulti(xi xorm.Interface, objs []IResetTable, reset, trunc bool) (total int64, err error)

ClusterInsertMulti 写入多行到分布式表中

func CreateTableLike

func CreateTableLike(engine *xorm.Engine, curr, orig string) (bool, error)

CreateTableLike 复制表结构,只用于MySQL

func ExecTx added in v1.4.2

func ExecTx(engine *xorm.Engine, modify ModifyFunc) error

ExecTx 执行事务

func FindTables

func FindTables(engine *xorm.Engine, prefix string, fullName bool) []string

FindTables 找出符合前缀的表名

func GetChangesFor

func GetChangesFor(v any, changes map[string]any) map[string]any

func GetColumns

func GetColumns(v any, alias string, cols []string) []string

func GetFinalType

func GetFinalType(v any) (rt reflect.Type)

func GetIndirectType

func GetIndirectType(v any) (rt reflect.Type)

func GetLevelString

func GetLevelString(lvl log.LogLevel) string

将 xorm 的日志级别转为字符串

func GetNullString

func GetNullString(data sql.NullString) (word string)

func GetPrimarykey

func GetPrimarykey(engine *xorm.Engine, m any) *schemas.Column

GetPrimarykey 获取Model的主键

func JoinQuery

func JoinQuery(engine *xorm.Engine, query *xorm.Session,
	table, fkey string, foreign ForeignTable) (*xorm.Session, []string)

JoinQuery 联表查询

func MoveEdge

func MoveEdge(query *xorm.Session, table string, base, offset int) error

MoveEdge 左右边界整体移动

func NegativeOffset

func NegativeOffset(offset, pagesize, total int) int

NegativeOffset 调整从后往前翻页

func NewNullString

func NewNullString(word string) sql.NullString

NewNullString string 与 NullString 相互转换

func Paginate

func Paginate(query *xorm.Session, pageno, pagesize int) *xorm.Session

Paginate 使用翻页

func Qprintf

func Qprintf(engine *xorm.Engine, format string, args ...any) string

Qprintf 对参数先进行转义Quote

func QueryAll added in v1.4.2

func QueryAll(qr *xorm.Session, filter FilterFunc, pages ...int) *xorm.Session

QueryAll 查询多行数据

func QuoteColumns

func QuoteColumns(cols []string, sep string, quote func(string) string) string

QuoteColumns 盲转义,认为字段名以小写字母开头

func RebuildNestedByDepth

func RebuildNestedByDepth(query *xorm.Session, table string) error

RebuildNestedByDepth 按照深度重建,即用之前比它深度小且最近的一个作为父节点

func SortedKeys

func SortedKeys(data any) (keys []string)

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 FilterFunc) *ClusterQuery

func (*ClusterQuery) ClearFilters

func (q *ClusterQuery) ClearFilters() *ClusterQuery

func (*ClusterQuery) ClusterCount

func (q *ClusterQuery) ClusterCount(bean ...any) (int64, error)

ClusterCount 分布式计数,查询全部表

func (*ClusterQuery) ClusterPaginate

func (q *ClusterQuery) ClusterPaginate(pageno, pagesize int,
	rowsSlicePtr any, condiBean ...any) (int64, error)

ClusterPaginate 分布式计数和翻页,查询全部表,但只获取部分结果集

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) GetQuery

func (q *ClusterQuery) GetQuery() *xorm.Session

GetQuery 重新构建当前查询,因为每次 COUNT 和 FIND 等操作会释放查询(只有主表名还保留着)

func (*ClusterQuery) GetTable

func (q *ClusterQuery) GetTable() string

GetTable 获取当前表名

func (*ClusterQuery) Limit

func (q *ClusterQuery) Limit(limit int, start ...int) *ClusterQuery

func (*ClusterQuery) OrderBy

func (q *ClusterQuery) OrderBy(order string) *ClusterQuery

func (ClusterQuery) Quote

func (q ClusterQuery) Quote(value string) string

type FilterFunc

type FilterFunc = func(qr *xorm.Session) *xorm.Session

FilterFunc 过滤查询

type ForeignTable

type ForeignTable struct {
	Join  enums.SqlJoin
	Table ITableName
	Alias string
	Index string
}

ForeignTable 关联表

func (ForeignTable) AliasName

func (f ForeignTable) AliasName() string

AliasName 表名或别名,通常用于字段之前

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 ITableComment

type ITableComment interface {
	TableComment() string
}

ITableComment 数据表注释

type ITableName

type ITableName interface {
	TableName() string
}

ITableName 数据表名

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 FilterFunc) *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) FindPaginate

func (q *LeftJoinQuery) FindPaginate(pageno, pagesize int,
	rowsSlicePtr any, condiBean ...any) (int64, error)

FindPaginate 计数和翻页,只获取部分结果集

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) Limit

func (q *LeftJoinQuery) Limit(limit int, start ...int) *LeftJoinQuery

func (*LeftJoinQuery) OrderBy

func (q *LeftJoinQuery) OrderBy(order string) *LeftJoinQuery

func (LeftJoinQuery) Quote

func (q LeftJoinQuery) Quote(value string) string

type ModifyFunc

type ModifyFunc = func(tx *xorm.Session) (int64, error)

ModifyFunc 修改操作,用于事务

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) FilterFunc

AncestorsFilter 找出所有直系祖先节点

func (NestedMixin) ChildrenFilter

func (n NestedMixin) ChildrenFilter(rank int, depthFirst bool) FilterFunc

ChildrenFilter 找出所有子孙节点

func (NestedMixin) CountChildren

func (n NestedMixin) CountChildren() int

CountChildren 有多少个子孙节点

func (NestedMixin) GetDepth

func (n NestedMixin) GetDepth() int

func (NestedMixin) IsLeaf

func (n NestedMixin) IsLeaf() bool

IsLeaf 是否叶子节点

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 SqlLogger

type SqlLogger struct {
	*utils.Logger
	// contains filtered or unexported fields
}

func NewSqlLogger

func NewSqlLogger(filename string) *SqlLogger

func (*SqlLogger) IsShowSQL

func (s *SqlLogger) IsShowSQL() bool

IsShowSQL implement ILogger

func (*SqlLogger) Level

func (s *SqlLogger) Level() log.LogLevel

Level implement ILogger

func (*SqlLogger) SetLevel

func (s *SqlLogger) SetLevel(l log.LogLevel)

SetLevel implement ILogger

func (*SqlLogger) ShowSQL

func (s *SqlLogger) ShowSQL(show ...bool)

ShowSQL implement ILogger

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 时间相关的三个典型字段

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL