query

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base added in v0.6.7

type Base interface {
	Sql() string
}

type Criteria added in v0.6.7

type Criteria struct {
	// contains filtered or unexported fields
}
Example
query := C().Col("name").Eq(Literal("wubin")).Or(C().Col("school").Eq(Literal("havard"))).And(C().Col("age").Eq(Literal(18)))
fmt.Println(query.Sql())

query = C().Col("name").Eq(Literal("wubin")).Or(C().Col("school").Eq(Literal("havard"))).And(C().Col("delete_at").IsNotNull())
fmt.Println(query.Sql())

query = C().Col("name").Eq(Literal("wubin")).Or(C().Col("school").In(Literal("havard"))).And(C().Col("delete_at").IsNotNull())
fmt.Println(query.Sql())

query = C().Col("name").Eq(Literal("wubin")).Or(C().Col("school").In(Literal([]string{"havard", "beijing unv"}))).And(C().Col("delete_at").IsNotNull())
fmt.Println(query.Sql())

var d int
var e int
d = 10
e = 5

query = C().Col("name").Eq(Literal("wubin")).Or(C().Col("age").In(Literal([]*int{&d, &e}))).And(C().Col("delete_at").IsNotNull())
fmt.Println(query.Sql())

query = C().Col("name").Ne(Literal("wubin")).Or(C().Col("create_at").Lt(Func("now()")))
fmt.Println(query.Sql())

query = C().Col("name").Ne(Literal("wubin")).Or(C().Col("create_at").Lte(Func("now()")))
fmt.Println(query.Sql())

query = C().Col("name").Ne(Literal("wubin")).Or(C().Col("create_at").Gt(Func("now()")))
fmt.Println(query.Sql())

query = C().Col("name").Ne(Literal("wubin")).Or(C().Col("create_at").Gte(Func("now()")))
fmt.Println(query.Sql())

page := Page{
	Orders: []Order{
		{
			Col:  "create_at",
			Sort: sortenum.Desc,
		},
	},
	Offset: 20,
	Size:   10,
}
page = page.Order(Order{
	Col:  "score",
	Sort: sortenum.Asc,
})
page = page.Limit(30, 5)
fmt.Println(page.Sql())
pageRet := NewPageRet(page)
fmt.Println(pageRet.PageNo)

fmt.Println(P().Order(Order{
	Col:  "score",
	Sort: sortenum.Asc,
}).Limit(20, 10).Sql())

query = C().Col("name").Eq(Literal("wubin")).Or(C().Col("school").Eq(Literal("havard"))).
	And(C().Col("age").Eq(Literal(18))).
	Or(C().Col("score").Gte(Literal(90)))
fmt.Println(query.Sql())

page = P().Order(Order{
	Col:  "create_at",
	Sort: sortenum.Desc,
}).Limit(0, 1)
var where Q
where = C().Col("project_id").Eq(Literal(1))
where = where.And(C().Col("delete_at").IsNull())
where = where.Append(page)
fmt.Println(where.Sql())
Output:

((`name` = 'wubin' or `school` = 'havard') and `age` = '18')
((`name` = 'wubin' or `school` = 'havard') and `delete_at` is not null)
((`name` = 'wubin' or `school` in ('havard')) and `delete_at` is not null)
((`name` = 'wubin' or `school` in ('havard','beijing unv')) and `delete_at` is not null)
((`name` = 'wubin' or `age` in ('10','5')) and `delete_at` is not null)
(`name` != 'wubin' or `create_at` < now())
(`name` != 'wubin' or `create_at` <= now())
(`name` != 'wubin' or `create_at` > now())
(`name` != 'wubin' or `create_at` >= now())
order by create_at desc,score asc limit 30,5
7
order by score asc limit 20,10
(((`name` = 'wubin' or `school` = 'havard') and `age` = '18') or `score` >= '90')
(`project_id` = '1' and `delete_at` is null) order by create_at desc limit 0,1

func C

func C() Criteria

func (Criteria) And added in v0.6.7

func (c Criteria) And(cri Base) Where

func (Criteria) Append added in v0.6.7

func (c Criteria) Append(cri Base) Where

func (Criteria) Col added in v0.6.7

func (c Criteria) Col(col string) Criteria

func (Criteria) Eq added in v0.6.7

func (c Criteria) Eq(val Val) Criteria

func (Criteria) Gt added in v0.6.7

func (c Criteria) Gt(val Val) Criteria

func (Criteria) Gte added in v0.6.7

func (c Criteria) Gte(val Val) Criteria

func (Criteria) In added in v0.6.7

func (c Criteria) In(val Val) Criteria

func (Criteria) IsNotNull added in v0.6.7

func (c Criteria) IsNotNull() Criteria

func (Criteria) IsNull added in v0.6.7

func (c Criteria) IsNull() Criteria

func (Criteria) Lt added in v0.6.7

func (c Criteria) Lt(val Val) Criteria

func (Criteria) Lte added in v0.6.7

func (c Criteria) Lte(val Val) Criteria

func (Criteria) Ne added in v0.6.7

func (c Criteria) Ne(val Val) Criteria

func (Criteria) Or added in v0.6.7

func (c Criteria) Or(cri Base) Where

func (Criteria) Sql added in v0.6.7

func (c Criteria) Sql() string

type Order

type Order struct {
	Col  string
	Sort sortenum.Sort
}

type Page

type Page struct {
	Orders []Order
	Offset int
	Size   int
}

func P

func P() Page

func (Page) Limit

func (p Page) Limit(offset, size int) Page

func (Page) Order

func (p Page) Order(o Order) Page

func (Page) Sql

func (p Page) Sql() string

Sql order by age desc limit 2,1

type PageRet

type PageRet struct {
	Items    interface{}
	PageNo   int
	PageSize int
	Total    int
	HasNext  bool
}

func NewPageRet

func NewPageRet(page Page) PageRet

type Q

type Q interface {
	Base
	And(q Base) Where
	Or(q Base) Where
	Append(q Base) Where
}

type Val

type Val struct {
	Data interface{}
	Type valtypeenum.ValType
}

func Func

func Func(data string) Val

func Literal

func Literal(data interface{}) Val

type Where added in v0.6.7

type Where struct {
	// contains filtered or unexported fields
}

func (Where) And added in v0.6.7

func (w Where) And(whe Base) Where

func (Where) Append added in v0.6.7

func (w Where) Append(whe Base) Where

func (Where) Or added in v0.6.7

func (w Where) Or(whe Base) Where

func (Where) Sql added in v0.6.7

func (w Where) Sql() string

Jump to

Keyboard shortcuts

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