-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (37 loc) · 959 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"log"
"github.com/gohxs/hqi"
"github.com/gohxs/hqi/drv/slicedrv"
)
type User struct {
Name string
Number int
}
func main() {
coll := []User{}
q := hqi.NewQuery(&slicedrv.Driver{&coll})
q.Insert(User{"a", 3}, User{"b", 2}, User{"c", 1})
q.Insert(User{"a", 3}, User{"b", 2}, User{"c", 1})
fmt.Println("collection:", coll)
res := []User{}
// Limit
q.Find().Sort("-Name").List(&res)
log.Println("Result for Sort 1:", res)
q.Find().Skip(1).List(&res)
q.Find().Max(1).List(&res)
log.Println("Result for Max 1:", res)
//find
sqry := q.Find(`{"Name":"a"}`, `{"Name":"b"}`)
sqry.List(&res)
log.Println("Name:a or Name:b", res)
sqry.Limit(1, 0).List(&res)
log.Println("Limit(1,0):", res)
sqry.Limit(0, 2).List(&res)
log.Println("Limit(0,2):", res)
sqry.Update(hqi.M{"Number": 99}) // Why not?
sqry.List(&res)
log.Println("After Update Name:a or Name:b", res)
fmt.Println("collection:", coll)
}