This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
query.go
128 lines (103 loc) · 3.02 KB
/
query.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package pmgo
import (
"time"
mgo "gopkg.in/mgo.v2"
)
type QueryManager interface {
All(result interface{}) error
Apply(change mgo.Change, result interface{}) (info *mgo.ChangeInfo, err error)
Batch(n int) QueryManager
Comment(comment string) QueryManager
Count() (n int, err error)
Distinct(key string, result interface{}) error
Explain(result interface{}) error
For(result interface{}, f func() error) error
Hint(indexKey ...string) QueryManager
Iter() *mgo.Iter
Limit(n int) QueryManager
LogReplay() QueryManager
MapReduce(job *mgo.MapReduce, result interface{}) (info *mgo.MapReduceInfo, err error)
One(result interface{}) (err error)
Prefetch(p float64) QueryManager
Select(selector interface{}) QueryManager
SetMaxScan(n int) QueryManager
SetMaxTime(d time.Duration) QueryManager
Skip(n int) QueryManager
Snapshot() QueryManager
Sort(fields ...string) QueryManager
Tail(timeout time.Duration) IterManager
}
type Query struct {
query *mgo.Query
}
func NewQueryManager(q *mgo.Query) QueryManager {
return &Query{
query: q,
}
}
func (q *Query) All(result interface{}) error {
return q.query.All(result)
}
func (q *Query) Apply(change mgo.Change, result interface{}) (info *mgo.ChangeInfo, err error) {
return q.query.Apply(change, result)
}
func (q *Query) Batch(n int) QueryManager {
return &Query{q.query.Batch(n)}
}
func (q *Query) Comment(comment string) QueryManager {
return &Query{q.query.Comment(comment)}
}
func (q *Query) Count() (int, error) {
return q.query.Count()
}
func (q *Query) Distinct(key string, result interface{}) error {
return q.query.Distinct(key, result)
}
func (q *Query) Explain(result interface{}) error {
return q.query.Explain(result)
}
func (q *Query) For(result interface{}, f func() error) error {
return q.query.For(result, f)
}
func (q *Query) Hint(indexKey ...string) QueryManager {
return &Query{q.query.Hint(indexKey...)}
}
func (q *Query) Iter() *mgo.Iter {
return q.query.Iter()
}
func (q *Query) Limit(n int) QueryManager {
return &Query{q.query.Limit(n)}
}
func (q *Query) LogReplay() QueryManager {
return &Query{q.query.LogReplay()}
}
func (q *Query) MapReduce(job *mgo.MapReduce, result interface{}) (info *mgo.MapReduceInfo, err error) {
return q.query.MapReduce(job, result)
}
func (q *Query) One(result interface{}) error {
return q.query.One(result)
}
func (q *Query) Prefetch(p float64) QueryManager {
return &Query{q.query.Prefetch(p)}
}
func (q *Query) Select(selector interface{}) QueryManager {
return &Query{q.query.Select(selector)}
}
func (q *Query) SetMaxScan(n int) QueryManager {
return &Query{q.query.SetMaxScan(n)}
}
func (q *Query) SetMaxTime(d time.Duration) QueryManager {
return &Query{q.query.SetMaxTime(d)}
}
func (q *Query) Skip(n int) QueryManager {
return &Query{q.query.Skip(n)}
}
func (q *Query) Snapshot() QueryManager {
return &Query{q.query.Snapshot()}
}
func (q *Query) Sort(fields ...string) QueryManager {
return &Query{q.query.Sort(fields...)}
}
func (q *Query) Tail(timeout time.Duration) IterManager {
return q.query.Tail(timeout)
}