Debian Codegraph @

query_select.go

raw symbols SCIP
1 package rethinkdb
2
3 import (
4 p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2"
5 )
6
7 // DB references a database.
8 func DB(args ...interface{}) Term {
9 return constructRootTerm("DB", p.Term_DB, args, map[string]interface{}{})
10 }
11
12 // TableOpts contains the optional arguments for the Table term
13 type TableOpts struct {
14 ReadMode interface{} `rethinkdb:"read_mode,omitempty"`
15 UseOutdated interface{} `rethinkdb:"use_outdated,omitempty"` // Deprecated
16 IdentifierFormat interface{} `rethinkdb:"identifier_format,omitempty"`
17 }
18
19 func (o TableOpts) toMap() map[string]interface{} {
20 return optArgsToMap(o)
21 }
22
23 // Table selects all documents in a table. This command can be chained with
24 // other commands to do further processing on the data.
25 //
26 // There are two optional arguments.
27 // - useOutdated: if true, this allows potentially out-of-date data to be
28 // returned, with potentially faster reads. It also allows you to perform reads
29 // from a secondary replica if a primary has failed. Default false.
30 // - identifierFormat: possible values are name and uuid, with a default of name.
31 // If set to uuid, then system tables will refer to servers, databases and tables
32 // by UUID rather than name. (This only has an effect when used with system tables.)
33 func Table(name interface{}, optArgs ...TableOpts) Term {
34 opts := map[string]interface{}{}
35 if len(optArgs) >= 1 {
36 opts = optArgs[0].toMap()
37 }
38 return constructRootTerm("Table", p.Term_TABLE, []interface{}{name}, opts)
39 }
40
41 // Table selects all documents in a table. This command can be chained with
42 // other commands to do further processing on the data.
43 //
44 // There are two optional arguments.
45 // - useOutdated: if true, this allows potentially out-of-date data to be
46 // returned, with potentially faster reads. It also allows you to perform reads
47 // from a secondary replica if a primary has failed. Default false.
48 // - identifierFormat: possible values are name and uuid, with a default of name.
49 // If set to uuid, then system tables will refer to servers, databases and tables
50 // by UUID rather than name. (This only has an effect when used with system tables.)
51 func (t Term) Table(name interface{}, optArgs ...TableOpts) Term {
52 opts := map[string]interface{}{}
53 if len(optArgs) >= 1 {
54 opts = optArgs[0].toMap()
55 }
56 return constructMethodTerm(t, "Table", p.Term_TABLE, []interface{}{name}, opts)
57 }
58
59 // Get gets a document by primary key. If nothing was found, RethinkDB will return a nil value.
60 func (t Term) Get(args ...interface{}) Term {
61 return constructMethodTerm(t, "Get", p.Term_GET, args, map[string]interface{}{})
62 }
63
64 // GetAllOpts contains the optional arguments for the GetAll term
65 type GetAllOpts struct {
66 Index interface{} `rethinkdb:"index,omitempty"`
67 }
68
69 func (o GetAllOpts) toMap() map[string]interface{} {
70 return optArgsToMap(o)
71 }
72
73 // GetAll gets all documents where the given value matches the value of the primary
74 // index. Multiple values can be passed this function if you want to select multiple
75 // documents. If the documents you are fetching have composite keys then each
76 // argument should be a slice. For more information see the examples.
77 func (t Term) GetAll(keys ...interface{}) Term {
78 return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{})
79 }
80
81 // GetAllByIndex gets all documents where the given value matches the value of
82 // the requested index.
83 func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term {
84 return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{"index": index})
85 }
86
87 // BetweenOpts contains the optional arguments for the Between term
88 type BetweenOpts struct {
89 Index interface{} `rethinkdb:"index,omitempty"`
90 LeftBound interface{} `rethinkdb:"left_bound,omitempty"`
91 RightBound interface{} `rethinkdb:"right_bound,omitempty"`
92 }
93
94 func (o BetweenOpts) toMap() map[string]interface{} {
95 return optArgsToMap(o)
96 }
97
98 // Between gets all documents between two keys. Accepts three optional arguments:
99 // index, leftBound, and rightBound. If index is set to the name of a secondary
100 // index, between will return all documents where that index’s value is in the
101 // specified range (it uses the primary key by default). leftBound or rightBound
102 // may be set to open or closed to indicate whether or not to include that endpoint
103 // of the range (by default, leftBound is closed and rightBound is open).
104 //
105 // You may also use the special constants r.minval and r.maxval for boundaries,
106 // which represent “less than any index key” and “more than any index key”
107 // respectively. For instance, if you use r.minval as the lower key, then between
108 // will return all documents whose primary keys (or indexes) are less than the
109 // specified upper key.
110 func (t Term) Between(lowerKey, upperKey interface{}, optArgs ...BetweenOpts) Term {
111 opts := map[string]interface{}{}
112 if len(optArgs) >= 1 {
113 opts = optArgs[0].toMap()
114 }
115 return constructMethodTerm(t, "Between", p.Term_BETWEEN, []interface{}{lowerKey, upperKey}, opts)
116 }
117
118 // FilterOpts contains the optional arguments for the Filter term
119 type FilterOpts struct {
120 Default interface{} `rethinkdb:"default,omitempty"`
121 }
122
123 func (o FilterOpts) toMap() map[string]interface{} {
124 return optArgsToMap(o)
125 }
126
127 // Filter gets all the documents for which the given predicate is true.
128 //
129 // Filter can be called on a sequence, selection, or a field containing an array
130 // of elements. The return type is the same as the type on which the function was
131 // called on. The body of every filter is wrapped in an implicit `.default(false)`,
132 // and the default value can be changed by passing the optional argument `default`.
133 // Setting this optional argument to `r.error()` will cause any non-existence
134 // errors to abort the filter.
135 func (t Term) Filter(f interface{}, optArgs ...FilterOpts) Term {
136 opts := map[string]interface{}{}
137 if len(optArgs) >= 1 {
138 opts = optArgs[0].toMap()
139 }
140 return constructMethodTerm(t, "Filter", p.Term_FILTER, []interface{}{funcWrap(f)}, opts)
141 }