gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/query_math.go (about) 1 package rethinkdb 2 3 import ( 4 p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2" 5 ) 6 7 var ( 8 // MinVal represents the smallest possible value RethinkDB can store 9 MinVal = constructRootTerm("MinVal", p.Term_MINVAL, []interface{}{}, map[string]interface{}{}) 10 // MaxVal represents the largest possible value RethinkDB can store 11 MaxVal = constructRootTerm("MaxVal", p.Term_MAXVAL, []interface{}{}, map[string]interface{}{}) 12 ) 13 14 // Add sums two numbers or concatenates two arrays. 15 func (t Term) Add(args ...interface{}) Term { 16 return constructMethodTerm(t, "Add", p.Term_ADD, args, map[string]interface{}{}) 17 } 18 19 // Add sums two numbers or concatenates two arrays. 20 func Add(args ...interface{}) Term { 21 return constructRootTerm("Add", p.Term_ADD, args, map[string]interface{}{}) 22 } 23 24 // Sub subtracts two numbers. 25 func (t Term) Sub(args ...interface{}) Term { 26 return constructMethodTerm(t, "Sub", p.Term_SUB, args, map[string]interface{}{}) 27 } 28 29 // Sub subtracts two numbers. 30 func Sub(args ...interface{}) Term { 31 return constructRootTerm("Sub", p.Term_SUB, args, map[string]interface{}{}) 32 } 33 34 // Mul multiplies two numbers. 35 func (t Term) Mul(args ...interface{}) Term { 36 return constructMethodTerm(t, "Mul", p.Term_MUL, args, map[string]interface{}{}) 37 } 38 39 // Mul multiplies two numbers. 40 func Mul(args ...interface{}) Term { 41 return constructRootTerm("Mul", p.Term_MUL, args, map[string]interface{}{}) 42 } 43 44 // Div divides two numbers. 45 func (t Term) Div(args ...interface{}) Term { 46 return constructMethodTerm(t, "Div", p.Term_DIV, args, map[string]interface{}{}) 47 } 48 49 // Div divides two numbers. 50 func Div(args ...interface{}) Term { 51 return constructRootTerm("Div", p.Term_DIV, args, map[string]interface{}{}) 52 } 53 54 // Mod divides two numbers and returns the remainder. 55 func (t Term) Mod(args ...interface{}) Term { 56 return constructMethodTerm(t, "Mod", p.Term_MOD, args, map[string]interface{}{}) 57 } 58 59 // Mod divides two numbers and returns the remainder. 60 func Mod(args ...interface{}) Term { 61 return constructRootTerm("Mod", p.Term_MOD, args, map[string]interface{}{}) 62 } 63 64 // And performs a logical and on two values. 65 func (t Term) And(args ...interface{}) Term { 66 return constructMethodTerm(t, "And", p.Term_AND, args, map[string]interface{}{}) 67 } 68 69 // And performs a logical and on two values. 70 func And(args ...interface{}) Term { 71 return constructRootTerm("And", p.Term_AND, args, map[string]interface{}{}) 72 } 73 74 // Or performs a logical or on two values. 75 func (t Term) Or(args ...interface{}) Term { 76 return constructMethodTerm(t, "Or", p.Term_OR, args, map[string]interface{}{}) 77 } 78 79 // Or performs a logical or on two values. 80 func Or(args ...interface{}) Term { 81 return constructRootTerm("Or", p.Term_OR, args, map[string]interface{}{}) 82 } 83 84 // Eq returns true if two values are equal. 85 func (t Term) Eq(args ...interface{}) Term { 86 return constructMethodTerm(t, "Eq", p.Term_EQ, args, map[string]interface{}{}) 87 } 88 89 // Eq returns true if two values are equal. 90 func Eq(args ...interface{}) Term { 91 return constructRootTerm("Eq", p.Term_EQ, args, map[string]interface{}{}) 92 } 93 94 // Ne returns true if two values are not equal. 95 func (t Term) Ne(args ...interface{}) Term { 96 return constructMethodTerm(t, "Ne", p.Term_NE, args, map[string]interface{}{}) 97 } 98 99 // Ne returns true if two values are not equal. 100 func Ne(args ...interface{}) Term { 101 return constructRootTerm("Ne", p.Term_NE, args, map[string]interface{}{}) 102 } 103 104 // Gt returns true if the first value is greater than the second. 105 func (t Term) Gt(args ...interface{}) Term { 106 return constructMethodTerm(t, "Gt", p.Term_GT, args, map[string]interface{}{}) 107 } 108 109 // Gt returns true if the first value is greater than the second. 110 func Gt(args ...interface{}) Term { 111 return constructRootTerm("Gt", p.Term_GT, args, map[string]interface{}{}) 112 } 113 114 // Ge returns true if the first value is greater than or equal to the second. 115 func (t Term) Ge(args ...interface{}) Term { 116 return constructMethodTerm(t, "Ge", p.Term_GE, args, map[string]interface{}{}) 117 } 118 119 // Ge returns true if the first value is greater than or equal to the second. 120 func Ge(args ...interface{}) Term { 121 return constructRootTerm("Ge", p.Term_GE, args, map[string]interface{}{}) 122 } 123 124 // Lt returns true if the first value is less than the second. 125 func (t Term) Lt(args ...interface{}) Term { 126 return constructMethodTerm(t, "Lt", p.Term_LT, args, map[string]interface{}{}) 127 } 128 129 // Lt returns true if the first value is less than the second. 130 func Lt(args ...interface{}) Term { 131 return constructRootTerm("Lt", p.Term_LT, args, map[string]interface{}{}) 132 } 133 134 // Le returns true if the first value is less than or equal to the second. 135 func (t Term) Le(args ...interface{}) Term { 136 return constructMethodTerm(t, "Le", p.Term_LE, args, map[string]interface{}{}) 137 } 138 139 // Le returns true if the first value is less than or equal to the second. 140 func Le(args ...interface{}) Term { 141 return constructRootTerm("Le", p.Term_LE, args, map[string]interface{}{}) 142 } 143 144 // Not performs a logical not on a value. 145 func (t Term) Not(args ...interface{}) Term { 146 return constructMethodTerm(t, "Not", p.Term_NOT, args, map[string]interface{}{}) 147 } 148 149 // Not performs a logical not on a value. 150 func Not(args ...interface{}) Term { 151 return constructRootTerm("Not", p.Term_NOT, args, map[string]interface{}{}) 152 } 153 154 // RandomOpts contains the optional arguments for the Random term. 155 type RandomOpts struct { 156 Float interface{} `rethinkdb:"float,omitempty"` 157 } 158 159 func (o RandomOpts) toMap() map[string]interface{} { 160 return optArgsToMap(o) 161 } 162 163 // Random generates a random number between given (or implied) bounds. Random 164 // takes zero, one or two arguments. 165 // 166 // With zero arguments, the result will be a floating-point number in the range 167 // [0,1). 168 // 169 // With one argument x, the result will be in the range [0,x), and will be an 170 // integer unless the Float option is set to true. Specifying a floating point 171 // number without the Float option will raise an error. 172 // 173 // With two arguments x and y, the result will be in the range [x,y), and will 174 // be an integer unless the Float option is set to true. If x and y are equal an 175 // error will occur, unless the floating-point option has been specified, in 176 // which case x will be returned. Specifying a floating point number without the 177 // float option will raise an error. 178 // 179 // Note: Any integer responses can be be coerced to floating-points, when 180 // unmarshaling to a Go floating-point type. The last argument given will always 181 // be the ‘open’ side of the range, but when generating a floating-point 182 // number, the ‘open’ side may be less than the ‘connClosed’ side. 183 func Random(args ...interface{}) Term { 184 var opts = map[string]interface{}{} 185 186 // Look for options map 187 if len(args) > 0 { 188 if possibleOpts, ok := args[len(args)-1].(RandomOpts); ok { 189 opts = possibleOpts.toMap() 190 args = args[:len(args)-1] 191 } 192 } 193 194 return constructRootTerm("Random", p.Term_RANDOM, args, opts) 195 } 196 197 // Round causes the input number to be rounded the given value to the nearest whole integer. 198 func (t Term) Round(args ...interface{}) Term { 199 return constructMethodTerm(t, "Round", p.Term_ROUND, args, map[string]interface{}{}) 200 } 201 202 // Round causes the input number to be rounded the given value to the nearest whole integer. 203 func Round(args ...interface{}) Term { 204 return constructRootTerm("Round", p.Term_ROUND, args, map[string]interface{}{}) 205 } 206 207 // Ceil rounds the given value up, returning the smallest integer value greater 208 // than or equal to the given value (the value’s ceiling). 209 func (t Term) Ceil(args ...interface{}) Term { 210 return constructMethodTerm(t, "Ceil", p.Term_CEIL, args, map[string]interface{}{}) 211 } 212 213 // Ceil rounds the given value up, returning the smallest integer value greater 214 // than or equal to the given value (the value’s ceiling). 215 func Ceil(args ...interface{}) Term { 216 return constructRootTerm("Ceil", p.Term_CEIL, args, map[string]interface{}{}) 217 } 218 219 // Floor rounds the given value down, returning the largest integer value less 220 // than or equal to the given value (the value’s floor). 221 func (t Term) Floor(args ...interface{}) Term { 222 return constructMethodTerm(t, "Floor", p.Term_FLOOR, args, map[string]interface{}{}) 223 } 224 225 // Floor rounds the given value down, returning the largest integer value less 226 // than or equal to the given value (the value’s floor). 227 func Floor(args ...interface{}) Term { 228 return constructRootTerm("Floor", p.Term_FLOOR, args, map[string]interface{}{}) 229 }