rethinkdb 1.2.6.1 → 1.4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/exc.rb +30 -0
- data/lib/func.rb +156 -0
- data/lib/net.rb +137 -177
- data/lib/ql2.pb.rb +615 -0
- data/lib/rethinkdb.rb +70 -9
- data/lib/rpp.rb +191 -0
- data/lib/shim.rb +101 -0
- metadata +13 -21
- data/lib/base_classes.rb +0 -39
- data/lib/bt.rb +0 -148
- data/lib/data_collectors.rb +0 -35
- data/lib/jsons.rb +0 -140
- data/lib/protob_compiler.rb +0 -137
- data/lib/query.rb +0 -111
- data/lib/query_language.pb.rb +0 -687
- data/lib/rql.rb +0 -472
- data/lib/sequence.rb +0 -350
- data/lib/streams.rb +0 -101
- data/lib/tables.rb +0 -123
- data/lib/utils.rb +0 -118
- data/lib/writes.rb +0 -24
data/lib/rethinkdb.rb
CHANGED
@@ -1,16 +1,77 @@
|
|
1
1
|
# Copyright 2010-2012 RethinkDB, all rights reserved.
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'ql2.pb.rb'
|
4
4
|
require 'socket'
|
5
5
|
require 'pp'
|
6
6
|
|
7
|
-
load '
|
8
|
-
load 'utils.rb'
|
9
|
-
load 'protob_compiler.rb'
|
10
|
-
|
7
|
+
load 'exc.rb'
|
11
8
|
load 'net.rb'
|
9
|
+
load 'shim.rb'
|
10
|
+
load 'func.rb'
|
11
|
+
load 'rpp.rb'
|
12
|
+
|
13
|
+
class Term
|
14
|
+
attr_accessor :context
|
15
|
+
attr_accessor :is_error
|
16
|
+
|
17
|
+
def bt_tag bt
|
18
|
+
@is_error = true
|
19
|
+
begin
|
20
|
+
return if bt == []
|
21
|
+
frame, sub_bt = bt[0], bt [1..-1]
|
22
|
+
if frame.class == String
|
23
|
+
optargs.each {|optarg|
|
24
|
+
if optarg.key == frame
|
25
|
+
@is_error = false
|
26
|
+
optarg.val.bt_tag(sub_bt)
|
27
|
+
end
|
28
|
+
}
|
29
|
+
else
|
30
|
+
@is_error = false
|
31
|
+
args[frame].bt_tag(sub_bt)
|
32
|
+
end
|
33
|
+
rescue StandardError => e
|
34
|
+
@is_error = true
|
35
|
+
$stderr.puts "ERROR: Failed to parse backtrace (we'll take our best guess)."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module RethinkDB
|
41
|
+
module Shortcuts
|
42
|
+
def r(*args)
|
43
|
+
args == [] ? RQL.new : RQL.new.expr(*args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Utils
|
48
|
+
def get_mname(i = 0)
|
49
|
+
caller[i]=~/`(.*?)'/
|
50
|
+
$1
|
51
|
+
end
|
52
|
+
def unbound_if (x, name = nil)
|
53
|
+
name = get_mname(1) if not name
|
54
|
+
raise NoMethodError, "undefined method `#{name}'" if x
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class RQL
|
59
|
+
include Utils
|
60
|
+
|
61
|
+
attr_accessor :body, :bitop
|
62
|
+
|
63
|
+
def initialize(body = nil, bitop = nil)
|
64
|
+
@body = body
|
65
|
+
@bitop = bitop
|
66
|
+
@body.context = RPP.sanitize_context caller if @body
|
67
|
+
end
|
12
68
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
69
|
+
def pp
|
70
|
+
unbound_if !@body
|
71
|
+
RethinkDB::RPP.pp(@body)
|
72
|
+
end
|
73
|
+
def inspect
|
74
|
+
@body ? pp : super
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/rpp.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'prettyprint'
|
3
|
+
|
4
|
+
module RethinkDB
|
5
|
+
module RPP
|
6
|
+
def self.sanitize_context context
|
7
|
+
if __FILE__ =~ /^(.*\/)[^\/]+.rb$/
|
8
|
+
prefix = $1;
|
9
|
+
context.reject{|x| x =~ /^#{prefix}/}
|
10
|
+
else
|
11
|
+
context
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.pp_int_optargs(q, optargs, pre_dot = false)
|
16
|
+
q.text("r(") if pre_dot
|
17
|
+
q.group(1, "{", "}") {
|
18
|
+
optargs.each_with_index {|optarg, i|
|
19
|
+
if i != 0
|
20
|
+
q.text(",")
|
21
|
+
q.breakable
|
22
|
+
end
|
23
|
+
q.text(":#{optarg.key} =>")
|
24
|
+
q.nest(2) {
|
25
|
+
q.breakable
|
26
|
+
pp_int(q, optarg.val)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
q.text(")") if pre_dot
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.pp_int_args(q, args, pre_dot = false)
|
34
|
+
q.text("r(") if pre_dot
|
35
|
+
q.group(1, "[", "]") {
|
36
|
+
args.each_with_index {|arg, i|
|
37
|
+
if i != 0
|
38
|
+
q.text(",")
|
39
|
+
q.breakable
|
40
|
+
end
|
41
|
+
pp_int(q, arg)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
q.text(")") if pre_dot
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.pp_int_datum(q, dat, pre_dot)
|
48
|
+
q.text("r(") if pre_dot
|
49
|
+
q.text(Shim.datum_to_native(dat).inspect)
|
50
|
+
q.text(")") if pre_dot
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.pp_int_func(q, func)
|
54
|
+
func_args = func.args[0].args.map{|x| x.datum.r_num}
|
55
|
+
func_body = func.args[1]
|
56
|
+
q.text(" ")
|
57
|
+
q.group(0, "{", "}") {
|
58
|
+
if func_args != []
|
59
|
+
q.text(func_args.map{|x| :"var_#{x}"}.inspect.gsub(/\[|\]/,"|").gsub(":",""))
|
60
|
+
end
|
61
|
+
q.nest(2) {
|
62
|
+
q.breakable
|
63
|
+
pp_int(q, func_body)
|
64
|
+
}
|
65
|
+
q.breakable('')
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.can_prefix (name, args)
|
70
|
+
return false if name == "db" || name == "funcall"
|
71
|
+
return false if args.size == 1 && args[0].type == Term::TermType::DATUM
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
def self.pp_int(q, term, pre_dot=false)
|
75
|
+
q.text("\x7", 0) if term.is_error
|
76
|
+
@@context = term.context if term.is_error
|
77
|
+
|
78
|
+
if term.type == Term::TermType::DATUM
|
79
|
+
res = pp_int_datum(q, term.datum, pre_dot)
|
80
|
+
q.text("\x7", 0) if term.is_error
|
81
|
+
return res
|
82
|
+
end
|
83
|
+
|
84
|
+
if term.type == Term::TermType::VAR
|
85
|
+
q.text("var_")
|
86
|
+
res = pp_int_datum(q, term.args[0].datum, false)
|
87
|
+
q.text("\x7", 0) if term.is_error
|
88
|
+
return res
|
89
|
+
elsif term.type == Term::TermType::FUNC
|
90
|
+
q.text("r(") if pre_dot
|
91
|
+
q.text("lambda")
|
92
|
+
res = pp_int_func(q, term)
|
93
|
+
q.text(")") if pre_dot
|
94
|
+
q.text("\x7", 0) if term.is_error
|
95
|
+
return res
|
96
|
+
elsif term.type == Term::TermType::MAKE_OBJ
|
97
|
+
res = pp_int_optargs(q, term.optargs, pre_dot)
|
98
|
+
q.text("\x7", 0) if term.is_error
|
99
|
+
return res
|
100
|
+
elsif term.type == Term::TermType::MAKE_ARRAY
|
101
|
+
res = pp_int_args(q, term.args, pre_dot)
|
102
|
+
q.text("\x7", 0) if term.is_error
|
103
|
+
return res
|
104
|
+
end
|
105
|
+
|
106
|
+
name = term.type.to_s.downcase
|
107
|
+
args = term.args.dup
|
108
|
+
optargs = term.optargs.dup
|
109
|
+
|
110
|
+
if can_prefix(name, args) && first_arg = args.shift
|
111
|
+
pp_int(q, first_arg, true)
|
112
|
+
else
|
113
|
+
q.text("r")
|
114
|
+
end
|
115
|
+
if name == "getattr"
|
116
|
+
argstart, argstop = "[", "]"
|
117
|
+
else
|
118
|
+
q.text(".")
|
119
|
+
q.text(name)
|
120
|
+
argstart, argstop = "(", ")"
|
121
|
+
end
|
122
|
+
|
123
|
+
func = args[-1] && args[-1].type == Term::TermType::FUNC && args.pop
|
124
|
+
|
125
|
+
if args != [] || optargs != []
|
126
|
+
q.group(0, argstart, argstop) {
|
127
|
+
pushed = nil
|
128
|
+
q.nest(2) {
|
129
|
+
args.each {|arg|
|
130
|
+
if !pushed
|
131
|
+
pushed = true
|
132
|
+
q.breakable('')
|
133
|
+
else
|
134
|
+
q.text(",")
|
135
|
+
q.breakable
|
136
|
+
end
|
137
|
+
pp_int(q, arg)
|
138
|
+
}
|
139
|
+
if optargs != []
|
140
|
+
if pushed
|
141
|
+
q.text(",")
|
142
|
+
q.breakable
|
143
|
+
end
|
144
|
+
pp_int_optargs(q, optargs)
|
145
|
+
end
|
146
|
+
if func && name == "grouped_map_reduce"
|
147
|
+
q.text(",")
|
148
|
+
q.breakable
|
149
|
+
q.text("lambda")
|
150
|
+
pp_int_func(q, func)
|
151
|
+
func = nil
|
152
|
+
end
|
153
|
+
}
|
154
|
+
q.breakable('')
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
pp_int_func(q, func) if func
|
159
|
+
q.text("\x7", 0) if term.is_error
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.pp term
|
163
|
+
begin
|
164
|
+
@@context = nil
|
165
|
+
q = PrettyPrint.new
|
166
|
+
pp_int(q, term, true)
|
167
|
+
q.flush
|
168
|
+
|
169
|
+
in_bt = false
|
170
|
+
q.output.split("\n").map {|line|
|
171
|
+
line = line.gsub(/^ */) {|x| x+"\x7"} if in_bt
|
172
|
+
arr = line.split("\x7")
|
173
|
+
if arr[1]
|
174
|
+
in_bt = !(arr[2] || (line[-1] == 0x7))
|
175
|
+
[arr.join(""), " "*arr[0].size + "^"*arr[1].size]
|
176
|
+
else
|
177
|
+
line
|
178
|
+
end
|
179
|
+
}.flatten.join("\n") +
|
180
|
+
(@@context ?
|
181
|
+
"\nErronious_Portion_Constructed:\n" +
|
182
|
+
"#{@@context.map{|x| "\tfrom "+x}.join("\n")}" +
|
183
|
+
"\nCalled:" : "")
|
184
|
+
rescue Exception => e
|
185
|
+
raise e
|
186
|
+
"AN ERROR OCCURED DURING PRETTY-PRINTING:\n#{e.inspect}\n" +
|
187
|
+
"FALLING BACK TO PROTOBUF PRETTY-PRINTER.\n#{@term.inspect}"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
data/lib/shim.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module RethinkDB
|
2
|
+
module Shim
|
3
|
+
def self.datum_to_native d
|
4
|
+
raise RqlRuntimeError, "SHENANIGANS" if d.class != Datum
|
5
|
+
dt = Datum::DatumType
|
6
|
+
case d.type
|
7
|
+
when dt::R_NUM then d.r_num
|
8
|
+
when dt::R_STR then d.r_str
|
9
|
+
when dt::R_BOOL then d.r_bool
|
10
|
+
when dt::R_NULL then nil
|
11
|
+
when dt::R_ARRAY then d.r_array.map{|d2| datum_to_native d2}
|
12
|
+
when dt::R_OBJECT then Hash[d.r_object.map{|x| [x.key, datum_to_native(x.val)]}]
|
13
|
+
else raise RqlRuntimeError, "Unimplemented."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.response_to_native(r, orig_term)
|
18
|
+
rt = Response::ResponseType
|
19
|
+
if r.backtrace
|
20
|
+
bt = r.backtrace.frames.map {|x|
|
21
|
+
x.type == Frame::FrameType::POS ? x.pos : x.opt
|
22
|
+
}
|
23
|
+
else
|
24
|
+
bt = []
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
case r.type
|
29
|
+
when rt::SUCCESS_ATOM then datum_to_native(r.response[0])
|
30
|
+
when rt::SUCCESS_PARTIAL then r.response.map{|d| datum_to_native(d)}
|
31
|
+
when rt::SUCCESS_SEQUENCE then r.response.map{|d| datum_to_native(d)}
|
32
|
+
when rt::RUNTIME_ERROR then
|
33
|
+
raise RqlRuntimeError, "#{r.response[0].r_str}"
|
34
|
+
when rt::COMPILE_ERROR then # TODO: remove?
|
35
|
+
raise RqlCompileError, "#{r.response[0].r_str}"
|
36
|
+
when rt::CLIENT_ERROR then
|
37
|
+
raise RqlDriverError, "#{r.response[0].r_str}"
|
38
|
+
else raise RqlRuntimeError, "Unexpected response: #{r.inspect}"
|
39
|
+
end
|
40
|
+
rescue RqlError => e
|
41
|
+
term = orig_term.dup
|
42
|
+
term.bt_tag(bt)
|
43
|
+
$t = term
|
44
|
+
raise e.class, "#{e.message}\nBacktrace:\n#{RPP.pp(term)}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.native_to_datum_term x
|
49
|
+
dt = Datum::DatumType
|
50
|
+
d = Datum.new
|
51
|
+
case x.class.hash
|
52
|
+
when Fixnum.hash then d.type = dt::R_NUM; d.r_num = x
|
53
|
+
when Float.hash then d.type = dt::R_NUM; d.r_num = x
|
54
|
+
when Bignum.hash then d.type = dt::R_NUM; d.r_num = x
|
55
|
+
when String.hash then d.type = dt::R_STR; d.r_str = x
|
56
|
+
when Symbol.hash then d.type = dt::R_STR; d.r_str = x.to_s
|
57
|
+
when TrueClass.hash then d.type = dt::R_BOOL; d.r_bool = x
|
58
|
+
when FalseClass.hash then d.type = dt::R_BOOL; d.r_bool = x
|
59
|
+
when NilClass.hash then d.type = dt::R_NULL
|
60
|
+
else raise RqlRuntimeError, "UNREACHABLE"
|
61
|
+
end
|
62
|
+
t = Term.new
|
63
|
+
t.type = Term::TermType::DATUM
|
64
|
+
t.datum = d
|
65
|
+
return t
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class RQL
|
70
|
+
def to_pb; @body; end
|
71
|
+
|
72
|
+
def expr(x)
|
73
|
+
unbound_if @body
|
74
|
+
return x if x.class == RQL
|
75
|
+
datum_types = [Fixnum, Float, Bignum, String, Symbol, TrueClass, FalseClass, NilClass]
|
76
|
+
if datum_types.map{|y| y.hash}.include? x.class.hash
|
77
|
+
return RQL.new(Shim.native_to_datum_term(x))
|
78
|
+
end
|
79
|
+
|
80
|
+
t = Term.new
|
81
|
+
case x.class.hash
|
82
|
+
when Array.hash
|
83
|
+
t.type = Term::TermType::MAKE_ARRAY
|
84
|
+
t.args = x.map{|y| expr(y).to_pb}
|
85
|
+
when Hash.hash
|
86
|
+
t.type = Term::TermType::MAKE_OBJ
|
87
|
+
t.optargs = x.map{|k,v| ap = Term::AssocPair.new;
|
88
|
+
ap.key = k.to_s; ap.val = expr(v).to_pb; ap}
|
89
|
+
when Proc.hash
|
90
|
+
t = RQL.new.new_func(&x).to_pb
|
91
|
+
else raise RqlDriverError, "r.expr can't handle #{x.inspect} of type #{x.class}"
|
92
|
+
end
|
93
|
+
|
94
|
+
return RQL.new(t)
|
95
|
+
end
|
96
|
+
|
97
|
+
def coerce(other)
|
98
|
+
[RQL.new.expr(other), self]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
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: 127
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
version: 1.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
- 0
|
11
|
+
version: 1.4.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-
|
19
|
+
date: 2013-03-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: json
|
@@ -55,21 +55,13 @@ extensions: []
|
|
55
55
|
extra_rdoc_files: []
|
56
56
|
|
57
57
|
files:
|
58
|
-
- lib/
|
59
|
-
- lib/
|
60
|
-
- lib/query.rb
|
61
|
-
- lib/rethinkdb.rb
|
62
|
-
- lib/bt.rb
|
63
|
-
- lib/writes.rb
|
64
|
-
- lib/rql.rb
|
65
|
-
- lib/utils.rb
|
66
|
-
- lib/protob_compiler.rb
|
58
|
+
- lib/exc.rb
|
59
|
+
- lib/func.rb
|
67
60
|
- lib/net.rb
|
68
|
-
- lib/
|
69
|
-
- lib/
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/data_collectors.rb
|
61
|
+
- lib/ql2.pb.rb
|
62
|
+
- lib/rethinkdb.rb
|
63
|
+
- lib/rpp.rb
|
64
|
+
- lib/shim.rb
|
73
65
|
homepage: http://rethinkdb.com
|
74
66
|
licenses:
|
75
67
|
- Apache-2
|
@@ -99,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
91
|
requirements: []
|
100
92
|
|
101
93
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.7.2
|
103
95
|
signing_key:
|
104
96
|
specification_version: 3
|
105
97
|
summary: This package provides the Ruby driver library for the RethinkDB database server.
|
data/lib/base_classes.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# Copyright 2010-2012 RethinkDB, all rights reserved.
|
2
|
-
#TODO: toplevel doc
|
3
|
-
module RethinkDB
|
4
|
-
class RQL_Query; end
|
5
|
-
class Read_Query < RQL_Query # :nodoc:
|
6
|
-
end
|
7
|
-
class Write_Query < RQL_Query # :nodoc:
|
8
|
-
end
|
9
|
-
class Meta_Query < RQL_Query # :nodoc:
|
10
|
-
end
|
11
|
-
|
12
|
-
module Sequence; end
|
13
|
-
class JSON_Expression < Read_Query; include Sequence; end
|
14
|
-
class Single_Row_Selection < JSON_Expression; end
|
15
|
-
class Stream_Expression < Read_Query; include Sequence; end
|
16
|
-
class Multi_Row_Selection < Stream_Expression; end
|
17
|
-
|
18
|
-
class Database; end
|
19
|
-
class Table; end
|
20
|
-
|
21
|
-
class Connection; end
|
22
|
-
class Query_Results; include Enumerable; end
|
23
|
-
|
24
|
-
module RQL; end
|
25
|
-
|
26
|
-
# Shortcuts to easily build RQL queries.
|
27
|
-
module Shortcuts
|
28
|
-
# The only shortcut right now. May be used as a wrapper to create
|
29
|
-
# RQL values or as a shortcut to access function in the RQL
|
30
|
-
# namespace. For example, the following are equivalent:
|
31
|
-
# r.add(1, 2)
|
32
|
-
# RethinkDB::RQL.add(1, 2)
|
33
|
-
# r(1) + r(2)
|
34
|
-
# r(3)
|
35
|
-
def r(*args)
|
36
|
-
(args == [] ) ? RethinkDB::RQL : RQL.expr(*args)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|