Documentation ¶
Index ¶
- type Base
- type Criteria
- func (c Criteria) And(cri Base) Where
- func (c Criteria) Append(cri Base) Where
- func (c Criteria) Col(col string) Criteria
- func (c Criteria) End(q Base) Where
- func (c Criteria) Eq(val interface{}) Criteria
- func (c Criteria) Gt(val interface{}) Criteria
- func (c Criteria) Gte(val interface{}) Criteria
- func (c Criteria) In(val interface{}) Criteria
- func (c Criteria) IsNotNull() Criteria
- func (c Criteria) IsNull() Criteria
- func (c Criteria) Like(val interface{}) Criteria
- func (c Criteria) Lt(val interface{}) Criteria
- func (c Criteria) Lte(val interface{}) Criteria
- func (c Criteria) Ne(val interface{}) Criteria
- func (c Criteria) NotIn(val interface{}) Criteria
- func (c Criteria) Or(cri Base) Where
- func (c Criteria) Sql() (string, []interface{})
- func (c Criteria) ToWhere() Where
- type Order
- type Page
- type PageRet
- type Q
- type String
- type Where
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Criteria ¶
type Criteria struct {
// contains filtered or unexported fields
}
Criteria wrap a group of column, value and operator such as name = 20
Example ¶
query := C().Col("name").Eq("wubin").Or(C().Col("school").Eq("havard")).And(C().Col("age").Eq(18)) fmt.Println(query.Sql()) query = C().Col("name").Eq("wubin").Or(C().Col("school").Eq("havard")).And(C().Col("delete_at").IsNotNull()) fmt.Println(query.Sql()) query = C().Col("name").Eq("wubin").Or(C().Col("school").In("havard")).And(C().Col("delete_at").IsNotNull()) fmt.Println(query.Sql()) query = C().Col("name").Eq("wubin").Or(C().Col("school").In([]string{"havard", "beijing unv"})).And(C().Col("delete_at").IsNotNull()) fmt.Println(query.Sql()) query = C().Col("name").Eq("wubin").Or(C().Col("age").In([]int{5, 10})).And(C().Col("delete_at").IsNotNull()) fmt.Println(query.Sql()) query = C().Col("name").Ne("wubin").Or(C().Col("create_at").Lt("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())
Output: ((`name` = ? or `school` = ?) and `age` = ?) [wubin havard 18] ((`name` = ? or `school` = ?) and `delete_at` is not null) [wubin havard] ((`name` = ? or `school` in (?)) and `delete_at` is not null) [wubin havard] ((`name` = ? or `school` in (?,?)) and `delete_at` is not null) [wubin havard beijing unv] ((`name` = ? or `age` in (?,?)) and `delete_at` is not null) [wubin 5 10] (`name` != ? or `create_at` < ?) [wubin now()] order by `create_at` desc,`score` asc limit ?,? [30 5] 7 order by `score` asc limit ?,? [20 10]
func (Criteria) NotIn ¶
NotIn set not in operator and column value, val should be a slice type value
type Where ¶
type Where struct {
// contains filtered or unexported fields
}
Where concat children clauses with one of logic operators And, Or, Append
Click to show internal directories.
Click to hide internal directories.