rethinkdb 1.5.0.0 → 1.6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/func.rb +23 -19
  2. data/lib/net.rb +27 -6
  3. data/lib/ql2.pb.rb +101 -9
  4. metadata +6 -6
data/lib/func.rb CHANGED
@@ -7,14 +7,23 @@ module RethinkDB
7
7
  RQL.new.func(args, body)
8
8
  end
9
9
 
10
- @@special_optargs = {
11
- :replace => :non_atomic, :update => :non_atomic, :insert => :upsert
12
- }
13
- @@opt_off = {
10
+ # Offsets of the "optarg" optional arguments hash in respective
11
+ # methods. Some methods change this depending on whether they're
12
+ # passed a block -- they take a hash specifying the offset for
13
+ # each circumstance, instead of an integer. -1 can be supplied to
14
+ # mean the "last" argument -- whatever argument is specified will
15
+ # only be removed from the argument list and treated as an optarg
16
+ # if it's a Hash. A positive value is necessary for functions
17
+ # that can take a hash for the last non-optarg argument.
18
+ @@optarg_offsets = {
19
+ :replace => {:with_block => 0, :without => 1},
20
+ :update => {:with_block => 0, :without => 1},
21
+ :insert => 1,
22
+ :delete => -1,
14
23
  :reduce => -1, :between => -1, :grouped_map_reduce => -1,
15
24
  :table => -1, :table_create => -1,
16
25
  :get_all => -1, :eq_join => -1,
17
- :javascript => -1
26
+ :javascript => -1, :filter => {:with_block => 0, :without => 1}
18
27
  }
19
28
  @@rewrites = {
20
29
  :< => :lt, :<= => :le, :> => :gt, :>= => :ge,
@@ -48,11 +57,15 @@ module RethinkDB
48
57
  termtype = Term::TermType.values[m.to_s.upcase.to_sym]
49
58
  unbound_if(!termtype, m)
50
59
 
51
- if (opt_name = @@special_optargs[m])
52
- a = optarg_jiggle(a, opt_name)
53
- opt_offset = -1
54
- end
55
- if (opt_offset ||= @@opt_off[m])
60
+ if (opt_offset = @@optarg_offsets[m])
61
+ if opt_offset.class == Hash
62
+ opt_offset = opt_offset[b ? :with_block : :without]
63
+ end
64
+ # TODO: This should drop the Hash comparison or at least
65
+ # @@optarg_offsets should stop specifying -1, where possible.
66
+ # Any time one of these operations is changed to support a
67
+ # hash argument, we'll have to remember to fix
68
+ # @@optarg_offsets, otherwise.
56
69
  optargs = a.delete_at(opt_offset) if a[opt_offset].class == Hash
57
70
  end
58
71
 
@@ -76,15 +89,6 @@ module RethinkDB
76
89
  end
77
90
  def groupby(*a, &b); group_by(*a, &b); end
78
91
 
79
- def optarg_jiggle(args, optarg)
80
- if (ind = args.map{|x| x.class == Symbol ? x : nil}.index(optarg))
81
- args << {args.delete_at(ind) => true}
82
- else
83
- args << {}
84
- end
85
- return args
86
- end
87
-
88
92
  def connect(*args)
89
93
  unbound_if @body
90
94
  Connection.new(*args)
data/lib/net.rb CHANGED
@@ -75,17 +75,26 @@ module RethinkDB
75
75
  end
76
76
 
77
77
  class Connection
78
+ def auto_reconnect(x=true)
79
+ @auto_reconnect = x
80
+ self
81
+ end
78
82
  def repl; RQL.set_default_conn self; end
79
83
 
80
- def initialize(host='localhost', port=28015, default_db=nil)
84
+ def initialize(opts={})
81
85
  begin
82
86
  @abort_module = ::IRB
83
87
  rescue NameError => e
84
88
  @abort_module = Faux_Abort
85
89
  end
90
+
91
+ opts = {:host => opts} if opts.class == String
92
+ @host = opts[:host] || "localhost"
93
+ @port = opts[:port] || 28015
94
+ default_db = opts[:db]
95
+ @auth_key = opts[:auth_key] || ""
96
+
86
97
  @@last = self
87
- @host = host
88
- @port = port
89
98
  @default_opts = default_db ? {:db => RQL.new.db(default_db)} : {}
90
99
  @conn_id = 0
91
100
  reconnect
@@ -98,6 +107,7 @@ module RethinkDB
98
107
  noreply ? nil : wait(q.token)
99
108
  end
100
109
  def run(msg, opts)
110
+ reconnect if @auto_reconnect && (!@socket || !@listener)
101
111
  raise RuntimeError, "Error: Connection Closed." if !@socket || !@listener
102
112
  q = Query.new
103
113
  q.type = Query::QueryType::START
@@ -135,9 +145,9 @@ module RethinkDB
135
145
  end
136
146
 
137
147
  def dispatch msg
138
- PP.pp msg if $DEBUG
148
+ # PP.pp msg if $DEBUG
139
149
  payload = msg.serialize_to_string
140
- #File.open('sexp_payloads.txt', 'a') {|f| f.write(payload.inspect+"\n")}
150
+ # File.open('sexp_payloads.txt', 'a') {|f| f.write(payload.inspect+"\n")}
141
151
  send([payload.length].pack('L<') + payload)
142
152
  return msg.token
143
153
  end
@@ -172,7 +182,7 @@ module RethinkDB
172
182
  end
173
183
 
174
184
  @@last = nil
175
- @@magic_number = 0x3f61ba36
185
+ @@magic_number = VersionDummy::Version::V0_2
176
186
 
177
187
  def debug_socket; @socket; end
178
188
 
@@ -212,6 +222,17 @@ module RethinkDB
212
222
  end
213
223
  end
214
224
  @socket.write([@@magic_number].pack('L<'))
225
+
226
+ @socket.write([@auth_key.size].pack('L<') + @auth_key)
227
+ response = ""
228
+ while response[-1..-1] != "\0"
229
+ response += @socket.read_exn(1)
230
+ end
231
+ response = response[0...-1]
232
+ if response != "SUCCESS"
233
+ raise RqlRuntimeError,"Server dropped connection with message: \"#{response}\""
234
+ end
235
+
215
236
  @listener.terminate if @listener
216
237
  @listener = Thread.new do
217
238
  loop do
data/lib/ql2.pb.rb CHANGED
@@ -10,6 +10,14 @@
10
10
  # // little-endian 32-bit integer over the wire raw. This number should
11
11
  # // only be sent once per connection.
12
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
+ #
13
21
  # // Next, for each query you want to send, construct a [Query] protobuf
14
22
  # // and serialize it to a binary blob. Send the blob's size to the
15
23
  # // server encoded as a little-endian 32-bit integer, followed by the
@@ -33,6 +41,7 @@
33
41
  # // non-conforming protobuf libraries
34
42
  # enum Version {
35
43
  # V0_1 = 0x3f61ba36;
44
+ # V0_2 = 0x723081e1;
36
45
  # }
37
46
  # }
38
47
  #
@@ -211,8 +220,12 @@
211
220
  # // Takes some javascript code and executes it.
212
221
  # JAVASCRIPT = 11; // STRING {timeout: !NUMBER} -> DATUM |
213
222
  # // STRING {timeout: !NUMBER} -> Function(*)
223
+ #
214
224
  # // Takes a string and throws an error with that message.
215
- # ERROR = 12; // STRING -> Error
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
216
229
  # // Takes nothing and returns a reference to the implicit variable.
217
230
  # IMPLICIT_VAR = 13; // -> DATUM
218
231
  #
@@ -244,17 +257,39 @@
244
257
  # // DATUM Array Ops
245
258
  # // Append a single element to the end of an array (like `snoc`).
246
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
+ #
247
275
  # SLICE = 30; // Sequence, NUMBER, NUMBER -> Sequence
248
276
  # SKIP = 70; // Sequence, NUMBER -> Sequence
249
277
  # LIMIT = 71; // Sequence, NUMBER -> Sequence
278
+ # INDEXES_OF = 87; // Sequence, DATUM -> Sequence | Sequence, Function(1) -> Sequence
279
+ # CONTAINS = 93; // Sequence, DATUM -> BOOL
250
280
  #
251
281
  # // Stream/Object Ops
252
282
  # // Get a particular attribute out of an object, or map that over a
253
283
  # // sequence.
254
284
  # GETATTR = 31; // OBJECT, STRING -> DATUM
255
- # // Check whether an object contains all of a set of attributes, or map
256
- # // that over a sequence.
257
- # CONTAINS = 32; // OBJECT, STRING... -> BOOL
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
258
293
  # // Get a subset of an object by selecting some attributes to preserve,
259
294
  # // or map that over a sequence. (Both pick and pluck, polymorphic.)
260
295
  # PLUCK = 33; // Sequence, STRING... -> Sequence | OBJECT, STRING... -> OBJECT
@@ -269,15 +304,26 @@
269
304
  # BETWEEN = 36; // StreamSelection, DATUM, DATUM, {:index:!STRING} -> StreamSelection
270
305
  # REDUCE = 37; // Sequence, Function(2), {base:DATUM} -> DATUM
271
306
  # MAP = 38; // Sequence, Function(1) -> Sequence
272
- # FILTER = 39; // Sequence, Function(1) -> Sequence | Sequence, OBJECT -> 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
273
317
  # // Map a function over a sequence and then concatenate the results together.
274
318
  # CONCATMAP = 40; // Sequence, Function(1) -> Sequence
275
319
  # // Order a sequence based on one or more attributes.
276
320
  # ORDERBY = 41; // Sequence, (!STRING | Ordering)... -> Sequence
277
321
  # // Get all distinct elements of a sequence (like `uniq`).
278
322
  # DISTINCT = 42; // Sequence -> Sequence
279
- # // Count the number of elements in a sequence.
280
- # COUNT = 43; // Sequence -> NUMBER
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
281
327
  # // Take the union of multiple sequences (preserves duplicate elements! (use distinct)).
282
328
  # UNION = 44; // Sequence... -> Sequence
283
329
  # // Get the Nth element of a sequence.
@@ -286,7 +332,7 @@
286
332
  # // - A function to group the sequence by.
287
333
  # // - A function to map over the groups.
288
334
  # // - A reduction to apply to each of the groups.
289
- # GROUPED_MAP_REDUCE = 46; // Sequence, Function(1), Function(1), Function(2), {base:DATUM} -> Sequence
335
+ # GROUPED_MAP_REDUCE = 46; // Sequence, Function(1), Function(1), Function(2), {base:DATUM} -> ARRAY
290
336
  # // Groups a sequence by one or more attributes, and then applies a reduction.
291
337
  # // The third argument is a special object literal giving the kind of operation to be
292
338
  # // performed and any necessary arguments.
@@ -301,6 +347,16 @@
301
347
  # EQ_JOIN = 50; // Sequence, !STRING, Sequence, {index:!STRING} -> Sequence
302
348
  # ZIP = 72; // Sequence -> Sequence
303
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
304
360
  #
305
361
  # // * Type Ops
306
362
  # // Coerces a datum to a named type (e.g. "bool").
@@ -423,6 +479,23 @@
423
479
  #
424
480
  # // Gets info about anything. INFO is most commonly called on tables.
425
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
426
499
  # }
427
500
  # optional TermType type = 1;
428
501
  #
@@ -498,6 +571,7 @@ class VersionDummy < ::Protobuf::Message
498
571
  class Version < ::Protobuf::Enum
499
572
  defined_in __FILE__
500
573
  V0_1 = value(:V0_1, 1063369270)
574
+ V0_2 = value(:V0_2, 1915781601)
501
575
  end
502
576
  end
503
577
  class Query < ::Protobuf::Message
@@ -602,11 +676,21 @@ class Term < ::Protobuf::Message
602
676
  DIV = value(:DIV, 27)
603
677
  MOD = value(:MOD, 28)
604
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)
605
685
  SLICE = value(:SLICE, 30)
606
686
  SKIP = value(:SKIP, 70)
607
687
  LIMIT = value(:LIMIT, 71)
688
+ INDEXES_OF = value(:INDEXES_OF, 87)
689
+ CONTAINS = value(:CONTAINS, 93)
608
690
  GETATTR = value(:GETATTR, 31)
609
- CONTAINS = value(:CONTAINS, 32)
691
+ KEYS = value(:KEYS, 94)
692
+ HAS_FIELDS = value(:HAS_FIELDS, 32)
693
+ WITH_FIELDS = value(:WITH_FIELDS, 96)
610
694
  PLUCK = value(:PLUCK, 33)
611
695
  WITHOUT = value(:WITHOUT, 34)
612
696
  MERGE = value(:MERGE, 35)
@@ -618,6 +702,7 @@ class Term < ::Protobuf::Message
618
702
  ORDERBY = value(:ORDERBY, 41)
619
703
  DISTINCT = value(:DISTINCT, 42)
620
704
  COUNT = value(:COUNT, 43)
705
+ IS_EMPTY = value(:IS_EMPTY, 86)
621
706
  UNION = value(:UNION, 44)
622
707
  NTH = value(:NTH, 45)
623
708
  GROUPED_MAP_REDUCE = value(:GROUPED_MAP_REDUCE, 46)
@@ -626,6 +711,10 @@ class Term < ::Protobuf::Message
626
711
  OUTER_JOIN = value(:OUTER_JOIN, 49)
627
712
  EQ_JOIN = value(:EQ_JOIN, 50)
628
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)
629
718
  COERCE_TO = value(:COERCE_TO, 51)
630
719
  TYPEOF = value(:TYPEOF, 52)
631
720
  UPDATE = value(:UPDATE, 53)
@@ -650,6 +739,9 @@ class Term < ::Protobuf::Message
650
739
  ASC = value(:ASC, 73)
651
740
  DESC = value(:DESC, 74)
652
741
  INFO = value(:INFO, 79)
742
+ MATCH = value(:MATCH, 97)
743
+ SAMPLE = value(:SAMPLE, 81)
744
+ DEFAULT = value(:DEFAULT, 92)
653
745
  end
654
746
  optional :TermType, :type, 1
655
747
  optional :Datum, :datum, 2
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: 119
4
+ hash: 111
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 5
8
+ - 6
9
9
  - 0
10
10
  - 0
11
- version: 1.5.0.0
11
+ version: 1.6.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-05-16 00:00:00 Z
19
+ date: 2013-06-13 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: json
@@ -55,13 +55,13 @@ extensions: []
55
55
  extra_rdoc_files: []
56
56
 
57
57
  files:
58
+ - lib/net.rb
58
59
  - lib/exc.rb
59
60
  - lib/ql2.pb.rb
60
61
  - lib/rethinkdb.rb
61
62
  - lib/rpp.rb
62
63
  - lib/shim.rb
63
64
  - lib/func.rb
64
- - lib/net.rb
65
65
  homepage: http://rethinkdb.com
66
66
  licenses:
67
67
  - Apache-2
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements: []
92
92
 
93
93
  rubyforge_project:
94
- rubygems_version: 1.7.2
94
+ rubygems_version: 1.8.15
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: This package provides the Ruby driver library for the RethinkDB database server.