models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitCache

func InitCache(cfg *config.Settings, name string, verbose bool) (*session.SessionRegistry, error)

func InitConn

func InitConn(cfg *config.Settings, name string, verbose bool) (*xorm.Engine, error)

func MoveEdge

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

左右边界整体移动

func Paginate

func Paginate(query *xorm.Session, out interface{}, pageno, pagesize int) (int, error)

*

  • 翻页查询,out参数需要传引用
  • 使用方法 total, err := Paginate(query, &rows, pageno, pagesize)

Types

type BaseModel

type BaseModel struct {
	Id uint `json:"id" xorm:"not null pk autoincr INT(10)"`
}

*

  • 带自增主键的基础Model

func (BaseModel) TableComment

func (BaseModel) TableComment() string

type FilterFunc

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

*

  • 过滤查询
  • 使用方法 query = query.Scopes(filters ...FilterFunc)

type ITableComment

type ITableComment interface {
	TableComment() string
}

*

  • 数据表注释

type ITableName

type ITableName interface {
	TableName() string
}

*

  • 数据表名

type NestedModel

type NestedModel struct {
	Lft   int `json:"lft" xorm:"not null default 0 comment('左边界') INT(10)"`
	Rgt   int `json:"rgt" xorm:"not null default 0 comment('右边界') index INT(10)"`
	Depth int `json:"depth" xorm:"not null default 1 comment('高度') index TINYINT(3)"`
}

嵌套集合树

func (*NestedModel) AddToParent

func (n *NestedModel) AddToParent(parent *NestedModel, tbQuery *xorm.Session) error

添加到父节点最末,tbQuery一定要使用db.Table(...)

func (NestedModel) AncestorsFilter

func (n NestedModel) AncestorsFilter(Backward bool) FilterFunc

找出所有直系祖先节点

func (NestedModel) ChildrenFilter

func (n NestedModel) ChildrenFilter(rank uint8) FilterFunc

找出所有子孙节点

func (NestedModel) CountChildren

func (n NestedModel) CountChildren() int

有多少个子孙节点

func (NestedModel) IsLeaf

func (n NestedModel) IsLeaf() bool

是否叶子节点

type SqlTag

type SqlTag struct {
	reflect.StructTag
	// contains filtered or unexported fields
}

StructTag named sql or xorm

func NewSqlTag

func NewSqlTag() *SqlTag

func (*SqlTag) Delete

func (st *SqlTag) Delete(key string)

Deletes a tag

func (*SqlTag) Get

func (st *SqlTag) Get(key string) (string, bool)

Returns a tag from the tag data

func (*SqlTag) ParseTag

func (st *SqlTag) ParseTag(tag reflect.StructTag)

func (*SqlTag) Set

func (st *SqlTag) Set(key, val string)

Sets a tag in the tag data map

func (*SqlTag) String

func (st *SqlTag) String(head string) string

转为字符串格式,头通常使用sql或xorm

type TimeModel

type TimeModel 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"`
}

*

  • 时间相关的三个典型字段

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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