rethinkdb 1.2.6.0 → 1.2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jsons.rb +8 -4
- data/lib/net.rb +3 -3
- data/lib/rql.rb +17 -11
- data/lib/sequence.rb +4 -6
- metadata +4 -4
data/lib/jsons.rb
CHANGED
@@ -53,12 +53,16 @@ module RethinkDB
|
|
53
53
|
JSON_Expression.new [:call, [:getattr, attrname], [self]]
|
54
54
|
end
|
55
55
|
|
56
|
-
# Check whether a JSON object has
|
56
|
+
# Check whether a JSON object has all of the particular attributes. The
|
57
57
|
# following are equivalent:
|
58
|
-
# r({:id => 1}).contains(:id)
|
58
|
+
# r({:id => 1, :val => 2}).contains(:id, :val)
|
59
59
|
# r(true)
|
60
|
-
def contains(
|
61
|
-
|
60
|
+
def contains(*attrnames)
|
61
|
+
if attrnames.length == 1
|
62
|
+
JSON_Expression.new [:call, [:contains, attrnames[0]], [self]]
|
63
|
+
else
|
64
|
+
self.contains(attrnames[0]) & self.contains(*attrnames[1..-1])
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
68
|
# Construct a JSON object that has a subset of the attributes of
|
data/lib/net.rb
CHANGED
@@ -218,7 +218,7 @@ module RethinkDB
|
|
218
218
|
|
219
219
|
# Close the connection.
|
220
220
|
def close
|
221
|
-
@listener.terminate
|
221
|
+
@listener.terminate if @listener
|
222
222
|
@listener = nil
|
223
223
|
@socket.close
|
224
224
|
@socket = nil
|
@@ -240,7 +240,7 @@ module RethinkDB
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
@socket.send([@@magic_number].pack('L<'), 0)
|
243
|
-
@listener.terminate
|
243
|
+
@listener.terminate if @listener
|
244
244
|
@listener = Thread.new do
|
245
245
|
loop do
|
246
246
|
begin
|
@@ -251,7 +251,7 @@ module RethinkDB
|
|
251
251
|
@listener = nil
|
252
252
|
@waiters.each {|kv| kv[1].signal}
|
253
253
|
end
|
254
|
-
Thread.current.terminate
|
254
|
+
Thread.current.terminate
|
255
255
|
abort("unreachable")
|
256
256
|
end
|
257
257
|
#TODO: Recovery
|
data/lib/rql.rb
CHANGED
@@ -29,22 +29,18 @@ module RethinkDB
|
|
29
29
|
|
30
30
|
# Construct a javascript expression, which may refer to variables in scope
|
31
31
|
# (use <b>+to_s+</b> to get the name of a variable query, or simply splice
|
32
|
-
# it in).
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# are equivalent:
|
32
|
+
# it in). Behaves as if passed to the standard `eval` function in
|
33
|
+
# JavaScript. If you have a table <b>+table+</b>, the following are
|
34
|
+
# equivalent:
|
36
35
|
# table.map{|row| row[:id]}
|
37
36
|
# table.map{|row| r.js("#{row}.id")}
|
38
37
|
# table.map{r.js("this.id")} #implicit variable
|
39
|
-
# table.map{r.js("
|
38
|
+
# table.map{r.js("var a = this.id; a;")} #implicit variable
|
40
39
|
# As are:
|
41
40
|
# r.let(:a => 1, :b => 2) { r.add(r.letvar('a'), r.letvar('b'), 1) }
|
42
41
|
# r.let(:a => 1, :b => 2) { r.js('a+b+1') }
|
43
|
-
def self.js(str
|
44
|
-
|
45
|
-
elsif type == :func then JSON_Expression.new [:js, str]
|
46
|
-
else raise TypeError, 'Type of javascript must be either :expr or :func.'
|
47
|
-
end
|
42
|
+
def self.js(str);
|
43
|
+
JSON_Expression.new [:js, str]
|
48
44
|
end
|
49
45
|
|
50
46
|
# Refer to the database named <b>+db_name+</b>. Usually used as a
|
@@ -105,7 +101,7 @@ or Hash)."
|
|
105
101
|
# Test a predicate and execute one of two branches (just like
|
106
102
|
# Ruby's <b>+if+</b>). For example, if we have a table
|
107
103
|
# <b>+table+</b>:
|
108
|
-
# table.update{|row| r.
|
104
|
+
# table.update{|row| r.branch(row[:score] < 10, {:score => 10}, {})}
|
109
105
|
# will change every row with score below 10 in <b>+table+</b> to have score 10.
|
110
106
|
def self.branch(test, t_branch, f_branch)
|
111
107
|
tb = S.r(t_branch)
|
@@ -422,6 +418,16 @@ or Hash)."
|
|
422
418
|
# A shortcut for Data_Collectors::avg
|
423
419
|
def self.avg(*args); Data_Collectors.avg(*args); end
|
424
420
|
|
421
|
+
# Specify ascending ordering for a given attribute passed to order_by.
|
422
|
+
def self.asc(attr)
|
423
|
+
return [attr, true]
|
424
|
+
end
|
425
|
+
|
426
|
+
# Specify descending ordering for a given attribute passed to order_by.
|
427
|
+
def self.desc(attr)
|
428
|
+
return [attr, false]
|
429
|
+
end
|
430
|
+
|
425
431
|
def self.boolprop(op, l, r) # :nodoc:
|
426
432
|
badop = l.boolop? ? l : r
|
427
433
|
if l.boolop? || r.boolop?
|
data/lib/sequence.rb
CHANGED
@@ -113,12 +113,10 @@ module RethinkDB
|
|
113
113
|
# example, to sort first by name and then by social security
|
114
114
|
# number for the table <b>+people+</b>, you could do:
|
115
115
|
# people.order_by(:name, :ssn)
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
# will sort first by name in descending order, and then by ssn in ascending
|
121
|
-
# order.
|
116
|
+
# By default order_by sorts in ascending order. To explicitly specify the
|
117
|
+
# ordering wrap the attribute to be ordered by with r.asc or r.desc as in:
|
118
|
+
# people.order_by(r.desc(:name), :ssn)
|
119
|
+
# which sorts first by name from Z-A and then by ssn from 0-9.
|
122
120
|
def order_by(*orderings)
|
123
121
|
orderings.map!{|x| x.class == Array ? x : [x, true]}
|
124
122
|
self.class.new [:call, [:orderby, *orderings], [self]]
|
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:
|
4
|
+
hash: 85
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 6
|
10
|
-
-
|
11
|
-
version: 1.2.6.
|
10
|
+
- 1
|
11
|
+
version: 1.2.6.1
|
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:
|
19
|
+
date: 2013-01-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: json
|