search

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

type 描述 query示例
exact/iexact 等于 status=1
contains/icontanins 包含 name=n
gt/gte 大于/大于等于 age=18
lt/lte 小于/小于等于 age=18
startswith/istartswith 以…起始 content=hell
endswith/iendswith 以…结束 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"`
	ApplicationOrder
}
type ApplicationOrder struct {
	IdOrder string `search:"type:order;column:id;table:receipt" form"id_order"`
}

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

Documentation

Index

Constants

View Source
const (
	TypeTag   = "type"   // 类型标签
	ColumnTag = "column" // 字段标签
	TableTag  = "table"  // 表标签
	OnTag     = "on"     // on标签
	JoinTag   = "join"   // 连接标签
	SkipTag   = "-"      // 连接标签

	LeftTypeTag        = "left"
	ExactTypeTag       = "exact"
	IExactTypeTag      = "iexact"
	ContainsTypeTag    = "contains"
	IContainsTypeTag   = "icontains"
	GtTypeTag          = "gt"  // 大于
	GteTypeTag         = "gte" // 大于等于
	LtTypeTag          = "lt"  // 小于
	LteTypeTag         = "lte" // 小于等于
	StartsWithTypeTag  = "startswith"
	IStartsWithTypeTag = "istartswith"
	EndWithTypeTag     = "endswith"
	IEndWithTypeTag    = "iendswith"
	IsNullTypeTag      = "isnull"
	InTypeTag          = "in"
	OrderTypeTag       = "order"
	DescTypeTag        = "desc"
	AscTypeTag         = "asc"
)
View Source
const (
	// Mysql 数据库标识
	Mysql = "mysql"
	// Postgres 数据库标识
	Postgres = "postgres"
)

Variables

View Source
var (
	// QueryTag tag标记
	QueryTag = "search"
)

Functions

func ResolveSearchQuery

func ResolveSearchQuery(driver string, q interface{}, condition Condition)

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{})
	SetOr(k string, v []interface{})
	SetOrder(k string)
	SetJoinOn(t, on string) Condition
}

Condition 条件

type OrmCondition

type OrmCondition struct {
	OrmWhere
	Join []*OrmJoin
}

OrmCondition Orm查询的条件

func NewOrmCondition

func NewOrmCondition() *OrmCondition

func (*OrmCondition) SetJoinOn

func (e *OrmCondition) SetJoinOn(t, on string) Condition

SetJoinOn 设置join on

type OrmJoin

type OrmJoin struct {
	Type   string
	JoinOn string
	OrmWhere
}

OrmJoin 连接标签

func (*OrmJoin) SetJoinOn

func (e *OrmJoin) SetJoinOn(t, on string) Condition

SetJoinOn 设置连接

type OrmWhere

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

OrmWhere 查询条件,where、order、or

func (*OrmWhere) SetOr

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

SetOr 设置or

func (*OrmWhere) SetOrder

func (e *OrmWhere) SetOrder(k string)

SetOrder 设置order

func (*OrmWhere) SetWhere

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

SetWhere 设置where

Jump to

Keyboard shortcuts

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