rethinkdb 1.7.0.0 → 1.8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/lib/func.rb +8 -6
  2. data/lib/net.rb +31 -10
  3. data/lib/ql2.pb.rb +39 -0
  4. data/lib/rpp.rb +1 -1
  5. data/lib/shim.rb +46 -8
  6. metadata +40 -64
@@ -15,15 +15,19 @@ module RethinkDB
15
15
  # only be removed from the argument list and treated as an optarg
16
16
  # if it's a Hash. A positive value is necessary for functions
17
17
  # that can take a hash for the last non-optarg argument.
18
+ # NOTE: we search for the optarg after we apply the rewrite rules below.
19
+ # For example we need to use orderby not order_by
18
20
  @@optarg_offsets = {
19
21
  :replace => {:with_block => 0, :without => 1},
20
22
  :update => {:with_block => 0, :without => 1},
21
23
  :insert => 1,
22
24
  :delete => -1,
23
- :reduce => -1, :between => -1, :grouped_map_reduce => -1,
25
+ :reduce => -1, :between => 2, :grouped_map_reduce => -1,
24
26
  :table => -1, :table_create => -1,
25
27
  :get_all => -1, :eq_join => -1,
26
- :javascript => -1, :filter => {:with_block => 0, :without => 1}
28
+ :javascript => -1, :filter => {:with_block => 0, :without => 1},
29
+ :slice => -1, :during => -1, :orderby => -1,
30
+ :iso8601 => -1
27
31
  }
28
32
  @@rewrites = {
29
33
  :< => :lt, :<= => :le, :> => :gt, :>= => :ge,
@@ -130,10 +134,8 @@ module RethinkDB
130
134
  elsif ind.class == Symbol || ind.class == String
131
135
  return get_field(ind)
132
136
  elsif ind.class == Range
133
- if ind.end == 0 && ind.exclude_end?
134
- raise ArgumentError, "Cannot slice to an excluded end of 0."
135
- end
136
- return slice(ind.begin, ind.end - (ind.exclude_end? ? 1 : 0))
137
+ return slice(ind.begin, ind.end, :right_bound =>
138
+ (ind.exclude_end? ? 'open' : 'closed'))
137
139
  end
138
140
  raise ArgumentError, "[] cannot handle #{ind.inspect} of type #{ind.class}."
139
141
  end
data/lib/net.rb CHANGED
@@ -20,6 +20,12 @@ module RethinkDB
20
20
  c, opts = @@default_conn, c if opts.nil? && !c.kind_of?(RethinkDB::Connection)
21
21
  opts = {} if opts.nil?
22
22
  opts = {opts => true} if opts.class != Hash
23
+ if (tf = opts[:time_format])
24
+ opts[:time_format] = (tf = tf.to_s)
25
+ if tf != 'raw' && tf != 'native'
26
+ raise ArgumentError, "`time_format` must be 'raw' or 'native' (got `#{tf}`)."
27
+ end
28
+ end
23
29
  if !c
24
30
  raise ArgumentError, "No connection specified!\n" \
25
31
  "Use `query.run(conn)` or `conn.repl(); query.run`."
@@ -46,13 +52,14 @@ module RethinkDB
46
52
  (@run ? "" : "\n#{preview}") + ">"
47
53
  end
48
54
 
49
- def initialize(results, msg, connection, token, more = true) # :nodoc:
55
+ def initialize(results, msg, connection, opts, token, more = true) # :nodoc:
50
56
  @more = more
51
57
  @results = results
52
58
  @msg = msg
53
59
  @run = false
54
60
  @conn_id = connection.conn_id
55
61
  @conn = connection
62
+ @opts = opts
56
63
  @token = token
57
64
  end
58
65
 
@@ -67,7 +74,7 @@ module RethinkDB
67
74
  q.type = Query::QueryType::CONTINUE
68
75
  q.token = @token
69
76
  res = @conn.run_internal q
70
- @results = Shim.response_to_native(res, @msg)
77
+ @results = Shim.response_to_native(res, @msg, @opts)
71
78
  if res.type == Response::ResponseType::SUCCESS_SEQUENCE
72
79
  @more = false
73
80
  end
@@ -133,11 +140,13 @@ module RethinkDB
133
140
  res = run_internal(q, all_opts[:noreply])
134
141
  return res if !res
135
142
  if res.type == Response::ResponseType::SUCCESS_PARTIAL
136
- Cursor.new(Shim.response_to_native(res, msg), msg, self, q.token, true)
143
+ Cursor.new(Shim.response_to_native(res, msg, opts),
144
+ msg, self, opts, q.token, true)
137
145
  elsif res.type == Response::ResponseType::SUCCESS_SEQUENCE
138
- Cursor.new(Shim.response_to_native(res, msg), msg, self, q.token, false)
146
+ Cursor.new(Shim.response_to_native(res, msg, opts),
147
+ msg, self, opts, q.token, false)
139
148
  else
140
- Shim.response_to_native(res, msg)
149
+ Shim.response_to_native(res, msg, opts)
141
150
  end
142
151
  end
143
152
 
@@ -259,11 +268,23 @@ module RethinkDB
259
268
  rescue
260
269
  raise RqlRuntimeError, "Bad Protobuf #{response}, server is buggy."
261
270
  end
262
- @mutex.synchronize do
263
- @data[protob.token] = protob
264
- if (@waiters[protob.token])
265
- cond = @waiters.delete protob.token
266
- cond.signal
271
+ if protob.token == -1
272
+ @mutex.synchronize do
273
+ @waiters.keys.each {|k|
274
+ @data[k] = protob
275
+ if @waiters[k]
276
+ cond = @waiters.delete k
277
+ cond.signal
278
+ end
279
+ }
280
+ end
281
+ else
282
+ @mutex.synchronize do
283
+ @data[protob.token] = protob
284
+ if @waiters[protob.token]
285
+ cond = @waiters.delete protob.token
286
+ cond.signal
287
+ end
267
288
  end
268
289
  end
269
290
  end
@@ -215,6 +215,45 @@ class Term < ::ProtocolBuffers::Message
215
215
  SAMPLE = 81
216
216
  DEFAULT = 92
217
217
  JSON = 98
218
+ ISO8601 = 99
219
+ TO_ISO8601 = 100
220
+ EPOCH_TIME = 101
221
+ TO_EPOCH_TIME = 102
222
+ NOW = 103
223
+ IN_TIMEZONE = 104
224
+ DURING = 105
225
+ DATE = 106
226
+ TIME_OF_DAY = 126
227
+ TIMEZONE = 127
228
+ YEAR = 128
229
+ MONTH = 129
230
+ DAY = 130
231
+ DAY_OF_WEEK = 131
232
+ DAY_OF_YEAR = 132
233
+ HOURS = 133
234
+ MINUTES = 134
235
+ SECONDS = 135
236
+ TIME = 136
237
+ MONDAY = 107
238
+ TUESDAY = 108
239
+ WEDNESDAY = 109
240
+ THURSDAY = 110
241
+ FRIDAY = 111
242
+ SATURDAY = 112
243
+ SUNDAY = 113
244
+ JANUARY = 114
245
+ FEBRUARY = 115
246
+ MARCH = 116
247
+ APRIL = 117
248
+ MAY = 118
249
+ JUNE = 119
250
+ JULY = 120
251
+ AUGUST = 121
252
+ SEPTEMBER = 122
253
+ OCTOBER = 123
254
+ NOVEMBER = 124
255
+ DECEMBER = 125
256
+ LITERAL = 137
218
257
  end
219
258
 
220
259
  # nested messages
data/lib/rpp.rb CHANGED
@@ -50,7 +50,7 @@ module RethinkDB
50
50
 
51
51
  def self.pp_int_datum(q, dat, pre_dot)
52
52
  q.text("r(") if pre_dot
53
- q.text(Shim.datum_to_native(dat).inspect)
53
+ q.text(Shim.datum_to_native(dat, :time_format => 'raw').inspect)
54
54
  q.text(")") if pre_dot
55
55
  end
56
56
 
@@ -1,8 +1,9 @@
1
1
  require 'json'
2
+ require 'time'
2
3
 
3
4
  module RethinkDB
4
5
  module Shim
5
- def self.datum_to_native d
6
+ def self.datum_to_native(d, opts)
6
7
  raise RqlRuntimeError, "SHENANIGANS" if d.class != Datum
7
8
  dt = Datum::DatumType
8
9
  case d.type
@@ -10,13 +11,21 @@ module RethinkDB
10
11
  when dt::R_STR then d.r_str
11
12
  when dt::R_BOOL then d.r_bool
12
13
  when dt::R_NULL then nil
13
- when dt::R_ARRAY then d.r_array.map{|d2| datum_to_native d2}
14
- when dt::R_OBJECT then Hash[d.r_object.map{|x| [x.key, datum_to_native(x.val)]}]
14
+ when dt::R_ARRAY then d.r_array.map{|d2| datum_to_native(d2, opts)}
15
+ when dt::R_OBJECT then
16
+ obj = Hash[d.r_object.map{|x| [x.key, datum_to_native(x.val, opts)]}]
17
+ if obj["$reql_type$"] == "TIME" && opts[:time_format] != 'raw'
18
+ t = Time.at(obj['epoch_time'])
19
+ tz = obj['timezone']
20
+ (tz && tz != "" && tz != "Z") ? t.getlocal(tz) : t.utc
21
+ else
22
+ obj
23
+ end
15
24
  else raise RqlRuntimeError, "Unimplemented."
16
25
  end
17
26
  end
18
27
 
19
- def self.response_to_native(r, orig_term)
28
+ def self.response_to_native(r, orig_term, opts)
20
29
  rt = Response::ResponseType
21
30
  if r.backtrace
22
31
  bt = r.backtrace.frames.map {|x|
@@ -28,9 +37,9 @@ module RethinkDB
28
37
 
29
38
  begin
30
39
  case r.type
31
- when rt::SUCCESS_ATOM then datum_to_native(r.response[0])
32
- when rt::SUCCESS_PARTIAL then r.response.map{|d| datum_to_native(d)}
33
- when rt::SUCCESS_SEQUENCE then r.response.map{|d| datum_to_native(d)}
40
+ when rt::SUCCESS_ATOM then datum_to_native(r.response[0], opts)
41
+ when rt::SUCCESS_PARTIAL then r.response.map{|d| datum_to_native(d, opts)}
42
+ when rt::SUCCESS_SEQUENCE then r.response.map{|d| datum_to_native(d, opts)}
34
43
  when rt::RUNTIME_ERROR then
35
44
  raise RqlRuntimeError, "#{r.response[0].r_str}"
36
45
  when rt::COMPILE_ERROR then # TODO: remove?
@@ -82,6 +91,13 @@ module RethinkDB
82
91
  return t
83
92
  end
84
93
 
94
+ def timezone_from_offset(offset)
95
+ raw_offset = offset.abs
96
+ raw_hours = raw_offset / 3600
97
+ raw_minutes = (raw_offset / 60) - (raw_hours * 60)
98
+ return (offset < 0 ? "-" : "+") + sprintf("%02d:%02d", raw_hours, raw_minutes);
99
+ end
100
+
85
101
  def fast_expr(x, context, allow_json)
86
102
  return x if x.class == RQL
87
103
  if @@datum_types.include?(x.class)
@@ -123,11 +139,33 @@ module RethinkDB
123
139
  end
124
140
  end
125
141
 
142
+ def check_depth depth
143
+ raise RqlRuntimeError, "Maximum expression depth of 20 exceeded." if depth > 20
144
+ end
145
+
146
+ def reql_typify(tree, depth=0)
147
+ check_depth(depth)
148
+ case tree
149
+ when Array
150
+ return tree.map{|x| reql_typify(x, depth+1)}
151
+ when Hash
152
+ return Hash[tree.map{|k,v| [k, reql_typify(v, depth+1)]}]
153
+ when Time
154
+ return {
155
+ '$reql_type$' => 'TIME',
156
+ 'epoch_time' => tree.to_f,
157
+ 'timezone' => timezone_from_offset(tree.utc_offset)
158
+ }
159
+ else
160
+ return tree
161
+ end
162
+ end
163
+
126
164
  def expr(x, opts={})
127
165
  allow_json = opts[:allow_json]
128
166
  unbound_if @body
129
167
  context = RPP.sanitize_context(caller)
130
- res = fast_expr(x, context, allow_json)
168
+ res = fast_expr(reql_typify(x), context, allow_json)
131
169
  return res if res.class == RQL
132
170
  return RQL.new(any_to_pb(res, context), nil, context)
133
171
  end
metadata CHANGED
@@ -1,99 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rethinkdb
3
- version: !ruby/object:Gem::Version
4
- hash: 103
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.0.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 7
9
- - 0
10
- - 0
11
- version: 1.7.0.0
12
6
  platform: ruby
13
- authors:
7
+ authors:
14
8
  - RethinkDB Inc.
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2013-07-03 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &17292480 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: ruby-protocol-buffers
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *17292480
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-protocol-buffers
27
+ requirement: &17291140 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :runtime
48
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *17291140
49
36
  description:
50
37
  email: bugs@rethinkdb.com
51
38
  executables: []
52
-
53
39
  extensions: []
54
-
55
40
  extra_rdoc_files: []
56
-
57
- files:
41
+ files:
58
42
  - lib/exc.rb
59
43
  - lib/ql2.pb.rb
60
- - lib/func.rb
61
- - lib/net.rb
62
44
  - lib/rethinkdb.rb
45
+ - lib/net.rb
63
46
  - lib/rpp.rb
64
47
  - lib/shim.rb
48
+ - lib/func.rb
65
49
  homepage: http://rethinkdb.com
66
- licenses:
50
+ licenses:
67
51
  - Apache-2
68
52
  post_install_message:
69
53
  rdoc_options: []
70
-
71
- require_paths:
54
+ require_paths:
72
55
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
74
57
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.9.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
63
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
91
68
  requirements: []
92
-
93
69
  rubyforge_project:
94
- rubygems_version: 1.8.15
70
+ rubygems_version: 1.8.11
95
71
  signing_key:
96
72
  specification_version: 3
97
- summary: This package provides the Ruby driver library for the RethinkDB database server.
73
+ summary: This package provides the Ruby driver library for the RethinkDB database
74
+ server.
98
75
  test_files: []
99
-