arangorb 0.1.0 → 1.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.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +2 -2
- data/README.md +418 -123
- data/lib/ArangoRB_AQL.rb +90 -103
- data/lib/ArangoRB_Col.rb +476 -159
- data/lib/ArangoRB_DB.rb +305 -79
- data/lib/ArangoRB_Doc.rb +112 -114
- data/lib/ArangoRB_Edg.rb +81 -62
- data/lib/ArangoRB_Gra.rb +125 -76
- data/lib/ArangoRB_Index.rb +144 -0
- data/lib/ArangoRB_Ser.rb +439 -18
- data/lib/ArangoRB_Task.rb +136 -0
- data/lib/ArangoRB_Tra.rb +47 -42
- data/lib/ArangoRB_Tran.rb +48 -0
- data/lib/ArangoRB_User.rb +152 -0
- data/lib/ArangoRB_Ver.rb +74 -57
- data/lib/arangorb.rb +4 -0
- data/spec/arangoRB_helper.rb +2 -9
- data/spec/arangoRestart_helper.rb +14 -0
- data/spec/lib/{arangoAQL_helper.rb → 0.1.0/arangoAQL_helper.rb} +2 -21
- data/spec/lib/{arangoC_helper.rb → 0.1.0/arangoC_helper.rb} +40 -19
- data/spec/lib/{arangoDB_helper.rb → 0.1.0/arangoDB_helper.rb} +13 -13
- data/spec/lib/{arangoDoc_helper.rb → 0.1.0/arangoDoc_helper.rb} +10 -23
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -0
- data/spec/lib/{arangoG_helper.rb → 0.1.0/arangoG_helper.rb} +7 -21
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -0
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -0
- data/spec/lib/{arangoV_helper.rb → 0.1.0/arangoV_helper.rb} +6 -22
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -0
- data/spec/lib/1.0.0/arangoDB_helper.rb +81 -0
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -0
- data/spec/lib/1.0.0/arangoS_helper.rb +196 -0
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -0
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -0
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -0
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -0
- data/spec/spec_helper.rb +34 -0
- metadata +28 -15
- data/spec/lib/arangoE_helper.rb +0 -70
- data/spec/lib/arangoS_helper.rb +0 -28
- data/spec/lib/arangoT_helper.rb +0 -67
data/lib/ArangoRB_AQL.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# === AQL ===
|
2
2
|
|
3
|
-
class ArangoAQL <
|
4
|
-
def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database)
|
3
|
+
class ArangoAQL < ArangoServer
|
4
|
+
def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) # TESTED
|
5
5
|
if query.is_a?(String)
|
6
6
|
@query = query
|
7
7
|
elsif query.is_a?(ArangoAQL)
|
@@ -9,7 +9,15 @@ class ArangoAQL < ArangoS
|
|
9
9
|
else
|
10
10
|
raise "query should be String or ArangoAQL instance, not a #{query.class}"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
if database.is_a?(String)
|
14
|
+
@database = database
|
15
|
+
elsif database.is_a?(ArangoDatabase)
|
16
|
+
@database = database.database
|
17
|
+
else
|
18
|
+
raise "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
|
19
|
+
end
|
20
|
+
|
13
21
|
@batchSize = batchSize
|
14
22
|
@ttl = ttl
|
15
23
|
@cache = cache
|
@@ -29,7 +37,7 @@ class ArangoAQL < ArangoS
|
|
29
37
|
|
30
38
|
# === EXECUTE QUERY ===
|
31
39
|
|
32
|
-
def execute(count: true)
|
40
|
+
def execute(count: true) # TESTED
|
33
41
|
body = {
|
34
42
|
"query" => @query,
|
35
43
|
"count" => count,
|
@@ -39,33 +47,12 @@ class ArangoAQL < ArangoS
|
|
39
47
|
"options" => @options,
|
40
48
|
"bindVars" => @bindVars
|
41
49
|
}.delete_if{|k,v| v.nil?}
|
42
|
-
|
43
|
-
result = self.class.post("/_db/#{@database}/_api/cursor",
|
44
|
-
if
|
45
|
-
|
46
|
-
else
|
47
|
-
@count = result["count"]
|
48
|
-
@hasMore = result["hasMore"]
|
49
|
-
@id = result["id"]
|
50
|
-
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
51
|
-
@result = result["result"]
|
52
|
-
else
|
53
|
-
@result = result["result"].map{|x| ArangoDoc.new(
|
54
|
-
key: x["_key"],
|
55
|
-
collection: x["_id"].split("/")[0],
|
56
|
-
database: @database,
|
57
|
-
body: x
|
58
|
-
)}
|
59
|
-
end
|
60
|
-
return @@verbose ? result : self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def next
|
65
|
-
unless @hasMore
|
66
|
-
print "No other results"
|
50
|
+
request = @@request.merge({ :body => body.to_json })
|
51
|
+
result = self.class.post("/_db/#{@database}/_api/cursor", request)
|
52
|
+
if @@async == "store"
|
53
|
+
result.headers["x-arango-async-id"]
|
67
54
|
else
|
68
|
-
result =
|
55
|
+
result = result.parsed_response
|
69
56
|
if result["error"]
|
70
57
|
return @@verbose ? result : result["errorMessage"]
|
71
58
|
else
|
@@ -75,7 +62,7 @@ class ArangoAQL < ArangoS
|
|
75
62
|
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
76
63
|
@result = result["result"]
|
77
64
|
else
|
78
|
-
@result = result["result"].map{|x|
|
65
|
+
@result = result["result"].map{|x| ArangoDocument.new(
|
79
66
|
key: x["_key"],
|
80
67
|
collection: x["_id"].split("/")[0],
|
81
68
|
database: @database,
|
@@ -87,52 +74,85 @@ class ArangoAQL < ArangoS
|
|
87
74
|
end
|
88
75
|
end
|
89
76
|
|
77
|
+
def next # TESTED
|
78
|
+
unless @hasMore
|
79
|
+
print "No other results"
|
80
|
+
else
|
81
|
+
result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
|
82
|
+
if @@async == "store"
|
83
|
+
result.headers["x-arango-async-id"]
|
84
|
+
else
|
85
|
+
result = result.parsed_response
|
86
|
+
if result["error"]
|
87
|
+
return @@verbose ? result : result["errorMessage"]
|
88
|
+
else
|
89
|
+
@count = result["count"]
|
90
|
+
@hasMore = result["hasMore"]
|
91
|
+
@id = result["id"]
|
92
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
93
|
+
@result = result["result"]
|
94
|
+
else
|
95
|
+
@result = result["result"].map{|x| ArangoDocument.new(
|
96
|
+
key: x["_key"],
|
97
|
+
collection: x["_id"].split("/")[0],
|
98
|
+
database: @database,
|
99
|
+
body: x
|
100
|
+
)}
|
101
|
+
end
|
102
|
+
return @@verbose ? result : self
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
90
108
|
# === PROPERTY QUERY ===
|
91
109
|
|
92
|
-
def explain
|
110
|
+
def explain # TESTED
|
93
111
|
body = {
|
94
112
|
"query" => @query,
|
95
113
|
"options" => @options,
|
96
114
|
"bindVars" => @bindVars
|
97
115
|
}.delete_if{|k,v| v.nil?}
|
98
|
-
|
99
|
-
result = self.class.post("/_db/#{@database}/_api/explain",
|
100
|
-
return_result
|
116
|
+
request = @@request.merge({ :body => body.to_json })
|
117
|
+
result = self.class.post("/_db/#{@database}/_api/explain", request)
|
118
|
+
return_result result: result
|
101
119
|
end
|
102
120
|
|
103
|
-
def parse
|
121
|
+
def parse # TESTED
|
104
122
|
body = { "query" => @query }
|
105
|
-
|
106
|
-
result = self.class.post("/_db/#{@database}/_api/query",
|
107
|
-
return_result
|
123
|
+
request = @@request.merge({ :body => body.to_json })
|
124
|
+
result = self.class.post("/_db/#{@database}/_api/query", request)
|
125
|
+
return_result result: result
|
108
126
|
end
|
109
127
|
|
110
|
-
def properties
|
111
|
-
result = self.class.get("/_db/#{@database}/_api/query/properties")
|
112
|
-
return_result
|
128
|
+
def properties # TESTED
|
129
|
+
result = self.class.get("/_db/#{@database}/_api/query/properties", @@request)
|
130
|
+
return_result result: result
|
113
131
|
end
|
114
132
|
|
115
|
-
def current
|
116
|
-
self.class.get("/_db/#{@database}/_api/query/current")
|
133
|
+
def current # TESTED
|
134
|
+
result = self.class.get("/_db/#{@database}/_api/query/current", @@request)
|
135
|
+
return_result result: result
|
117
136
|
end
|
118
137
|
|
119
|
-
def slow
|
120
|
-
self.class.get("/_db/#{@database}/_api/query/slow")
|
138
|
+
def slow # TESTED
|
139
|
+
result = self.class.get("/_db/#{@database}/_api/query/slow", @@request)
|
140
|
+
return_result result: result
|
121
141
|
end
|
122
142
|
|
123
143
|
# === DELETE ===
|
124
144
|
|
125
|
-
def stopSlow
|
126
|
-
result = self.class.delete("/_db/#{@database}/_api/query/slow")
|
127
|
-
|
145
|
+
def stopSlow # TESTED
|
146
|
+
result = self.class.delete("/_db/#{@database}/_api/query/slow", @@request)
|
147
|
+
return_result result: result, caseTrue: true
|
128
148
|
end
|
129
149
|
|
130
|
-
def kill(id: @id)
|
131
|
-
result = self.class.delete("/_db/#{@database}/_api/query/#{id}")
|
132
|
-
|
150
|
+
def kill(id: @id) # TESTED
|
151
|
+
result = self.class.delete("/_db/#{@database}/_api/query/#{id}", @@request)
|
152
|
+
return_result result: result, caseTrue: true
|
133
153
|
end
|
134
154
|
|
135
|
-
def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil)
|
155
|
+
def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) # TESTED
|
136
156
|
body = {
|
137
157
|
"slowQueryThreshold" => slowQueryThreshold,
|
138
158
|
"enabled" => enabled,
|
@@ -140,62 +160,29 @@ class ArangoAQL < ArangoS
|
|
140
160
|
"trackSlowQueries" => trackSlowQueries,
|
141
161
|
"maxQueryStringLength" => maxQueryStringLength
|
142
162
|
}.delete_if{|k,v| v.nil?}
|
143
|
-
|
144
|
-
result = self.class.put("/_db/#{@database}/_api/query/properties",
|
145
|
-
return_result
|
146
|
-
end
|
147
|
-
|
148
|
-
# === CACHE ===
|
149
|
-
|
150
|
-
def clearCache
|
151
|
-
result = self.class.delete("/_db/#{@database}/_api/query-cache").parsed_response
|
152
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
153
|
-
end
|
154
|
-
|
155
|
-
def propertyCache
|
156
|
-
self.class.get("/_db/#{@database}/_api/query-cache/properties").parsed_response
|
157
|
-
end
|
158
|
-
|
159
|
-
def changePropertyCache(mode: nil, maxResults: nil)
|
160
|
-
body = { "mode" => mode, "maxResults" => maxResults }.delete_if{|k,v| v.nil?}
|
161
|
-
new_Document = { :body => body.to_json }
|
162
|
-
self.class.put("/_db/#{@database}/_api/query-cache/properties", new_Document).parsed_response
|
163
|
-
end
|
164
|
-
|
165
|
-
# === AQL FUNCTION ===
|
166
|
-
|
167
|
-
def createFunction(code:, name:, isDeterministic: nil)
|
168
|
-
body = {
|
169
|
-
"code" => code,
|
170
|
-
"name" => name,
|
171
|
-
"isDeterministic" => isDeterministic
|
172
|
-
}.delete_if{|k,v| v.nil?}
|
173
|
-
new_Document = { :body => body.to_json }
|
174
|
-
result = self.class.post("/_db/#{@database}/_api/aqlfunction", new_Document).parsed_response
|
175
|
-
return_result(result)
|
176
|
-
end
|
177
|
-
|
178
|
-
def deleteFunction(name:)
|
179
|
-
result = self.class.delete("/_db/#{@database}/_api/aqlfunction/#{name}").parsed_response
|
180
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
181
|
-
end
|
182
|
-
|
183
|
-
def functions
|
184
|
-
self.class.get("/_db/#{@database}/_api/aqlfunction").parsed_response
|
163
|
+
request = @@request.merge({ :body => body.to_json })
|
164
|
+
result = self.class.put("/_db/#{@database}/_api/query/properties", request)
|
165
|
+
return_result result: result
|
185
166
|
end
|
186
167
|
|
187
168
|
# === UTILITY ===
|
188
169
|
|
189
|
-
def return_result(result)
|
190
|
-
if @@
|
191
|
-
result
|
170
|
+
def return_result(result:, caseTrue: false)
|
171
|
+
if @@async == "store"
|
172
|
+
result.headers["x-arango-async-id"]
|
192
173
|
else
|
193
|
-
|
194
|
-
|
195
|
-
else
|
196
|
-
result.delete("error")
|
197
|
-
result.delete("code")
|
174
|
+
result = result.parsed_response
|
175
|
+
if @@verbose
|
198
176
|
result
|
177
|
+
else
|
178
|
+
if result.is_a?(Hash) && result["error"]
|
179
|
+
result["errorMessage"]
|
180
|
+
else
|
181
|
+
return true if caseTrue
|
182
|
+
result.delete("error")
|
183
|
+
result.delete("code")
|
184
|
+
result
|
185
|
+
end
|
199
186
|
end
|
200
187
|
end
|
201
188
|
end
|