forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_select.go
141 lines (124 loc) · 5.89 KB
/
query_select.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
129
130
131
132
133
134
135
136
137
138
139
140
141
package gorethink
import (
p "gopkg.in/dancannon/gorethink.v2/ql2"
)
// DB references a database.
func DB(args ...interface{}) Term {
return constructRootTerm("DB", p.Term_DB, args, map[string]interface{}{})
}
// TableOpts contains the optional arguments for the Table term
type TableOpts struct {
ReadMode interface{} `gorethink:"read_mode,omitempty"`
UseOutdated interface{} `gorethink:"use_outdated,omitempty"` // Deprecated
IdentifierFormat interface{} `gorethink:"identifier_format,omitempty"`
}
func (o TableOpts) toMap() map[string]interface{} {
return optArgsToMap(o)
}
// Table selects all documents in a table. This command can be chained with
// other commands to do further processing on the data.
//
// There are two optional arguments.
// - useOutdated: if true, this allows potentially out-of-date data to be
// returned, with potentially faster reads. It also allows you to perform reads
// from a secondary replica if a primary has failed. Default false.
// - identifierFormat: possible values are name and uuid, with a default of name.
// If set to uuid, then system tables will refer to servers, databases and tables
// by UUID rather than name. (This only has an effect when used with system tables.)
func Table(name interface{}, optArgs ...TableOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructRootTerm("Table", p.Term_TABLE, []interface{}{name}, opts)
}
// Table selects all documents in a table. This command can be chained with
// other commands to do further processing on the data.
//
// There are two optional arguments.
// - useOutdated: if true, this allows potentially out-of-date data to be
// returned, with potentially faster reads. It also allows you to perform reads
// from a secondary replica if a primary has failed. Default false.
// - identifierFormat: possible values are name and uuid, with a default of name.
// If set to uuid, then system tables will refer to servers, databases and tables
// by UUID rather than name. (This only has an effect when used with system tables.)
func (t Term) Table(name interface{}, optArgs ...TableOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Table", p.Term_TABLE, []interface{}{name}, opts)
}
// Get gets a document by primary key. If nothing was found, RethinkDB will return a nil value.
func (t Term) Get(args ...interface{}) Term {
return constructMethodTerm(t, "Get", p.Term_GET, args, map[string]interface{}{})
}
// GetAllOpts contains the optional arguments for the GetAll term
type GetAllOpts struct {
Index interface{} `gorethink:"index,omitempty"`
}
func (o GetAllOpts) toMap() map[string]interface{} {
return optArgsToMap(o)
}
// GetAll gets all documents where the given value matches the value of the primary
// index. Multiple values can be passed this function if you want to select multiple
// documents. If the documents you are fetching have composite keys then each
// argument should be a slice. For more information see the examples.
func (t Term) GetAll(keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{})
}
// GetAllByIndex gets all documents where the given value matches the value of
// the requested index.
func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{"index": index})
}
// BetweenOpts contains the optional arguments for the Between term
type BetweenOpts struct {
Index interface{} `gorethink:"index,omitempty"`
LeftBound interface{} `gorethink:"left_bound,omitempty"`
RightBound interface{} `gorethink:"right_bound,omitempty"`
}
func (o BetweenOpts) toMap() map[string]interface{} {
return optArgsToMap(o)
}
// Between gets all documents between two keys. Accepts three optional arguments:
// index, leftBound, and rightBound. If index is set to the name of a secondary
// index, between will return all documents where that index’s value is in the
// specified range (it uses the primary key by default). leftBound or rightBound
// may be set to open or closed to indicate whether or not to include that endpoint
// of the range (by default, leftBound is closed and rightBound is open).
//
// You may also use the special constants r.minval and r.maxval for boundaries,
// which represent “less than any index key” and “more than any index key”
// respectively. For instance, if you use r.minval as the lower key, then between
// will return all documents whose primary keys (or indexes) are less than the
// specified upper key.
func (t Term) Between(lowerKey, upperKey interface{}, optArgs ...BetweenOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Between", p.Term_BETWEEN, []interface{}{lowerKey, upperKey}, opts)
}
// FilterOpts contains the optional arguments for the Filter term
type FilterOpts struct {
Default interface{} `gorethink:"default,omitempty"`
}
func (o FilterOpts) toMap() map[string]interface{} {
return optArgsToMap(o)
}
// Filter gets all the documents for which the given predicate is true.
//
// Filter can be called on a sequence, selection, or a field containing an array
// of elements. The return type is the same as the type on which the function was
// called on. The body of every filter is wrapped in an implicit `.default(false)`,
// and the default value can be changed by passing the optional argument `default`.
// Setting this optional argument to `r.error()` will cause any non-existence
// errors to abort the filter.
func (t Term) Filter(f interface{}, optArgs ...FilterOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Filter", p.Term_FILTER, []interface{}{funcWrap(f)}, opts)
}