-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
query_math.go
177 lines (143 loc) · 5.83 KB
/
query_math.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package gorethink
import (
p "github.com/dancannon/gorethink/ql2"
)
// Add sums two numbers or concatenates two arrays.
func (t Term) Add(args ...interface{}) Term {
return constructMethodTerm(t, "Add", p.Term_ADD, args, map[string]interface{}{})
}
// Add sums two numbers or concatenates two arrays.
func Add(args ...interface{}) Term {
return constructRootTerm("Add", p.Term_ADD, args, map[string]interface{}{})
}
// Sub subtracts two numbers.
func (t Term) Sub(args ...interface{}) Term {
return constructMethodTerm(t, "Sub", p.Term_SUB, args, map[string]interface{}{})
}
// Sub subtracts two numbers.
func Sub(args ...interface{}) Term {
return constructRootTerm("Sub", p.Term_SUB, args, map[string]interface{}{})
}
// Mul multiplies two numbers.
func (t Term) Mul(args ...interface{}) Term {
return constructMethodTerm(t, "Mul", p.Term_MUL, args, map[string]interface{}{})
}
func Mul(args ...interface{}) Term {
return constructRootTerm("Mul", p.Term_MUL, args, map[string]interface{}{})
}
// Div divides two numbers.
func (t Term) Div(args ...interface{}) Term {
return constructMethodTerm(t, "Div", p.Term_DIV, args, map[string]interface{}{})
}
// Div divides two numbers.
func Div(args ...interface{}) Term {
return constructRootTerm("Div", p.Term_DIV, args, map[string]interface{}{})
}
// Mod divides two numbers and returns the remainder.
func (t Term) Mod(args ...interface{}) Term {
return constructMethodTerm(t, "Mod", p.Term_MOD, args, map[string]interface{}{})
}
// Mod divides two numbers and returns the remainder.
func Mod(args ...interface{}) Term {
return constructRootTerm("Mod", p.Term_MOD, args, map[string]interface{}{})
}
// And performs a logical and on two values.
func (t Term) And(args ...interface{}) Term {
return constructMethodTerm(t, "And", p.Term_ALL, args, map[string]interface{}{})
}
// And performs a logical and on two values.
func And(args ...interface{}) Term {
return constructRootTerm("And", p.Term_ALL, args, map[string]interface{}{})
}
// Or performs a logical or on two values.
func (t Term) Or(args ...interface{}) Term {
return constructMethodTerm(t, "Or", p.Term_ANY, args, map[string]interface{}{})
}
// Or performs a logical or on two values.
func Or(args ...interface{}) Term {
return constructRootTerm("Or", p.Term_ANY, args, map[string]interface{}{})
}
// Eq returns true if two values are equal.
func (t Term) Eq(args ...interface{}) Term {
return constructMethodTerm(t, "Eq", p.Term_EQ, args, map[string]interface{}{})
}
// Eq returns true if two values are equal.
func Eq(args ...interface{}) Term {
return constructRootTerm("Eq", p.Term_EQ, args, map[string]interface{}{})
}
// Ne returns true if two values are not equal.
func (t Term) Ne(args ...interface{}) Term {
return constructMethodTerm(t, "Ne", p.Term_NE, args, map[string]interface{}{})
}
// Ne returns true if two values are not equal.
func Ne(args ...interface{}) Term {
return constructRootTerm("Ne", p.Term_NE, args, map[string]interface{}{})
}
// Gt returns true if the first value is greater than the second.
func (t Term) Gt(args ...interface{}) Term {
return constructMethodTerm(t, "Gt", p.Term_GT, args, map[string]interface{}{})
}
// Gt returns true if the first value is greater than the second.
func Gt(args ...interface{}) Term {
return constructRootTerm("Gt", p.Term_GT, args, map[string]interface{}{})
}
// Ge returns true if the first value is greater than or equal to the second.
func (t Term) Ge(args ...interface{}) Term {
return constructMethodTerm(t, "Ge", p.Term_GE, args, map[string]interface{}{})
}
// Ge returns true if the first value is greater than or equal to the second.
func Ge(args ...interface{}) Term {
return constructRootTerm("Ge", p.Term_GE, args, map[string]interface{}{})
}
// Lt returns true if the first value is less than the second.
func (t Term) Lt(args ...interface{}) Term {
return constructMethodTerm(t, "Lt", p.Term_LT, args, map[string]interface{}{})
}
// Lt returns true if the first value is less than the second.
func Lt(args ...interface{}) Term {
return constructRootTerm("Lt", p.Term_LT, args, map[string]interface{}{})
}
// Le returns true if the first value is less than or equal to the second.
func (t Term) Le(args ...interface{}) Term {
return constructMethodTerm(t, "Le", p.Term_LE, args, map[string]interface{}{})
}
// Le returns true if the first value is less than or equal to the second.
func Le(args ...interface{}) Term {
return constructRootTerm("Le", p.Term_LE, args, map[string]interface{}{})
}
// Not performs a logical not on a value.
func (t Term) Not(args ...interface{}) Term {
return constructMethodTerm(t, "Not", p.Term_NOT, args, map[string]interface{}{})
}
// Not performs a logical not on a value.
func Not(args ...interface{}) Term {
return constructRootTerm("Not", p.Term_NOT, args, map[string]interface{}{})
}
type RandomOpts struct {
Float interface{} `gorethink:"float,omitempty"`
}
func (o *RandomOpts) toMap() map[string]interface{} {
return optArgsToMap(o)
}
// Generate a random number between the given bounds. If no arguments are
// given, the result will be a floating-point number in the range [0,1).
//
// When passing a single argument, r.random(x), the result will be in the
// range [0,x), and when passing two arguments, r.random(x,y), the range is
// [x,y). If x and y are equal, an error will occur, unless generating a
// floating-point number, for which x will be returned.
//
// Note: The last argument given will always be the 'open' side of the range,
// but when generating a floating-point number, the 'open' side may be less
// than the 'closed' side.
func (t Term) Random(args ...interface{}) Term {
var opts = map[string]interface{}{}
// Look for options map
if len(args) > 0 {
if possibleOpts, ok := args[len(args)-1].(RandomOpts); ok {
opts = possibleOpts.toMap()
args = args[:len(args)-1]
}
}
return constructMethodTerm(t, "Random", p.Term_RANDOM, args, opts)
}