arangorb 1.0.0 → 1.1.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 +1 -1
- data/README.md +26 -1
- data/lib/ArangoRB_AQL.rb +30 -60
- data/lib/ArangoRB_Col.rb +89 -258
- data/lib/ArangoRB_DB.rb +18 -90
- data/lib/ArangoRB_Doc.rb +46 -45
- data/lib/ArangoRB_Edg.rb +48 -57
- data/lib/ArangoRB_Gra.rb +66 -105
- data/lib/ArangoRB_Index.rb +41 -72
- data/lib/ArangoRB_Ser.rb +21 -65
- data/lib/ArangoRB_Task.rb +33 -57
- data/lib/ArangoRB_Tra.rb +31 -35
- data/lib/ArangoRB_Tran.rb +17 -15
- data/lib/ArangoRB_User.rb +54 -71
- data/lib/ArangoRB_Ver.rb +48 -57
- data/spec/arangoRB_helper.rb +1 -0
- data/spec/lib/0.1.0/arangoC_helper.rb +2 -2
- data/spec/lib/0.1.0/arangoDoc_helper.rb +1 -1
- data/spec/lib/0.1.0/arangoE_helper.rb +1 -1
- data/spec/lib/0.1.0/arangoS_helper.rb +3 -3
- data/spec/lib/0.1.0/arangoT_helper.rb +4 -4
- data/spec/lib/0.1.0/arangoV_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoDB_helper.rb +0 -33
- data/spec/lib/1.0.0/arangoS_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoTa_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoTr_helper.rb +1 -1
- data/spec/lib/1.1.0/arangoRB_helper.rb +144 -0
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +18 -0
- data/spec/lib/arangoRB_1.1.0_helper.rb +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db23869df50a9624a7f54598b85fdc08b776fb6c
|
4
|
+
data.tar.gz: e4cd9e680e9f71b40357b7d4bc08f3f397f63982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4149062e4f5b9a3883769c54b2ba889b672477773ef60fd9364a72648519054aa79ae28ef8ba8a76597a374a07de434175f669084e5d6d68bc56aa091e60ae61
|
7
|
+
data.tar.gz: a2ae7171adcb75443f86d4522940615d3220dd50f08e672b1e5699fe0a700651cf712073ca5a7ac0a7b71fb5a20cd90c4e3c264820edc4aa4a0b3beace5dd25f
|
data/ArangoRB.gemspec
CHANGED
data/README.md
CHANGED
@@ -236,6 +236,15 @@ myDatabase.graphs # Obtain an Array with the available graphs in the selected D
|
|
236
236
|
myDatabase.functions # Obtain an Array with the available functions in the selected Database
|
237
237
|
```
|
238
238
|
|
239
|
+
It is possible to access its Collections and Graphs by their ids.
|
240
|
+
|
241
|
+
``` ruby
|
242
|
+
myDatabase["MyCollection"] # where "MyCollection" is the id of the collection
|
243
|
+
myDatabase.collection("MyCollection")
|
244
|
+
myDatabase.graph("MyGraph")
|
245
|
+
```
|
246
|
+
|
247
|
+
|
239
248
|
### Query
|
240
249
|
|
241
250
|
ArangoDatabase instances can manage the queries used in their Database.
|
@@ -337,6 +346,16 @@ Truncate will delete all the Documents inside the selected Collection.
|
|
337
346
|
|
338
347
|
### Retrieve information
|
339
348
|
|
349
|
+
It is possible to access its Documents and its database.
|
350
|
+
|
351
|
+
``` ruby
|
352
|
+
myCollection["MyDocument"]
|
353
|
+
myDatabase.document("MyDocument")
|
354
|
+
myDatabase.database
|
355
|
+
```
|
356
|
+
|
357
|
+
For other information
|
358
|
+
|
340
359
|
``` ruby
|
341
360
|
myCollection.retrieve # Retrieve the selected Collection
|
342
361
|
myCollection.indexes # Return a list of all used Indexes in the Collection
|
@@ -348,7 +367,7 @@ myCollection.revision # Return collection revision id
|
|
348
367
|
myCollection.checksum # Return checksum for the Collection
|
349
368
|
```
|
350
369
|
|
351
|
-
To retrieve the documents of a Collection you can use:
|
370
|
+
To retrieve all the documents of a Collection you can use:
|
352
371
|
|
353
372
|
``` ruby
|
354
373
|
myCollection.documents
|
@@ -544,6 +563,8 @@ myDocument.destroy
|
|
544
563
|
|
545
564
|
``` ruby
|
546
565
|
myDocument.retrieve # Retrieve Document
|
566
|
+
myDocument.collection # Retrieve Collection of the Document
|
567
|
+
myDocument.database # Retrieve Database of the Document
|
547
568
|
myDocument.retrieve_edges collection: myEdgeCollection # Retrieve all myEdgeCollection edges connected with the Document
|
548
569
|
myDocument.any(myEdgeCollection) # Retrieve all myEdgeCollection edges connected with the Document
|
549
570
|
myDocument.in(myEdgeCollection) # Retrieve all myEdgeCollection edges coming in the Document
|
@@ -601,6 +622,7 @@ myGraph = ArangoGraph.new # By using the defauly Database and Graph
|
|
601
622
|
``` ruby
|
602
623
|
myGraph.create # create a new Graph
|
603
624
|
myGraph.retrieve # retrieve the Graph
|
625
|
+
myGraph.database # retrieve database of the Graph
|
604
626
|
myGraph.destroy # destroy the Graph
|
605
627
|
```
|
606
628
|
|
@@ -636,6 +658,7 @@ To use ArangoVertex, the Collection of the Vertex needs to be added either to th
|
|
636
658
|
myVertex = ArangoVertex.new key: "newVertex", body: {"value" => 3}, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
|
637
659
|
myVertex.create # create a new Document in the Graph
|
638
660
|
myVertex.retrieve # retrieve a Document
|
661
|
+
myVertex.graph # Retrieve Graph of the Document
|
639
662
|
myVertex.replace body: {"value" => 6} # replace the Document
|
640
663
|
myVertex.update body: {"value" => 6} # update the Document
|
641
664
|
myVertex.destroy # delete the Document
|
@@ -650,6 +673,7 @@ To use ArangoEdge, the Collection of the Edge needs to be added to the EdgeColle
|
|
650
673
|
myEdge = ArangoEdge.new key: "newVertex", body: {"value" => 3}, from: myArangoDocument, to: myArangoDocument, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
|
651
674
|
myEdge.create # create a new Document of type Edge in the Graph
|
652
675
|
myEdge.retrieve # retrieve a Document
|
676
|
+
myEdge.graph # Retrieve Graph of the Document
|
653
677
|
myEdge.replace body: {"value" => 6} # replace the Document
|
654
678
|
myEdge.update body: {"value" => 6} # update the Document
|
655
679
|
myEdge.destroy # delete the Document
|
@@ -733,6 +757,7 @@ myUser = ArangoUser.new user: "MyUser", password: "password"
|
|
733
757
|
|
734
758
|
``` ruby
|
735
759
|
myUser.retrieve # Retrieve User
|
760
|
+
myUser["MyDatabase"] # Retrieve database if the user can access it
|
736
761
|
myUser.create # Create a new User
|
737
762
|
myUser.replace active: false # Replace User
|
738
763
|
myUser.update active: false # Update User
|
data/lib/ArangoRB_AQL.rb
CHANGED
@@ -31,10 +31,16 @@ class ArangoAQL < ArangoServer
|
|
31
31
|
end
|
32
32
|
|
33
33
|
attr_accessor :query, :batchSize, :ttl, :cache, :options, :bindVars
|
34
|
-
attr_reader :count, :
|
34
|
+
attr_reader :count, :count, :hasMore, :id, :result
|
35
35
|
alias size batchSize
|
36
36
|
alias size= batchSize=
|
37
37
|
|
38
|
+
# === RETRIEVE ===
|
39
|
+
|
40
|
+
def database
|
41
|
+
ArangoDatabase.new(database: @database)
|
42
|
+
end
|
43
|
+
|
38
44
|
# === EXECUTE QUERY ===
|
39
45
|
|
40
46
|
def execute(count: true) # TESTED
|
@@ -49,29 +55,18 @@ class ArangoAQL < ArangoServer
|
|
49
55
|
}.delete_if{|k,v| v.nil?}
|
50
56
|
request = @@request.merge({ :body => body.to_json })
|
51
57
|
result = self.class.post("/_db/#{@database}/_api/cursor", request)
|
52
|
-
if @@async == "store"
|
53
|
-
|
58
|
+
return result.headers["x-arango-async-id"]if @@async == "store"
|
59
|
+
result = result.parsed_response
|
60
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
61
|
+
@count = result["count"]
|
62
|
+
@hasMore = result["hasMore"]
|
63
|
+
@id = result["id"]
|
64
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
65
|
+
@result = result["result"]
|
54
66
|
else
|
55
|
-
result = result.
|
56
|
-
if result["error"]
|
57
|
-
return @@verbose ? result : result["errorMessage"]
|
58
|
-
else
|
59
|
-
@count = result["count"]
|
60
|
-
@hasMore = result["hasMore"]
|
61
|
-
@id = result["id"]
|
62
|
-
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
63
|
-
@result = result["result"]
|
64
|
-
else
|
65
|
-
@result = result["result"].map{|x| ArangoDocument.new(
|
66
|
-
key: x["_key"],
|
67
|
-
collection: x["_id"].split("/")[0],
|
68
|
-
database: @database,
|
69
|
-
body: x
|
70
|
-
)}
|
71
|
-
end
|
72
|
-
return @@verbose ? result : self
|
73
|
-
end
|
67
|
+
@result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
|
74
68
|
end
|
69
|
+
return @@verbose ? result : self
|
75
70
|
end
|
76
71
|
|
77
72
|
def next # TESTED
|
@@ -79,29 +74,18 @@ class ArangoAQL < ArangoServer
|
|
79
74
|
print "No other results"
|
80
75
|
else
|
81
76
|
result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
|
82
|
-
if @@async == "store"
|
83
|
-
|
77
|
+
return result.headers["x-arango-async-id"]if @@async == "store"
|
78
|
+
result = result.parsed_response
|
79
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
80
|
+
@count = result["count"]
|
81
|
+
@hasMore = result["hasMore"]
|
82
|
+
@id = result["id"]
|
83
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
84
|
+
@result = result["result"]
|
84
85
|
else
|
85
|
-
result = result.
|
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
|
86
|
+
@result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
|
104
87
|
end
|
88
|
+
return @@verbose ? result : self
|
105
89
|
end
|
106
90
|
end
|
107
91
|
|
@@ -168,22 +152,8 @@ class ArangoAQL < ArangoServer
|
|
168
152
|
# === UTILITY ===
|
169
153
|
|
170
154
|
def return_result(result:, caseTrue: false)
|
171
|
-
if @@async == "store"
|
172
|
-
|
173
|
-
|
174
|
-
result = result.parsed_response
|
175
|
-
if @@verbose
|
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
|
186
|
-
end
|
187
|
-
end
|
155
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
156
|
+
result = result.parsed_response
|
157
|
+
@@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : caseTrue ? true : result
|
188
158
|
end
|
189
159
|
end
|
data/lib/ArangoRB_Col.rb
CHANGED
@@ -36,7 +36,19 @@ class ArangoCollection < ArangoServer
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
attr_reader :
|
39
|
+
attr_reader :collection, :body, :type
|
40
|
+
alias name collection
|
41
|
+
|
42
|
+
# === RETRIEVE ===
|
43
|
+
|
44
|
+
def [](document_name)
|
45
|
+
ArangoDocument.new(key: document_name, collection: @collection, database: @database)
|
46
|
+
end
|
47
|
+
alias document []
|
48
|
+
|
49
|
+
def database
|
50
|
+
ArangoDatabase.new(database: @database)
|
51
|
+
end
|
40
52
|
|
41
53
|
# === GET ===
|
42
54
|
|
@@ -108,29 +120,11 @@ class ArangoCollection < ArangoServer
|
|
108
120
|
end
|
109
121
|
|
110
122
|
def create_document(document: {}, waitForSync: nil, returnNew: nil) # TESTED
|
111
|
-
# if document.is_a? Hash
|
112
|
-
# body = document
|
113
|
-
# elsif document.is_a? ArangoDocument
|
114
|
-
# body = document.body
|
115
|
-
# elsif document.is_a? Array
|
116
|
-
# body = document.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
|
117
|
-
# else
|
118
|
-
# raise "document should be Hash, an ArangoDocument instance or an Array of Hashes or ArangoDocument instances"
|
119
|
-
# end
|
120
123
|
ArangoDocument.create(body: document, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
121
124
|
end
|
122
125
|
alias create_vertex create_document
|
123
126
|
|
124
127
|
def create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil) # TESTED
|
125
|
-
# if document.is_a? Hash
|
126
|
-
# body = document
|
127
|
-
# elsif document.is_a? ArangoDocument
|
128
|
-
# body = document.body
|
129
|
-
# elsif document.is_a? Array
|
130
|
-
# body = document.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
|
131
|
-
# else
|
132
|
-
# raise "document should be Hash, an ArangoDocument instance or an Array of Hashes or ArangoDocument instances"
|
133
|
-
# end
|
134
128
|
ArangoDocument.create_edge(body: document, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
135
129
|
end
|
136
130
|
|
@@ -191,23 +185,12 @@ class ArangoCollection < ArangoServer
|
|
191
185
|
}.delete_if{|k,v| v.nil?}.to_json
|
192
186
|
request = @@request.merge({ :body => body })
|
193
187
|
result = self.class.put("/_db/#{@database}/_api/simple/all-keys", request)
|
194
|
-
if @@async == "store"
|
195
|
-
|
188
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
189
|
+
result = result.parsed_response
|
190
|
+
if type.nil?
|
191
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| value = self.class.get(x).parsed_response; ArangoDocument.new(key: value["_key"], collection: @collection, body: value)}
|
196
192
|
else
|
197
|
-
result
|
198
|
-
if type.nil?
|
199
|
-
if @@verbose
|
200
|
-
result
|
201
|
-
else
|
202
|
-
if result["error"]
|
203
|
-
result["errorMessage"]
|
204
|
-
else
|
205
|
-
result["result"].map{|x| value = self.class.get(x).parsed_response; ArangoDocument.new(key: value["_key"], collection: @collection, body: value)}
|
206
|
-
end
|
207
|
-
end
|
208
|
-
else
|
209
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
|
210
|
-
end
|
193
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
|
211
194
|
end
|
212
195
|
end
|
213
196
|
|
@@ -220,20 +203,9 @@ class ArangoCollection < ArangoServer
|
|
220
203
|
}.delete_if{|k,v| v.nil?}.to_json
|
221
204
|
request = @@request.merge({ :body => body })
|
222
205
|
result = self.class.put("/_db/#{@database}/_api/simple/all", request)
|
223
|
-
if @@async == "store"
|
224
|
-
|
225
|
-
|
226
|
-
result = result.parsed_response
|
227
|
-
if @@verbose
|
228
|
-
result
|
229
|
-
else
|
230
|
-
if result["error"]
|
231
|
-
result["errorMessage"]
|
232
|
-
else
|
233
|
-
result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
206
|
+
result.headers["x-arango-async-id"] if @@async == "store"
|
207
|
+
result = result.parsed_response
|
208
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
237
209
|
end
|
238
210
|
|
239
211
|
def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) # TESTED
|
@@ -246,20 +218,9 @@ class ArangoCollection < ArangoServer
|
|
246
218
|
}.delete_if{|k,v| v.nil?}.to_json
|
247
219
|
request = @@request.merge({ :body => body })
|
248
220
|
result = self.class.put("/_db/#{@database}/_api/simple/by-example", request)
|
249
|
-
if @@async == "store"
|
250
|
-
|
251
|
-
|
252
|
-
result = result.parsed_response
|
253
|
-
if @@verbose
|
254
|
-
result
|
255
|
-
else
|
256
|
-
if result["error"]
|
257
|
-
result["errorMessage"]
|
258
|
-
else
|
259
|
-
result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
221
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
222
|
+
result = result.parsed_response
|
223
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
263
224
|
end
|
264
225
|
|
265
226
|
def documentMatch(match:) # TESTED
|
@@ -269,20 +230,9 @@ class ArangoCollection < ArangoServer
|
|
269
230
|
}.delete_if{|k,v| v.nil?}.to_json
|
270
231
|
request = @@request.merge({ :body => body })
|
271
232
|
result = self.class.put("/_db/#{@database}/_api/simple/first-example", request)
|
272
|
-
if @@async == "store"
|
273
|
-
|
274
|
-
|
275
|
-
result = result.parsed_response
|
276
|
-
if @@verbose
|
277
|
-
result
|
278
|
-
else
|
279
|
-
if result["error"]
|
280
|
-
result["errorMessage"]
|
281
|
-
else
|
282
|
-
ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
233
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
234
|
+
result = result.parsed_response
|
235
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
286
236
|
end
|
287
237
|
|
288
238
|
def documentByKeys(keys:) # TESTED
|
@@ -291,40 +241,18 @@ class ArangoCollection < ArangoServer
|
|
291
241
|
body = { "collection" => @collection, "keys" => keys }
|
292
242
|
request = @@request.merge({ :body => body.to_json })
|
293
243
|
result = self.class.put("/_db/#{@database}/_api/simple/lookup-by-keys", request)
|
294
|
-
if @@async == "store"
|
295
|
-
|
296
|
-
|
297
|
-
result = result.parsed_response
|
298
|
-
if @@verbose
|
299
|
-
result
|
300
|
-
else
|
301
|
-
if result["error"]
|
302
|
-
result["errorMessage"]
|
303
|
-
else
|
304
|
-
result["documents"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
244
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
245
|
+
result = result.parsed_response
|
246
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["documents"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)}
|
308
247
|
end
|
309
248
|
|
310
249
|
def random # TESTED
|
311
250
|
body = { "collection" => @collection }.to_json
|
312
251
|
request = @@request.merge({ :body => body })
|
313
252
|
result = self.class.put("/_db/#{@database}/_api/simple/any", request)
|
314
|
-
if @@async == "store"
|
315
|
-
|
316
|
-
|
317
|
-
result = result.parsed_response
|
318
|
-
if @@verbose
|
319
|
-
result
|
320
|
-
else
|
321
|
-
if result["error"]
|
322
|
-
result["errorMessage"]
|
323
|
-
else
|
324
|
-
ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
253
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
254
|
+
result = result.parsed_response
|
255
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
328
256
|
end
|
329
257
|
|
330
258
|
def removeByKeys(keys:, options: nil) # TESTED
|
@@ -384,30 +312,12 @@ class ArangoCollection < ArangoServer
|
|
384
312
|
"details": details
|
385
313
|
}.delete_if{|k,v| v.nil?}
|
386
314
|
body = "#{attributes}\n"
|
387
|
-
|
388
|
-
values.each{|x| body += "#{x}\n"}
|
389
|
-
else
|
390
|
-
body += "#{values}\n"
|
391
|
-
end
|
392
|
-
# print body
|
315
|
+
values[0].is_a?(Array) ? values.each{|x| body += "#{x}\n"} : body += "#{values}\n"
|
393
316
|
request = @@request.merge({ :body => body, :query => query })
|
394
317
|
result = self.class.post("/_db/#{@database}/_api/import", request)
|
395
|
-
if @@async == "store"
|
396
|
-
|
397
|
-
|
398
|
-
result = result.parsed_response
|
399
|
-
if @@verbose
|
400
|
-
result
|
401
|
-
else
|
402
|
-
if result["error"]
|
403
|
-
result["errorMessage"]
|
404
|
-
else
|
405
|
-
result.delete("error")
|
406
|
-
result.delete("code")
|
407
|
-
result
|
408
|
-
end
|
409
|
-
end
|
410
|
-
end
|
318
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
319
|
+
result = result.parsed_response
|
320
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result.delete_if{|k,v| k == "error" || k == "code"}
|
411
321
|
end
|
412
322
|
|
413
323
|
def importJSON(body:, type: "auto", from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) # TESTED
|
@@ -424,22 +334,9 @@ class ArangoCollection < ArangoServer
|
|
424
334
|
}.delete_if{|k,v| v.nil?}
|
425
335
|
request = @@request.merge({ :body => body.to_json, :query => query })
|
426
336
|
result = self.class.post("/_db/#{@database}/_api/import", request)
|
427
|
-
if @@async == "store"
|
428
|
-
|
429
|
-
|
430
|
-
result = result.parsed_response
|
431
|
-
if @@verbose
|
432
|
-
result
|
433
|
-
else
|
434
|
-
if result["error"]
|
435
|
-
result["errorMessage"]
|
436
|
-
else
|
437
|
-
result.delete("error")
|
438
|
-
result.delete("code")
|
439
|
-
result
|
440
|
-
end
|
441
|
-
end
|
442
|
-
end
|
337
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
338
|
+
result = result.parsed_response
|
339
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result.delete_if{|k,v| k == "error" || k == "code"}
|
443
340
|
end
|
444
341
|
|
445
342
|
# === EXPORT ===
|
@@ -456,29 +353,18 @@ class ArangoCollection < ArangoServer
|
|
456
353
|
}.delete_if{|k,v| v.nil?}
|
457
354
|
request = @@request.merge({ :body => body.to_json, :query => query })
|
458
355
|
result = self.class.post("/_db/#{@database}/_api/export", request)
|
459
|
-
if @@async == "store"
|
460
|
-
|
356
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
357
|
+
result = result.parsed_response
|
358
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
359
|
+
@countExport = result["count"]
|
360
|
+
@hasMoreExport = result["hasMore"]
|
361
|
+
@idExport = result["id"]
|
362
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
363
|
+
result = result["result"]
|
461
364
|
else
|
462
|
-
result = result.
|
463
|
-
if result["error"]
|
464
|
-
return @@verbose ? result : result["errorMessage"]
|
465
|
-
else
|
466
|
-
@countExport = result["count"]
|
467
|
-
@hasMoreExport = result["hasMore"]
|
468
|
-
@idExport = result["id"]
|
469
|
-
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
470
|
-
result = result["result"]
|
471
|
-
else
|
472
|
-
result = result["result"].map{|x| ArangoDocument.new(
|
473
|
-
key: x["_key"],
|
474
|
-
collection: @collection,
|
475
|
-
database: @database,
|
476
|
-
body: x
|
477
|
-
)}
|
478
|
-
end
|
479
|
-
result
|
480
|
-
end
|
365
|
+
result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: x)}
|
481
366
|
end
|
367
|
+
result
|
482
368
|
end
|
483
369
|
|
484
370
|
def exportNext # TESTED
|
@@ -488,29 +374,18 @@ class ArangoCollection < ArangoServer
|
|
488
374
|
query = { "collection": @collection }
|
489
375
|
request = @@request.merge({ :query => query })
|
490
376
|
result = self.class.put("/_db/#{@database}/_api/cursor/#{@idExport}", request)
|
491
|
-
if @@async == "store"
|
492
|
-
|
377
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
378
|
+
result = result.parsed_response
|
379
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
380
|
+
@countExport = result["count"]
|
381
|
+
@hasMoreExport = result["hasMore"]
|
382
|
+
@idExport = result["id"]
|
383
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
384
|
+
result = result["result"]
|
493
385
|
else
|
494
|
-
result = result.
|
495
|
-
if result["error"]
|
496
|
-
return @@verbose ? result : result["errorMessage"]
|
497
|
-
else
|
498
|
-
@countExport = result["count"]
|
499
|
-
@hasMoreExport = result["hasMore"]
|
500
|
-
@idExport = result["id"]
|
501
|
-
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
502
|
-
result = result["result"]
|
503
|
-
else
|
504
|
-
result = result["result"].map{|x| ArangoDocument.new(
|
505
|
-
key: x["_key"],
|
506
|
-
collection: @collection,
|
507
|
-
database: @database,
|
508
|
-
body: x
|
509
|
-
)}
|
510
|
-
end
|
511
|
-
result
|
512
|
-
end
|
386
|
+
result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: x)}
|
513
387
|
end
|
388
|
+
result
|
514
389
|
end
|
515
390
|
end
|
516
391
|
|
@@ -538,23 +413,13 @@ class ArangoCollection < ArangoServer
|
|
538
413
|
query = { "collection": @collection }
|
539
414
|
request = @@request.merge({ :query => query })
|
540
415
|
result = self.class.get("/_db/#{@database}/_api/index", request)
|
541
|
-
if @@async == "store"
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
if result["error"]
|
549
|
-
result["errorMessage"]
|
550
|
-
else
|
551
|
-
result.delete("error")
|
552
|
-
result.delete("code")
|
553
|
-
result["indexes"] = result["indexes"].map{|x| ArangoIndex.new(body: x, id: x["id"], database: @database, collection: @collection, type: x["type"], unique: x["unique"], fields: x["fields"])}
|
554
|
-
result
|
555
|
-
end
|
556
|
-
end
|
557
|
-
end
|
416
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
417
|
+
result = result.parsed_response
|
418
|
+
return result if @@verbose
|
419
|
+
return result["errorMessage"] if result["error"]
|
420
|
+
result.delete_if{|k,v| k == "error" || k == "code"}
|
421
|
+
result["indexes"] = result["indexes"].map{|x| ArangoIndex.new(body: x, id: x["id"], database: @database, collection: @collection, type: x["type"], unique: x["unique"], fields: x["fields"])}
|
422
|
+
result
|
558
423
|
end
|
559
424
|
|
560
425
|
def createIndex(body: {}, unique: nil, type:, fields:, id: nil) # TESTED
|
@@ -565,20 +430,9 @@ class ArangoCollection < ArangoServer
|
|
565
430
|
query = { "collection": @collection }
|
566
431
|
request = @@request.merge({ :body => body.to_json, :query => query })
|
567
432
|
result = self.class.post("/_db/#{@database}/_api/index", request)
|
568
|
-
if @@async == "store"
|
569
|
-
|
570
|
-
|
571
|
-
result = result.parsed_response
|
572
|
-
if @@verbose
|
573
|
-
result
|
574
|
-
else
|
575
|
-
if result["error"]
|
576
|
-
result["errorMessage"]
|
577
|
-
else
|
578
|
-
ArangoIndex.new(body: result, id: result["id"], database: @database, collection: @collection, type: result["type"], unique: result["unique"], fields: result["fields"])
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|
433
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
434
|
+
result = result.parsed_response
|
435
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : ArangoIndex.new(body: result, id: result["id"], database: @database, collection: @collection, type: result["type"], unique: result["unique"], fields: result["fields"])
|
582
436
|
end
|
583
437
|
#
|
584
438
|
# def deleteIndex(id:) # TESTED
|
@@ -614,54 +468,31 @@ class ArangoCollection < ArangoServer
|
|
614
468
|
}.delete_if{|k,v| v.nil?}
|
615
469
|
request = @@request.merge({ :query => query })
|
616
470
|
result = self.class.get("/_db/#{@database}/_api/replication/dump", request)
|
617
|
-
if @@async == "store"
|
618
|
-
|
619
|
-
|
620
|
-
result = result.parsed_response
|
621
|
-
if @@verbose
|
622
|
-
result
|
623
|
-
else
|
624
|
-
if result["error"]
|
625
|
-
result["errorMessage"]
|
626
|
-
else
|
627
|
-
result
|
628
|
-
end
|
629
|
-
end
|
630
|
-
end
|
471
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
472
|
+
result = result.parsed_response
|
473
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result
|
631
474
|
end
|
632
475
|
|
633
476
|
# === UTILITY ===
|
634
477
|
|
635
478
|
def return_result(result:, caseTrue: false, key: nil, checkType: false)
|
636
|
-
if @@async == "store"
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
result.delete("code")
|
645
|
-
@body = result
|
646
|
-
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
647
|
-
end
|
648
|
-
resultTemp
|
649
|
-
else
|
650
|
-
if result["error"]
|
651
|
-
result["errorMessage"]
|
652
|
-
else
|
653
|
-
return true if caseTrue
|
654
|
-
result.delete("error")
|
655
|
-
result.delete("code")
|
656
|
-
@body = result
|
657
|
-
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
658
|
-
if key.nil?
|
659
|
-
self
|
660
|
-
else
|
661
|
-
result[key]
|
662
|
-
end
|
663
|
-
end
|
479
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
480
|
+
result = result.parsed_response
|
481
|
+
if @@verbose || !result.is_a?(Hash)
|
482
|
+
resultTemp = result
|
483
|
+
unless result["errorMessage"]
|
484
|
+
result.delete_if{|k,v| k == "error" || k == "code"}
|
485
|
+
@body = result
|
486
|
+
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
664
487
|
end
|
488
|
+
resultTemp
|
489
|
+
else
|
490
|
+
return result["errorMessage"] if result["error"]
|
491
|
+
return true if caseTrue
|
492
|
+
result.delete_if{|k,v| k == "error" || k == "code"}
|
493
|
+
@body = result
|
494
|
+
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
495
|
+
key.nil? ? self : result[key]
|
665
496
|
end
|
666
497
|
end
|
667
498
|
end
|