rethinkdb 1.6.0.0 → 1.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/lib/func.rb +5 -4
  2. data/lib/net.rb +14 -8
  3. data/lib/ql2.pb.rb +207 -732
  4. data/lib/rethinkdb.rb +2 -19
  5. data/lib/rpp.rb +5 -1
  6. data/lib/shim.rb +40 -13
  7. metadata +7 -7
data/lib/func.rb CHANGED
@@ -37,6 +37,7 @@ module RethinkDB
37
37
  :js => :javascript,
38
38
  :type_of => :typeof
39
39
  }
40
+ @@allow_json = {:insert => true}
40
41
  def method_missing(m, *a, &b)
41
42
  unbound_if(m.to_s.downcase != m.to_s, m)
42
43
  bitop = [:"|", :"&"].include?(m) ? [m, a, b] : nil
@@ -54,7 +55,7 @@ module RethinkDB
54
55
  end
55
56
 
56
57
  m = @@rewrites[m] || m
57
- termtype = Term::TermType.values[m.to_s.upcase.to_sym]
58
+ termtype = Term::TermType.const_get(m.to_s.upcase)
58
59
  unbound_if(!termtype, m)
59
60
 
60
61
  if (opt_offset = @@optarg_offsets[m])
@@ -73,11 +74,11 @@ module RethinkDB
73
74
 
74
75
  t = Term.new
75
76
  t.type = termtype
76
- t.args = args.map{|x| RQL.new.expr(x).to_pb}
77
+ t.args = args.map{|x| RQL.new.expr(x, :allow_json => @@allow_json[m]).to_pb}
77
78
  t.optargs = (optargs || {}).map {|k,v|
78
79
  ap = Term::AssocPair.new
79
80
  ap.key = k.to_s
80
- ap.val = RQL.new.expr(v).to_pb
81
+ ap.val = RQL.new.expr(v, :allow_json => @@allow_json[m]).to_pb
81
82
  ap
82
83
  }
83
84
  return RQL.new(t, bitop)
@@ -127,7 +128,7 @@ module RethinkDB
127
128
  if ind.class == Fixnum
128
129
  return nth(ind)
129
130
  elsif ind.class == Symbol || ind.class == String
130
- return getattr(ind)
131
+ return get_field(ind)
131
132
  elsif ind.class == Range
132
133
  if ind.end == 0 && ind.exclude_end?
133
134
  raise ArgumentError, "Cannot slice to an excluded end of 0."
data/lib/net.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright 2010-2012 RethinkDB, all rights reserved.
2
2
  require 'socket'
3
3
  require 'thread'
4
+ require 'timeout'
4
5
 
5
6
  # $f = File.open("fuzz_seed.rb", "w")
6
7
 
@@ -213,12 +214,17 @@ module RethinkDB
213
214
 
214
215
  def start_listener
215
216
  class << @socket
216
- def read_exn(len)
217
- buf = read len
218
- if !buf or buf.length != len
219
- raise RqlRuntimeError, "Connection closed by server."
220
- end
221
- return buf
217
+ def maybe_timeout(sec=nil, &b)
218
+ sec ? timeout(sec, &b) : b.call
219
+ end
220
+ def read_exn(len, timeout_sec=nil)
221
+ maybe_timeout(timeout_sec) {
222
+ buf = read len
223
+ if !buf or buf.length != len
224
+ raise RqlRuntimeError, "Connection closed by server."
225
+ end
226
+ return buf
227
+ }
222
228
  end
223
229
  end
224
230
  @socket.write([@@magic_number].pack('L<'))
@@ -226,7 +232,7 @@ module RethinkDB
226
232
  @socket.write([@auth_key.size].pack('L<') + @auth_key)
227
233
  response = ""
228
234
  while response[-1..-1] != "\0"
229
- response += @socket.read_exn(1)
235
+ response += @socket.read_exn(1, 20)
230
236
  end
231
237
  response = response[0...-1]
232
238
  if response != "SUCCESS"
@@ -249,7 +255,7 @@ module RethinkDB
249
255
  end
250
256
  #TODO: Recovery
251
257
  begin
252
- protob = Response.new.parse_from_string(response)
258
+ protob = Response.parse(response)
253
259
  rescue
254
260
  raise RqlRuntimeError, "Bad Protobuf #{response}, server is buggy."
255
261
  end
data/lib/ql2.pb.rb CHANGED
@@ -1,756 +1,231 @@
1
- ### Generated by rprotoc. DO NOT EDIT!
2
- ### <proto file: ../../src/rdb_protocol/ql2.proto>
3
- # ////////////////////////////////////////////////////////////////////////////////
4
- # // THE HIGH-LEVEL VIEW //
5
- # ////////////////////////////////////////////////////////////////////////////////
6
- #
7
- # // Process: When you first open a connection, send the magic number
8
- # // for the version of the protobuf you're targetting (in the [Version]
9
- # // enum). This should **NOT** be sent as a protobuf; just send the
10
- # // little-endian 32-bit integer over the wire raw. This number should
11
- # // only be sent once per connection.
12
- #
13
- # // The magic number shall be followed by an authorization key. The
14
- # // first 4 bytes are the length of the key to be sent as a little-endian
15
- # // 32-bit integer, followed by the key string. Even if there is no key,
16
- # // an empty string should be sent (length 0 and no data). The server will
17
- # // then respond with a NULL-terminated string response. "SUCCESS" indicates
18
- # // that the connection has been accepted. Any other response indicates an
19
- # // error, and the response string should describe the error.
20
- #
21
- # // Next, for each query you want to send, construct a [Query] protobuf
22
- # // and serialize it to a binary blob. Send the blob's size to the
23
- # // server encoded as a little-endian 32-bit integer, followed by the
24
- # // blob itself. You will recieve a [Response] protobuf back preceded
25
- # // by its own size, once again encoded as a little-endian 32-bit
26
- # // integer. You can see an example exchange below in **EXAMPLE**.
27
- #
28
- # // A query consists of a [Term] to evaluate and a unique-per-connection
29
- # // [token].
30
- #
31
- # // Tokens are used for two things:
32
- # // * Keeping track of which responses correspond to which queries.
33
- # // * Batched queries. Some queries return lots of results, so we send back
34
- # // batches of <1000, and you need to send a [CONTINUE] query with the same
35
- # // token to get more results from the original query.
36
- # ////////////////////////////////////////////////////////////////////////////////
37
- #
38
- # // This enum contains the magic numbers for your version. See **THE HIGH-LEVEL
39
- # // VIEW** for what to do with it.
40
- # message VersionDummy { // We need to wrap it like this for some
41
- # // non-conforming protobuf libraries
42
- # enum Version {
43
- # V0_1 = 0x3f61ba36;
44
- # V0_2 = 0x723081e1;
45
- # }
46
- # }
47
- #
48
- # // You send one of:
49
- # // * A [START] query with a [Term] to evaluate and a unique-per-connection token.
50
- # // * A [CONTINUE] query with the same token as a [START] query that returned
51
- # // [SUCCESS_PARTIAL] in its [Response].
52
- # // * A [STOP] query with the same token as a [START] query that you want to stop.
53
- # message Query {
54
- # enum QueryType {
55
- # START = 1; // Start a new query.
56
- # CONTINUE = 2; // Continue a query that returned [SUCCESS_PARTIAL]
57
- # // (see [Response]).
58
- # STOP = 3; // Stop a query partway through executing.
59
- # }
60
- # optional QueryType type = 1;
61
- # // A [Term] is how we represent the operations we want a query to perform.
62
- # optional Term query = 2; // only present when [type] = [START]
63
- # optional int64 token = 3;
64
- # // This flag is ignored on the server. `noreply` should be added
65
- # // to `global_optargs` instead (the key "noreply" should map to
66
- # // either true or false).
67
- # optional bool OBSOLETE_noreply = 4 [default = false];
68
- #
69
- # message AssocPair {
70
- # optional string key = 1;
71
- # optional Term val = 2;
72
- # }
73
- # repeated AssocPair global_optargs = 6;
74
- # }
75
- #
76
- # // A backtrace frame (see `backtrace` in Response below)
77
- # message Frame {
78
- # enum FrameType {
79
- # POS = 1; // Error occured in a positional argument.
80
- # OPT = 2; // Error occured in an optional argument.
81
- # }
82
- # optional FrameType type = 1;
83
- # optional int64 pos = 2; // The index of the positional argument.
84
- # optional string opt = 3; // The name of the optional argument.
85
- # }
86
- # message Backtrace {
87
- # repeated Frame frames = 1;
88
- # }
89
- #
90
- # // You get back a response with the same [token] as your query.
91
- # message Response {
92
- # enum ResponseType {
93
- # // These response types indicate success.
94
- # SUCCESS_ATOM = 1; // Query returned a single RQL datatype.
95
- # SUCCESS_SEQUENCE = 2; // Query returned a sequence of RQL datatypes.
96
- # SUCCESS_PARTIAL = 3; // Query returned a partial sequence of RQL
97
- # // datatypes. If you send a [CONTINUE] query with
98
- # // the same token as this response, you will get
99
- # // more of the sequence. Keep sending [CONTINUE]
100
- # // queries until you get back [SUCCESS_SEQUENCE].
101
- #
102
- # // These response types indicate failure.
103
- # CLIENT_ERROR = 16; // Means the client is buggy. An example is if the
104
- # // client sends a malformed protobuf, or tries to
105
- # // send [CONTINUE] for an unknown token.
106
- # COMPILE_ERROR = 17; // Means the query failed during parsing or type
107
- # // checking. For example, if you pass too many
108
- # // arguments to a function.
109
- # RUNTIME_ERROR = 18; // Means the query failed at runtime. An example is
110
- # // if you add together two values from a table, but
111
- # // they turn out at runtime to be booleans rather
112
- # // than numbers.
113
- # }
114
- # optional ResponseType type = 1;
115
- # optional int64 token = 2; // Indicates what [Query] this response corresponds to.
116
- #
117
- # // [response] contains 1 RQL datum if [type] is [SUCCESS_ATOM], or many RQL
118
- # // data if [type] is [SUCCESS_SEQUENCE] or [SUCCESS_PARTIAL]. It contains 1
119
- # // error message (of type [R_STR]) in all other cases.
120
- # repeated Datum response = 3;
121
- #
122
- # // If [type] is [CLIENT_ERROR], [TYPE_ERROR], or [RUNTIME_ERROR], then a
123
- # // backtrace will be provided. The backtrace says where in the query the
124
- # // error occured. Ideally this information will be presented to the user as
125
- # // a pretty-printed version of their query with the erroneous section
126
- # // underlined. A backtrace is a series of 0 or more [Frame]s, each of which
127
- # // specifies either the index of a positional argument or the name of an
128
- # // optional argument. (Those words will make more sense if you look at the
129
- # // [Term] message below.)
130
- #
131
- # optional Backtrace backtrace = 4; // Contains n [Frame]s when you get back an error.
132
- # }
133
- #
134
- # // A [Datum] is a chunk of data that can be serialized to disk or returned to
135
- # // the user in a Response. Currently we only support JSON types, but we may
136
- # // support other types in the future (e.g., a date type or an integer type).
137
- # message Datum {
138
- # enum DatumType {
139
- # R_NULL = 1;
140
- # R_BOOL = 2;
141
- # R_NUM = 3; // a double
142
- # R_STR = 4;
143
- # R_ARRAY = 5;
144
- # R_OBJECT = 6;
145
- # }
146
- # optional DatumType type = 1;
147
- # optional bool r_bool = 2;
148
- # optional double r_num = 3;
149
- # optional string r_str = 4;
150
- #
151
- # repeated Datum r_array = 5;
152
- # message AssocPair {
153
- # optional string key = 1;
154
- # optional Datum val = 2;
155
- # }
156
- # repeated AssocPair r_object = 6;
157
- #
158
- # extensions 10000 to 20000;
159
- # }
160
- #
161
- # // A [Term] is either a piece of data (see **Datum** above), or an operator and
162
- # // its operands. If you have a [Datum], it's stored in the member [datum]. If
163
- # // you have an operator, its positional arguments are stored in [args] and its
164
- # // optional arguments are stored in [optargs].
165
- # //
166
- # // A note about type signatures:
167
- # // We use the following notation to denote types:
168
- # // arg1_type, arg2_type, argrest_type... -> result_type
169
- # // So, for example, if we have a function `avg` that takes any number of
170
- # // arguments and averages them, we might write:
171
- # // NUMBER... -> NUMBER
172
- # // Or if we had a function that took one number modulo another:
173
- # // NUMBER, NUMBER -> NUMBER
174
- # // Or a function that takes a table and a primary key of any Datum type, then
175
- # // retrieves the entry with that primary key:
176
- # // Table, DATUM -> OBJECT
177
- # // Some arguments must be provided as literal values (and not the results of sub
178
- # // terms). These are marked with a `!`.
179
- # // Optional arguments are specified within curly braces as argname `:` value
180
- # // type (e.x `{use_outdated:BOOL}`)
181
- # // Many RQL operations are polymorphic. For these, alterantive type signatures
182
- # // are separated by `|`.
183
- # //
184
- # // The RQL type hierarchy is as follows:
185
- # // Top
186
- # // DATUM
187
- # // NULL
188
- # // BOOL
189
- # // NUMBER
190
- # // STRING
191
- # // OBJECT
192
- # // SingleSelection
193
- # // ARRAY
194
- # // Sequence
195
- # // ARRAY
196
- # // Stream
197
- # // StreamSelection
198
- # // Table
199
- # // Database
200
- # // Function
201
- # // Ordering - used only by ORDER_BY
202
- # // Error
203
- # message Term {
204
- # enum TermType {
205
- # // A RQL datum, stored in `datum` below.
206
- # DATUM = 1;
207
- #
208
- # MAKE_ARRAY = 2; // DATUM... -> ARRAY
209
- # // Evaluate the terms in [optargs] and make an object
210
- # MAKE_OBJ = 3; // {...} -> OBJECT
211
- #
212
- # // * Compound types
213
- # // Takes an integer representing a variable and returns the value stored
214
- # // in that variable. It's the responsibility of the client to translate
215
- # // from their local representation of a variable to a unique integer for
216
- # // that variable. (We do it this way instead of letting clients provide
217
- # // variable names as strings to discourage variable-capturing client
218
- # // libraries, and because it's more efficient on the wire.)
219
- # VAR = 10; // !NUMBER -> DATUM
220
- # // Takes some javascript code and executes it.
221
- # JAVASCRIPT = 11; // STRING {timeout: !NUMBER} -> DATUM |
222
- # // STRING {timeout: !NUMBER} -> Function(*)
223
- #
224
- # // Takes a string and throws an error with that message.
225
- # // Inside of a `default` block, you can omit the first
226
- # // argument to rethrow whatever error you catch (this is most
227
- # // useful as an argument to the `default` filter optarg).
228
- # ERROR = 12; // STRING -> Error | -> Error
229
- # // Takes nothing and returns a reference to the implicit variable.
230
- # IMPLICIT_VAR = 13; // -> DATUM
231
- #
232
- # // * Data Operators
233
- # // Returns a reference to a database.
234
- # DB = 14; // STRING -> Database
235
- # // Returns a reference to a table.
236
- # TABLE = 15; // Database, STRING, {use_outdated:BOOL} -> Table | STRING, {use_outdated:BOOL} -> Table
237
- # // Gets a single element from a table by its primary or a secondary key.
238
- # GET = 16; // Table, STRING -> SingleSelection | Table, NUMBER -> SingleSelection |
239
- # // Table, STRING -> NULL | Table, NUMBER -> NULL |
240
- # GET_ALL = 78; // Table, JSON {index:!STRING} => ARRAY
241
- #
242
- # // Simple DATUM Ops
243
- # EQ = 17; // DATUM... -> BOOL
244
- # NE = 18; // DATUM... -> BOOL
245
- # LT = 19; // DATUM... -> BOOL
246
- # LE = 20; // DATUM... -> BOOL
247
- # GT = 21; // DATUM... -> BOOL
248
- # GE = 22; // DATUM... -> BOOL
249
- # NOT = 23; // BOOL -> BOOL
250
- # // ADD can either add two numbers or concatenate two arrays.
251
- # ADD = 24; // NUMBER... -> NUMBER | STRING... -> STRING
252
- # SUB = 25; // NUMBER... -> NUMBER
253
- # MUL = 26; // NUMBER... -> NUMBER
254
- # DIV = 27; // NUMBER... -> NUMBER
255
- # MOD = 28; // NUMBER, NUMBER -> NUMBER
256
- #
257
- # // DATUM Array Ops
258
- # // Append a single element to the end of an array (like `snoc`).
259
- # APPEND = 29; // ARRAY, DATUM -> ARRAY
260
- # // Prepend a single element to the end of an array (like `cons`).
261
- # PREPEND = 80; // ARRAY, DATUM -> ARRAY
262
- # //Remove the elements of one array from another array.
263
- # DIFFERENCE = 95; // ARRAY, ARRAY -> ARRAY
264
- #
265
- # // DATUM Set Ops
266
- # // Set ops work on arrays. They don't use actual sets and thus have
267
- # // performance characteristics you would expect from arrays rather than
268
- # // from sets. All set operations have the post condition that they
269
- # // array they return contains no duplicate values.
270
- # SET_INSERT = 88; // ARRAY, DATUM -> ARRAY
271
- # SET_INTERSECTION = 89; // ARRAY, ARRAY -> ARRAY
272
- # SET_UNION = 90; // ARRAY, ARRAY -> ARRAY
273
- # SET_DIFFERENCE = 91; // ARRAY, ARRAY -> ARRAY
274
- #
275
- # SLICE = 30; // Sequence, NUMBER, NUMBER -> Sequence
276
- # SKIP = 70; // Sequence, NUMBER -> Sequence
277
- # LIMIT = 71; // Sequence, NUMBER -> Sequence
278
- # INDEXES_OF = 87; // Sequence, DATUM -> Sequence | Sequence, Function(1) -> Sequence
279
- # CONTAINS = 93; // Sequence, DATUM -> BOOL
280
- #
281
- # // Stream/Object Ops
282
- # // Get a particular attribute out of an object, or map that over a
283
- # // sequence.
284
- # GETATTR = 31; // OBJECT, STRING -> DATUM
285
- # // Return an array containing the keys of the object.
286
- # KEYS = 94; // OBJECT -> ARRAY
287
- # // Check whether an object contains all the specified fields,
288
- # // or filters a sequence so that all objects inside of it
289
- # // contain all the specified fields.
290
- # HAS_FIELDS = 32; // OBJECT, STRING... -> BOOL
291
- # // x.with_fields(...) <=> x.has_fields(...).pluck(...)
292
- # WITH_FIELDS = 96; // Sequence, STRING... -> Sequence
293
- # // Get a subset of an object by selecting some attributes to preserve,
294
- # // or map that over a sequence. (Both pick and pluck, polymorphic.)
295
- # PLUCK = 33; // Sequence, STRING... -> Sequence | OBJECT, STRING... -> OBJECT
296
- # // Get a subset of an object by selecting some attributes to discard, or
297
- # // map that over a sequence. (Both unpick and without, polymorphic.)
298
- # WITHOUT = 34; // Sequence, STRING... -> Sequence | OBJECT, STRING... -> OBJECT
299
- # // Merge objects (right-preferential)
300
- # MERGE = 35; // OBJECT... -> OBJECT | Sequence -> Sequence
301
- #
302
- # // Sequence Ops
303
- # // Get all elements of a sequence between two values.
304
- # BETWEEN = 36; // StreamSelection, DATUM, DATUM, {:index:!STRING} -> StreamSelection
305
- # REDUCE = 37; // Sequence, Function(2), {base:DATUM} -> DATUM
306
- # MAP = 38; // Sequence, Function(1) -> Sequence
307
- #
308
- # // Filter a sequence with either a function or a shortcut
309
- # // object (see API docs for details). The body of FILTER is
310
- # // wrapped in an implicit `.default(false)`, and you can
311
- # // change the default value by specifying the `default`
312
- # // optarg. If you make the default `r.error`, all errors
313
- # // caught by `default` will be rethrown as if the `default`
314
- # // did not exist.
315
- # FILTER = 39; // Sequence, Function(1), {default:DATUM} -> Sequence |
316
- # // Sequence, OBJECT, {default:DATUM} -> Sequence
317
- # // Map a function over a sequence and then concatenate the results together.
318
- # CONCATMAP = 40; // Sequence, Function(1) -> Sequence
319
- # // Order a sequence based on one or more attributes.
320
- # ORDERBY = 41; // Sequence, (!STRING | Ordering)... -> Sequence
321
- # // Get all distinct elements of a sequence (like `uniq`).
322
- # DISTINCT = 42; // Sequence -> Sequence
323
- # // Count the number of elements in a sequence, or only the elements that match
324
- # // a given filter.
325
- # COUNT = 43; // Sequence -> NUMBER | Sequence, DATUM -> NUMBER | Sequence, Function(1) -> NUMBER
326
- # IS_EMPTY = 86; // Sequence -> BOOL
327
- # // Take the union of multiple sequences (preserves duplicate elements! (use distinct)).
328
- # UNION = 44; // Sequence... -> Sequence
329
- # // Get the Nth element of a sequence.
330
- # NTH = 45; // Sequence, NUMBER -> DATUM
331
- # // Takes a sequence, and three functions:
332
- # // - A function to group the sequence by.
333
- # // - A function to map over the groups.
334
- # // - A reduction to apply to each of the groups.
335
- # GROUPED_MAP_REDUCE = 46; // Sequence, Function(1), Function(1), Function(2), {base:DATUM} -> ARRAY
336
- # // Groups a sequence by one or more attributes, and then applies a reduction.
337
- # // The third argument is a special object literal giving the kind of operation to be
338
- # // performed and any necessary arguments.
339
- # // At present, GROUPBY suports the following operations
340
- # // * {'COUNT': <ignored>} - count the size of the group
341
- # // * {'SUM': attr} - sum the values of the given attribute across the group
342
- # // * {'AVG': attr} - average the values of the given attribute across the group
343
- # GROUPBY = 47; // Sequence, ARRAY, !GROUP_BY_OBJECT -> Sequence
344
- # INNER_JOIN = 48; // Sequence, Sequence, Function(2) -> Sequence
345
- # OUTER_JOIN = 49; // Sequence, Sequence, Function(2) -> Sequence
346
- # // An inner-join that does an equality comparison on two attributes.
347
- # EQ_JOIN = 50; // Sequence, !STRING, Sequence, {index:!STRING} -> Sequence
348
- # ZIP = 72; // Sequence -> Sequence
349
- #
350
- # // Array Ops
351
- # // Insert an element in to an array at a given index.
352
- # INSERT_AT = 82; // ARRAY, NUMBER, DATUM -> ARRAY
353
- # // Remove an element at a given index from an array.
354
- # DELETE_AT = 83; // ARRAY, NUMBER -> ARRAY |
355
- # // ARRAY, NUMBER, NUMBER -> ARRAY
356
- # // Change the element at a given index of an array.
357
- # CHANGE_AT = 84; // ARRAY, NUMBER, DATUM -> ARRAY
358
- # // Splice one array in to another array.
359
- # SPLICE_AT = 85; // ARRAY, NUMBER, ARRAY -> ARRAY
360
- #
361
- # // * Type Ops
362
- # // Coerces a datum to a named type (e.g. "bool").
363
- # // If you previously used `stream_to_array`, you should use this instead
364
- # // with the type "array".
365
- # COERCE_TO = 51; // Top, STRING -> Top
366
- # // Returns the named type of a datum (e.g. TYPEOF(true) = "BOOL")
367
- # TYPEOF = 52; // Top -> STRING
368
- #
369
- # // * Write Ops (the OBJECTs contain data about number of errors etc.)
370
- # // Updates all the rows in a selection. Calls its Function with the row
371
- # // to be updated, and then merges the result of that call.
372
- # UPDATE = 53; // StreamSelection, Function(1), {non_atomic:BOOL} -> OBJECT |
373
- # // SingleSelection, Function(1), {non_atomic:BOOL} -> OBJECT |
374
- # // StreamSelection, OBJECT, {non_atomic:BOOL} -> OBJECT |
375
- # // SingleSelection, OBJECT, {non_atomic:BOOL} -> OBJECT
376
- # // Deletes all the rows in a selection.
377
- # DELETE = 54; // StreamSelection -> OBJECT | SingleSelection -> OBJECT
378
- # // Replaces all the rows in a selection. Calls its Function with the row
379
- # // to be replaced, and then discards it and stores the result of that
380
- # // call.
381
- # REPLACE = 55; // StreamSelection, Function(1), {non_atomic:BOOL} -> OBJECT | SingleSelection, Function(1), {non_atomic:BOOL} -> OBJECT
382
- # // Inserts into a table. If `upsert` is true, overwrites entries with
383
- # // the same primary key (otherwise errors).
384
- # INSERT = 56; // Table, OBJECT, {upsert:BOOL} -> OBJECT | Table, Sequence, {upsert:BOOL} -> OBJECT
385
- #
386
- # // * Administrative OPs
387
- # // Creates a database with a particular name.
388
- # DB_CREATE = 57; // STRING -> OBJECT
389
- # // Drops a database with a particular name.
390
- # DB_DROP = 58; // STRING -> OBJECT
391
- # // Lists all the databases by name. (Takes no arguments)
392
- # DB_LIST = 59; // -> ARRAY
393
- # // Creates a table with a particular name in a particular
394
- # // database. (You may omit the first argument to use the
395
- # // default database.)
396
- # TABLE_CREATE = 60; // Database, STRING, {datacenter:STRING, primary_key:STRING, cache_size:NUMBER, hard_durability:BOOL} -> OBJECT
397
- # // STRING, {datacenter:STRING, primary_key:STRING, cache_size:NUMBER, hard_durability:BOOL} -> OBJECT
398
- # // Drops a table with a particular name from a particular
399
- # // database. (You may omit the first argument to use the
400
- # // default database.)
401
- # TABLE_DROP = 61; // Database, STRING -> OBJECT
402
- # // STRING -> OBJECT
403
- # // Lists all the tables in a particular database. (You may
404
- # // omit the first argument to use the default database.)
405
- # TABLE_LIST = 62; // Database -> ARRAY
406
- # // -> ARRAY
407
- #
408
- # // * Secondary indexes OPs
409
- # // Creates a new secondary index with a particular name and definition.
410
- # INDEX_CREATE = 75; // Table, STRING, Function(1) -> OBJECT
411
- # // Drops a secondary index with a particular name from the specified table.
412
- # INDEX_DROP = 76; // Table, STRING -> OBJECT
413
- # // Lists all secondary indexes on a particular table.
414
- # INDEX_LIST = 77; // Table -> ARRAY
415
- #
416
- # // * Control Operators
417
- # // Calls a function on data
418
- # FUNCALL = 64; // Function(*), DATUM... -> DATUM
419
- # // Executes its first argument, and returns its second argument if it
420
- # // got [true] or its third argument if it got [false] (like an `if`
421
- # // statement).
422
- # BRANCH = 65; // BOOL, Top, Top -> Top
423
- # // Returns true if any of its arguments returns true (short-circuits).
424
- # // (Like `or` in most languages.)
425
- # ANY = 66; // BOOL... -> BOOL
426
- # // Returns true if all of its arguments return true (short-circuits).
427
- # // (Like `and` in most languages.)
428
- # ALL = 67; // BOOL... -> BOOL
429
- # // Calls its Function with each entry in the sequence
430
- # // and executes the array of terms that Function returns.
431
- # FOREACH = 68; // Sequence, Function(1) -> OBJECT
432
- #
433
- # ////////////////////////////////////////////////////////////////////////////////
434
- # ////////// Special Terms
435
- # ////////////////////////////////////////////////////////////////////////////////
436
- #
437
- # // An anonymous function. Takes an array of numbers representing
438
- # // variables (see [VAR] above), and a [Term] to execute with those in
439
- # // scope. Returns a function that may be passed an array of arguments,
440
- # // then executes the Term with those bound to the variable names. The
441
- # // user will never construct this directly. We use it internally for
442
- # // things like `map` which take a function. The "arity" of a [Function] is
443
- # // the number of arguments it takes.
444
- # // For example, here's what `_X_.map{|x| x+2}` turns into:
445
- # // Term {
446
- # // type = MAP;
447
- # // args = [_X_,
448
- # // Term {
449
- # // type = Function;
450
- # // args = [Term {
451
- # // type = DATUM;
452
- # // datum = Datum {
453
- # // type = R_ARRAY;
454
- # // r_array = [Datum { type = R_NUM; r_num = 1; }];
455
- # // };
456
- # // },
457
- # // Term {
458
- # // type = ADD;
459
- # // args = [Term {
460
- # // type = VAR;
461
- # // args = [Term {
462
- # // type = DATUM;
463
- # // datum = Datum { type = R_NUM;
464
- # // r_num = 1};
465
- # // }];
466
- # // },
467
- # // Term {
468
- # // type = DATUM;
469
- # // datum = Datum { type = R_NUM; r_num = 2; };
470
- # // }];
471
- # // }];
472
- # // }];
473
- # FUNC = 69; // ARRAY, Top -> ARRAY -> Top
474
- #
475
- # // Indicates to ORDER_BY that this attribute is to be sorted in ascending order.
476
- # ASC = 73; // !STRING -> Ordering
477
- # // Indicates to ORDER_BY that this attribute is to be sorted in descending order.
478
- # DESC = 74; // !STRING -> Ordering
479
- #
480
- # // Gets info about anything. INFO is most commonly called on tables.
481
- # INFO = 79; // Top -> OBJECT
482
- #
483
- # // `a.match(b)` returns a match object if the string `a`
484
- # // matches the regular expression `b`.
485
- # MATCH = 97; // STRING, STRING -> DATUM
486
- #
487
- # // Select a number of elements from sequence with uniform distribution.
488
- # SAMPLE = 81; // Sequence, NUMBER -> Sequence
489
- #
490
- # // Evaluates its first argument. If that argument returns
491
- # // NULL or throws an error related to the absence of an
492
- # // expected value (for instance, accessing a non-existent
493
- # // field or adding NULL to an integer), DEFAULT will either
494
- # // return its second argument or execute it if it's a
495
- # // function. If the second argument is a function, it will be
496
- # // passed either the text of the error or NULL as its
497
- # // argument.
498
- # DEFAULT = 92; // Top, Top -> Top
499
- # }
500
- # optional TermType type = 1;
501
- #
502
- # // This is only used when type is DATUM.
503
- # optional Datum datum = 2;
504
- #
505
- # repeated Term args = 3; // Holds the positional arguments of the query.
506
- # message AssocPair {
507
- # optional string key = 1;
508
- # optional Term val = 2;
509
- # }
510
- # repeated AssocPair optargs = 4; // Holds the optional arguments of the query.
511
- # // (Note that the order of the optional arguments doesn't matter; think of a
512
- # // Hash.)
513
- #
514
- # extensions 10000 to 20000;
515
- # }
516
- #
517
- # ////////////////////////////////////////////////////////////////////////////////
518
- # // EXAMPLE //
519
- # ////////////////////////////////////////////////////////////////////////////////
520
- # // ```ruby
521
- # // r.table('tbl', {:use_outdated => true}).insert([{:id => 0}, {:id => 1}])
522
- # // ```
523
- # // Would turn into:
524
- # // Term {
525
- # // type = INSERT;
526
- # // args = [Term {
527
- # // type = TABLE;
528
- # // args = [Term {
529
- # // type = DATUM;
530
- # // datum = Datum { type = R_STR; r_str = "tbl"; };
531
- # // }];
532
- # // optargs = [["use_outdated",
533
- # // Term {
534
- # // type = DATUM;
535
- # // datum = Datum { type = R_BOOL; r_bool = true; };
536
- # // }]];
537
- # // },
538
- # // Term {
539
- # // type = MAKE_ARRAY;
540
- # // args = [Term {
541
- # // type = DATUM;
542
- # // datum = Datum { type = R_OBJECT; r_object = [["id", 0]]; };
543
- # // },
544
- # // Term {
545
- # // type = DATUM;
546
- # // datum = Datum { type = R_OBJECT; r_object = [["id", 1]]; };
547
- # // }];
548
- # // }]
549
- # // }
550
- # // And the server would reply:
551
- # // Response {
552
- # // type = SUCCESS_ATOM;
553
- # // token = 1;
554
- # // response = [Datum { type = R_OBJECT; r_object = [["inserted", 2]]; }];
555
- # // }
556
- # // Or, if there were an error:
557
- # // Response {
558
- # // type = RUNTIME_ERROR;
559
- # // token = 1;
560
- # // response = [Datum { type = R_STR; r_str = "The table `tbl` doesn't exist!"; }];
561
- # // backtrace = [Frame { type = POS; pos = 0; }, Frame { type = POS; pos = 0; }];
562
- # // }
1
+ #!/usr/bin/env ruby
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
563
3
 
564
- require 'protobuf/message/message'
565
- require 'protobuf/message/enum'
566
- require 'protobuf/message/service'
567
- require 'protobuf/message/extend'
4
+ require 'protocol_buffers'
568
5
 
569
- class VersionDummy < ::Protobuf::Message
570
- defined_in __FILE__
571
- class Version < ::Protobuf::Enum
572
- defined_in __FILE__
573
- V0_1 = value(:V0_1, 1063369270)
574
- V0_2 = value(:V0_2, 1915781601)
6
+ # forward declarations
7
+ class VersionDummy < ::ProtocolBuffers::Message; end
8
+ class Query < ::ProtocolBuffers::Message; end
9
+ class Frame < ::ProtocolBuffers::Message; end
10
+ class Backtrace < ::ProtocolBuffers::Message; end
11
+ class Response < ::ProtocolBuffers::Message; end
12
+ class Datum < ::ProtocolBuffers::Message; end
13
+ class Term < ::ProtocolBuffers::Message; end
14
+
15
+ class VersionDummy < ::ProtocolBuffers::Message
16
+ # forward declarations
17
+
18
+ # enums
19
+ module Version
20
+ include ::ProtocolBuffers::Enum
21
+ V0_1 = 1063369270
22
+ V0_2 = 1915781601
575
23
  end
24
+
576
25
  end
577
- class Query < ::Protobuf::Message
578
- defined_in __FILE__
579
- class QueryType < ::Protobuf::Enum
580
- defined_in __FILE__
581
- START = value(:START, 1)
582
- CONTINUE = value(:CONTINUE, 2)
583
- STOP = value(:STOP, 3)
26
+
27
+ class Query < ::ProtocolBuffers::Message
28
+ # forward declarations
29
+ class AssocPair < ::ProtocolBuffers::Message; end
30
+
31
+ # enums
32
+ module QueryType
33
+ include ::ProtocolBuffers::Enum
34
+ START = 1
35
+ CONTINUE = 2
36
+ STOP = 3
584
37
  end
585
- optional :QueryType, :type, 1
586
- optional :Term, :query, 2
587
- optional :int64, :token, 3
588
- optional :bool, :OBSOLETE_noreply, 4, :default => false
589
- class AssocPair < ::Protobuf::Message
590
- defined_in __FILE__
38
+
39
+ # nested messages
40
+ class AssocPair < ::ProtocolBuffers::Message
591
41
  optional :string, :key, 1
592
- optional :Term, :val, 2
42
+ optional ::Term, :val, 2
593
43
  end
594
- repeated :AssocPair, :global_optargs, 6
44
+
45
+ optional ::Query::QueryType, :type, 1
46
+ optional ::Term, :query, 2
47
+ optional :int64, :token, 3
48
+ optional :bool, :OBSOLETE_noreply, 4, :default => false
49
+ repeated ::Query::AssocPair, :global_optargs, 6
595
50
  end
596
- class Frame < ::Protobuf::Message
597
- defined_in __FILE__
598
- class FrameType < ::Protobuf::Enum
599
- defined_in __FILE__
600
- POS = value(:POS, 1)
601
- OPT = value(:OPT, 2)
51
+
52
+ class Frame < ::ProtocolBuffers::Message
53
+ # forward declarations
54
+
55
+ # enums
56
+ module FrameType
57
+ include ::ProtocolBuffers::Enum
58
+ POS = 1
59
+ OPT = 2
602
60
  end
603
- optional :FrameType, :type, 1
61
+
62
+ optional ::Frame::FrameType, :type, 1
604
63
  optional :int64, :pos, 2
605
64
  optional :string, :opt, 3
606
65
  end
607
- class Backtrace < ::Protobuf::Message
608
- defined_in __FILE__
609
- repeated :Frame, :frames, 1
66
+
67
+ class Backtrace < ::ProtocolBuffers::Message
68
+ repeated ::Frame, :frames, 1
610
69
  end
611
- class Response < ::Protobuf::Message
612
- defined_in __FILE__
613
- class ResponseType < ::Protobuf::Enum
614
- defined_in __FILE__
615
- SUCCESS_ATOM = value(:SUCCESS_ATOM, 1)
616
- SUCCESS_SEQUENCE = value(:SUCCESS_SEQUENCE, 2)
617
- SUCCESS_PARTIAL = value(:SUCCESS_PARTIAL, 3)
618
- CLIENT_ERROR = value(:CLIENT_ERROR, 16)
619
- COMPILE_ERROR = value(:COMPILE_ERROR, 17)
620
- RUNTIME_ERROR = value(:RUNTIME_ERROR, 18)
70
+
71
+ class Response < ::ProtocolBuffers::Message
72
+ # forward declarations
73
+
74
+ # enums
75
+ module ResponseType
76
+ include ::ProtocolBuffers::Enum
77
+ SUCCESS_ATOM = 1
78
+ SUCCESS_SEQUENCE = 2
79
+ SUCCESS_PARTIAL = 3
80
+ CLIENT_ERROR = 16
81
+ COMPILE_ERROR = 17
82
+ RUNTIME_ERROR = 18
621
83
  end
622
- optional :ResponseType, :type, 1
84
+
85
+ optional ::Response::ResponseType, :type, 1
623
86
  optional :int64, :token, 2
624
- repeated :Datum, :response, 3
625
- optional :Backtrace, :backtrace, 4
87
+ repeated ::Datum, :response, 3
88
+ optional ::Backtrace, :backtrace, 4
626
89
  end
627
- class Datum < ::Protobuf::Message
628
- defined_in __FILE__
629
- class DatumType < ::Protobuf::Enum
630
- defined_in __FILE__
631
- R_NULL = value(:R_NULL, 1)
632
- R_BOOL = value(:R_BOOL, 2)
633
- R_NUM = value(:R_NUM, 3)
634
- R_STR = value(:R_STR, 4)
635
- R_ARRAY = value(:R_ARRAY, 5)
636
- R_OBJECT = value(:R_OBJECT, 6)
90
+
91
+ class Datum < ::ProtocolBuffers::Message
92
+ # forward declarations
93
+ class AssocPair < ::ProtocolBuffers::Message; end
94
+
95
+ # enums
96
+ module DatumType
97
+ include ::ProtocolBuffers::Enum
98
+ R_NULL = 1
99
+ R_BOOL = 2
100
+ R_NUM = 3
101
+ R_STR = 4
102
+ R_ARRAY = 5
103
+ R_OBJECT = 6
637
104
  end
638
- optional :DatumType, :type, 1
105
+
106
+ # nested messages
107
+ class AssocPair < ::ProtocolBuffers::Message
108
+ optional :string, :key, 1
109
+ optional ::Datum, :val, 2
110
+ end
111
+
112
+ optional ::Datum::DatumType, :type, 1
639
113
  optional :bool, :r_bool, 2
640
114
  optional :double, :r_num, 3
641
115
  optional :string, :r_str, 4
642
- repeated :Datum, :r_array, 5
643
- class AssocPair < ::Protobuf::Message
644
- defined_in __FILE__
645
- optional :string, :key, 1
646
- optional :Datum, :val, 2
647
- end
648
- repeated :AssocPair, :r_object, 6
649
- extensions 10000..20000
116
+ repeated ::Datum, :r_array, 5
117
+ repeated ::Datum::AssocPair, :r_object, 6
650
118
  end
651
- class Term < ::Protobuf::Message
652
- defined_in __FILE__
653
- class TermType < ::Protobuf::Enum
654
- defined_in __FILE__
655
- DATUM = value(:DATUM, 1)
656
- MAKE_ARRAY = value(:MAKE_ARRAY, 2)
657
- MAKE_OBJ = value(:MAKE_OBJ, 3)
658
- VAR = value(:VAR, 10)
659
- JAVASCRIPT = value(:JAVASCRIPT, 11)
660
- ERROR = value(:ERROR, 12)
661
- IMPLICIT_VAR = value(:IMPLICIT_VAR, 13)
662
- DB = value(:DB, 14)
663
- TABLE = value(:TABLE, 15)
664
- GET = value(:GET, 16)
665
- GET_ALL = value(:GET_ALL, 78)
666
- EQ = value(:EQ, 17)
667
- NE = value(:NE, 18)
668
- LT = value(:LT, 19)
669
- LE = value(:LE, 20)
670
- GT = value(:GT, 21)
671
- GE = value(:GE, 22)
672
- NOT = value(:NOT, 23)
673
- ADD = value(:ADD, 24)
674
- SUB = value(:SUB, 25)
675
- MUL = value(:MUL, 26)
676
- DIV = value(:DIV, 27)
677
- MOD = value(:MOD, 28)
678
- APPEND = value(:APPEND, 29)
679
- PREPEND = value(:PREPEND, 80)
680
- DIFFERENCE = value(:DIFFERENCE, 95)
681
- SET_INSERT = value(:SET_INSERT, 88)
682
- SET_INTERSECTION = value(:SET_INTERSECTION, 89)
683
- SET_UNION = value(:SET_UNION, 90)
684
- SET_DIFFERENCE = value(:SET_DIFFERENCE, 91)
685
- SLICE = value(:SLICE, 30)
686
- SKIP = value(:SKIP, 70)
687
- LIMIT = value(:LIMIT, 71)
688
- INDEXES_OF = value(:INDEXES_OF, 87)
689
- CONTAINS = value(:CONTAINS, 93)
690
- GETATTR = value(:GETATTR, 31)
691
- KEYS = value(:KEYS, 94)
692
- HAS_FIELDS = value(:HAS_FIELDS, 32)
693
- WITH_FIELDS = value(:WITH_FIELDS, 96)
694
- PLUCK = value(:PLUCK, 33)
695
- WITHOUT = value(:WITHOUT, 34)
696
- MERGE = value(:MERGE, 35)
697
- BETWEEN = value(:BETWEEN, 36)
698
- REDUCE = value(:REDUCE, 37)
699
- MAP = value(:MAP, 38)
700
- FILTER = value(:FILTER, 39)
701
- CONCATMAP = value(:CONCATMAP, 40)
702
- ORDERBY = value(:ORDERBY, 41)
703
- DISTINCT = value(:DISTINCT, 42)
704
- COUNT = value(:COUNT, 43)
705
- IS_EMPTY = value(:IS_EMPTY, 86)
706
- UNION = value(:UNION, 44)
707
- NTH = value(:NTH, 45)
708
- GROUPED_MAP_REDUCE = value(:GROUPED_MAP_REDUCE, 46)
709
- GROUPBY = value(:GROUPBY, 47)
710
- INNER_JOIN = value(:INNER_JOIN, 48)
711
- OUTER_JOIN = value(:OUTER_JOIN, 49)
712
- EQ_JOIN = value(:EQ_JOIN, 50)
713
- ZIP = value(:ZIP, 72)
714
- INSERT_AT = value(:INSERT_AT, 82)
715
- DELETE_AT = value(:DELETE_AT, 83)
716
- CHANGE_AT = value(:CHANGE_AT, 84)
717
- SPLICE_AT = value(:SPLICE_AT, 85)
718
- COERCE_TO = value(:COERCE_TO, 51)
719
- TYPEOF = value(:TYPEOF, 52)
720
- UPDATE = value(:UPDATE, 53)
721
- DELETE = value(:DELETE, 54)
722
- REPLACE = value(:REPLACE, 55)
723
- INSERT = value(:INSERT, 56)
724
- DB_CREATE = value(:DB_CREATE, 57)
725
- DB_DROP = value(:DB_DROP, 58)
726
- DB_LIST = value(:DB_LIST, 59)
727
- TABLE_CREATE = value(:TABLE_CREATE, 60)
728
- TABLE_DROP = value(:TABLE_DROP, 61)
729
- TABLE_LIST = value(:TABLE_LIST, 62)
730
- INDEX_CREATE = value(:INDEX_CREATE, 75)
731
- INDEX_DROP = value(:INDEX_DROP, 76)
732
- INDEX_LIST = value(:INDEX_LIST, 77)
733
- FUNCALL = value(:FUNCALL, 64)
734
- BRANCH = value(:BRANCH, 65)
735
- ANY = value(:ANY, 66)
736
- ALL = value(:ALL, 67)
737
- FOREACH = value(:FOREACH, 68)
738
- FUNC = value(:FUNC, 69)
739
- ASC = value(:ASC, 73)
740
- DESC = value(:DESC, 74)
741
- INFO = value(:INFO, 79)
742
- MATCH = value(:MATCH, 97)
743
- SAMPLE = value(:SAMPLE, 81)
744
- DEFAULT = value(:DEFAULT, 92)
119
+
120
+ class Term < ::ProtocolBuffers::Message
121
+ # forward declarations
122
+ class AssocPair < ::ProtocolBuffers::Message; end
123
+
124
+ # enums
125
+ module TermType
126
+ include ::ProtocolBuffers::Enum
127
+ DATUM = 1
128
+ MAKE_ARRAY = 2
129
+ MAKE_OBJ = 3
130
+ VAR = 10
131
+ JAVASCRIPT = 11
132
+ ERROR = 12
133
+ IMPLICIT_VAR = 13
134
+ DB = 14
135
+ TABLE = 15
136
+ GET = 16
137
+ GET_ALL = 78
138
+ EQ = 17
139
+ NE = 18
140
+ LT = 19
141
+ LE = 20
142
+ GT = 21
143
+ GE = 22
144
+ NOT = 23
145
+ ADD = 24
146
+ SUB = 25
147
+ MUL = 26
148
+ DIV = 27
149
+ MOD = 28
150
+ APPEND = 29
151
+ PREPEND = 80
152
+ DIFFERENCE = 95
153
+ SET_INSERT = 88
154
+ SET_INTERSECTION = 89
155
+ SET_UNION = 90
156
+ SET_DIFFERENCE = 91
157
+ SLICE = 30
158
+ SKIP = 70
159
+ LIMIT = 71
160
+ INDEXES_OF = 87
161
+ CONTAINS = 93
162
+ GET_FIELD = 31
163
+ KEYS = 94
164
+ HAS_FIELDS = 32
165
+ WITH_FIELDS = 96
166
+ PLUCK = 33
167
+ WITHOUT = 34
168
+ MERGE = 35
169
+ BETWEEN = 36
170
+ REDUCE = 37
171
+ MAP = 38
172
+ FILTER = 39
173
+ CONCATMAP = 40
174
+ ORDERBY = 41
175
+ DISTINCT = 42
176
+ COUNT = 43
177
+ IS_EMPTY = 86
178
+ UNION = 44
179
+ NTH = 45
180
+ GROUPED_MAP_REDUCE = 46
181
+ GROUPBY = 47
182
+ INNER_JOIN = 48
183
+ OUTER_JOIN = 49
184
+ EQ_JOIN = 50
185
+ ZIP = 72
186
+ INSERT_AT = 82
187
+ DELETE_AT = 83
188
+ CHANGE_AT = 84
189
+ SPLICE_AT = 85
190
+ COERCE_TO = 51
191
+ TYPEOF = 52
192
+ UPDATE = 53
193
+ DELETE = 54
194
+ REPLACE = 55
195
+ INSERT = 56
196
+ DB_CREATE = 57
197
+ DB_DROP = 58
198
+ DB_LIST = 59
199
+ TABLE_CREATE = 60
200
+ TABLE_DROP = 61
201
+ TABLE_LIST = 62
202
+ INDEX_CREATE = 75
203
+ INDEX_DROP = 76
204
+ INDEX_LIST = 77
205
+ FUNCALL = 64
206
+ BRANCH = 65
207
+ ANY = 66
208
+ ALL = 67
209
+ FOREACH = 68
210
+ FUNC = 69
211
+ ASC = 73
212
+ DESC = 74
213
+ INFO = 79
214
+ MATCH = 97
215
+ SAMPLE = 81
216
+ DEFAULT = 92
217
+ JSON = 98
745
218
  end
746
- optional :TermType, :type, 1
747
- optional :Datum, :datum, 2
748
- repeated :Term, :args, 3
749
- class AssocPair < ::Protobuf::Message
750
- defined_in __FILE__
219
+
220
+ # nested messages
221
+ class AssocPair < ::ProtocolBuffers::Message
751
222
  optional :string, :key, 1
752
- optional :Term, :val, 2
223
+ optional ::Term, :val, 2
753
224
  end
754
- repeated :AssocPair, :optargs, 4
755
- extensions 10000..20000
756
- end
225
+
226
+ optional ::Term::TermType, :type, 1
227
+ optional ::Datum, :datum, 2
228
+ repeated ::Term, :args, 3
229
+ repeated ::Term::AssocPair, :optargs, 4
230
+ end
231
+
data/lib/rethinkdb.rb CHANGED
@@ -2,23 +2,6 @@
2
2
  require 'rubygems'
3
3
  require 'ql2.pb.rb'
4
4
 
5
- if 2**63 != 9223372036854775808
6
- $stderr.puts "WARNING: Ruby believes 2**63 = #{2**63} rather than 9223372036854775808!"
7
- $stderr.puts "Consider upgrading your verison of Ruby."
8
- $stderr.puts "Hot-patching ruby_protobuf to compensate..."
9
- rethinkdb_verbose, $VERBOSE = $VERBOSE, nil
10
- module Protobuf
11
- module Field
12
- class VarintField < BaseField
13
- INT64_MAX = 9223372036854775807
14
- INT64_MIN = -9223372036854775808
15
- UINT64_MAX = 18446744073709551615
16
- end
17
- end
18
- end
19
- $VERBOSE = rethinkdb_verbose
20
- end
21
-
22
5
  require 'socket'
23
6
  require 'pp'
24
7
 
@@ -78,10 +61,10 @@ module RethinkDB
78
61
 
79
62
  attr_accessor :body, :bitop
80
63
 
81
- def initialize(body = nil, bitop = nil)
64
+ def initialize(body = nil, bitop = nil, context = nil)
82
65
  @body = body
83
66
  @bitop = bitop
84
- @body.context = RPP.sanitize_context caller if @body
67
+ @body.context = (context || RPP.sanitize_context(caller)) if @body
85
68
  end
86
69
 
87
70
  def pp
data/lib/rpp.rb CHANGED
@@ -3,6 +3,10 @@ require 'prettyprint'
3
3
 
4
4
  module RethinkDB
5
5
  module RPP
6
+ @@termtype_to_str = Hash[
7
+ Term::TermType.constants.map{|x| [Term::TermType.const_get(x), x.to_s]}
8
+ ]
9
+
6
10
  def self.sanitize_context context
7
11
  if __FILE__ =~ /^(.*\/)[^\/]+.rb$/
8
12
  prefix = $1;
@@ -103,7 +107,7 @@ module RethinkDB
103
107
  return res
104
108
  end
105
109
 
106
- name = term.type.to_s.downcase
110
+ name = @@termtype_to_str[term.type].downcase
107
111
  args = term.args.dup
108
112
  optargs = term.optargs.dup
109
113
 
data/lib/shim.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module RethinkDB
2
4
  module Shim
3
5
  def self.datum_to_native d
@@ -69,40 +71,65 @@ module RethinkDB
69
71
  class RQL
70
72
  def to_pb; @body; end
71
73
 
72
- def expr(x)
73
- unbound_if @body
74
- return x if x.class == RQL
75
- datum_types = [Fixnum, Float, Bignum, String, Symbol,
74
+ @@datum_types = [Fixnum, Float, Bignum, String, Symbol,
76
75
  TrueClass, FalseClass, NilClass]
77
76
 
78
- if datum_types.include? x.class
79
- return RQL.new(Shim.native_to_datum_term(x))
77
+ def any_to_pb(x, context)
78
+ return x.to_pb if x.class == RQL
79
+ t = Term.new
80
+ t.type = Term::TermType::JSON
81
+ t.args = [Shim.native_to_datum_term(x.to_json(:max_nesting => 500))]
82
+ return t
83
+ end
84
+
85
+ def fast_expr(x, context, allow_json)
86
+ return x if x.class == RQL
87
+ if @@datum_types.include?(x.class)
88
+ return x if allow_json
89
+ return RQL.new(Shim.native_to_datum_term(x), nil, context)
80
90
  end
81
91
 
82
- t = Term.new
83
92
  case x
84
93
  when Array
94
+ args = x.map{|y| fast_expr(y, context, allow_json)}
95
+ return x if allow_json && args.all?{|y| y.class != RQL}
96
+ t = Term.new
85
97
  t.type = Term::TermType::MAKE_ARRAY
86
- t.args = x.map{|y| expr(y).to_pb}
98
+ t.args = args.map{|y| any_to_pb(y, context)}
99
+ return RQL.new(t, nil, context)
87
100
  when Hash
101
+ kvs = x.map{|k,v| [k, fast_expr(v, context, allow_json)]}
102
+ return x if allow_json && kvs.all? {|k,v|
103
+ (k.class == String || k.class == Symbol) && v.class != RQL
104
+ }
105
+ t = Term.new
88
106
  t.type = Term::TermType::MAKE_OBJ
89
- t.optargs = x.map{|k,v|
107
+ t.optargs = kvs.map{|k,v|
90
108
  ap = Term::AssocPair.new;
91
- if [Symbol, String].include? k.class
109
+ if k.class == Symbol || k.class == String
92
110
  ap.key = k.to_s
93
111
  else
94
112
  raise RqlDriverError, "Object keys must be strings or symbols." +
95
113
  " (Got object `#{k.inspect}` of class `#{k.class}`.)"
96
114
  end
97
- ap.val = expr(v).to_pb
115
+ ap.val = any_to_pb(v, context)
98
116
  ap
99
117
  }
118
+ return RQL.new(t, nil, context)
100
119
  when Proc
101
- t = RQL.new.new_func(&x).to_pb
120
+ t = RQL.new(nil, nil, context).new_func(&x).to_pb
121
+ return RQL.new(t, nil, context)
102
122
  else raise RqlDriverError, "r.expr can't handle #{x.inspect} of type #{x.class}"
103
123
  end
124
+ end
104
125
 
105
- return RQL.new(t)
126
+ def expr(x, opts={})
127
+ allow_json = opts[:allow_json]
128
+ unbound_if @body
129
+ context = RPP.sanitize_context(caller)
130
+ res = fast_expr(x, context, allow_json)
131
+ return res if res.class == RQL
132
+ return RQL.new(any_to_pb(res, context), nil, context)
106
133
  end
107
134
 
108
135
  def coerce(other)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rethinkdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 111
4
+ hash: 103
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 6
8
+ - 7
9
9
  - 0
10
10
  - 0
11
- version: 1.6.0.0
11
+ version: 1.7.0.0
12
12
  platform: ruby
13
13
  authors:
14
14
  - RethinkDB Inc.
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-06-13 00:00:00 Z
19
+ date: 2013-07-03 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: json
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: ruby_protobuf
36
+ name: ruby-protocol-buffers
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -55,13 +55,13 @@ extensions: []
55
55
  extra_rdoc_files: []
56
56
 
57
57
  files:
58
- - lib/net.rb
59
58
  - lib/exc.rb
60
59
  - lib/ql2.pb.rb
60
+ - lib/func.rb
61
+ - lib/net.rb
61
62
  - lib/rethinkdb.rb
62
63
  - lib/rpp.rb
63
64
  - lib/shim.rb
64
- - lib/func.rb
65
65
  homepage: http://rethinkdb.com
66
66
  licenses:
67
67
  - Apache-2