search

package
v0.0.0-...-d57715f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README

type 描述 query示例
exact/iexact 等于 status=1
contains 包含 name=n
gt/gte 大于/大于等于 age=18
lt/lte 小于/小于等于 age=18
startswith 以…起始 content=hell
endswith 以…结束 content=world
in in查询 status[]=0&status[]=1
isnull isnull查询 startTime=1
order 排序 sort=asc/sort=desc

e.g.

type ApplicationQuery struct {
	Id       string    `search:"type:icontains;column:id;table:receipt" form:"id"`
	Domain   string    `search:"type:icontains;column:domain;table:receipt" form:"domain"`
	Version  string    `search:"type:exact;column:version;table:receipt" form:"version"`
	Status   []int     `search:"type:in;column:status;table:receipt" form:"status"`
	Start    time.Time `search:"type:gte;column:created_at;table:receipt" form:"start"`
	End      time.Time `search:"type:lte;column:created_at;table:receipt" form:"end"`
	TestJoin \`search:"type:left;on:id:receipt_id;table:receipt_goods;join:receipts"\`
}

type TestJoin struct {
	PaymentAccount string \`search:"type:icontains;column:payment_account;table:receipts" form:"payment_account"\`
}

Documentation

Index

Constants

View Source
const (
	// FromQueryTag tag标记
	FromQueryTag = "search"
)

Variables

This section is empty.

Functions

func MakeCondition

func MakeCondition(q interface{}, page ...Pagination) func(db *xorm.Session) *xorm.Session

func ResolveSearchQuery

func ResolveSearchQuery(q interface{}, condition Condition, nu int)

ResolveSearchQuery 解析 *

  • exact / iexact 等于
  • contains / icontains 包含
  • gt / gte 大于 / 大于等于
  • lt / lte 小于 / 小于等于
  • startswith / istartswith 以…起始
  • endswith / iendswith 以…结束
  • in
  • isnull
  • order 排序 e.g. order[key]=desc order[key]=asc

Types

type Condition

type Condition interface {
	SetWhere(k string, v []interface{})
	SetIn(k string, v []interface{})
	SetOr(k string, v []interface{})
	SetOrder(k string)
	SetJoinOn(t, table, on string) Condition
}

type Pagination

type Pagination interface {
	GetPageIndex() int
	GetPageSize() int
}

type XormCondition

type XormCondition struct {
	XormPublic
	Join []*XormJoin
}

func (*XormCondition) SetJoinOn

func (e *XormCondition) SetJoinOn(t, table, on string) Condition

type XormJoin

type XormJoin struct {
	Type   string
	Table  string
	JoinOn string
	XormPublic
}

func (*XormJoin) SetJoinOn

func (e *XormJoin) SetJoinOn(t, table, on string) Condition

type XormPublic

type XormPublic struct {
	Where map[string][]interface{}
	In    map[string][]interface{}
	Order []string
	Or    map[string][]interface{}
}

func (*XormPublic) SetIn

func (e *XormPublic) SetIn(k string, v []interface{})

func (*XormPublic) SetOr

func (e *XormPublic) SetOr(k string, v []interface{})

func (*XormPublic) SetOrder

func (e *XormPublic) SetOrder(k string)

func (*XormPublic) SetWhere

func (e *XormPublic) SetWhere(k string, v []interface{})

Jump to

Keyboard shortcuts

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