arangorb 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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_Col.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
# === COLLECTION ===
|
2
2
|
|
3
|
-
class
|
4
|
-
def initialize(collection: @@collection, database: @@database, body: {}, type: nil)
|
3
|
+
class ArangoCollection < ArangoServer
|
4
|
+
def initialize(collection: @@collection, database: @@database, body: {}, type: nil) # TESTED
|
5
5
|
if collection.is_a?(String)
|
6
6
|
@collection = collection
|
7
|
+
elsif collection.is_a?(ArangoCollection)
|
8
|
+
@collection = collection.collection
|
7
9
|
else
|
8
|
-
raise "collection should be a String, not a #{collection.class}"
|
10
|
+
raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
|
9
11
|
end
|
10
12
|
|
11
13
|
if database.is_a?(String)
|
12
14
|
@database = database
|
15
|
+
elsif database.is_a?(ArangoDatabase)
|
16
|
+
@database = database.database
|
13
17
|
else
|
14
|
-
raise "database should be a String, not a #{database.class}"
|
18
|
+
raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
|
15
19
|
end
|
16
20
|
|
17
21
|
if body.is_a?(Hash)
|
18
22
|
@body = body
|
19
23
|
else
|
20
|
-
raise "body should be a
|
24
|
+
raise "body should be a Hash, not a #{body.class}"
|
21
25
|
end
|
22
26
|
|
23
27
|
if !@type.nil? && @type != "Document" && @type != "Edge"
|
@@ -36,43 +40,47 @@ class ArangoC < ArangoS
|
|
36
40
|
|
37
41
|
# === GET ===
|
38
42
|
|
39
|
-
def retrieve
|
40
|
-
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}")
|
41
|
-
self.return_result
|
43
|
+
def retrieve # TESTED
|
44
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}", @@request)
|
45
|
+
self.return_result result: result, checkType: true
|
42
46
|
end
|
43
47
|
|
44
|
-
def properties
|
45
|
-
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/properties")
|
46
|
-
|
48
|
+
def properties # TESTED
|
49
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/properties", @@request)
|
50
|
+
result = self.return_result result: result
|
51
|
+
return result.is_a?(ArangoCollection) ? result.body : result
|
47
52
|
end
|
48
53
|
|
49
|
-
def count
|
50
|
-
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/count")
|
51
|
-
|
54
|
+
def count # TESTED
|
55
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/count", @@request)
|
56
|
+
self.return_result result: result, key: "count"
|
52
57
|
end
|
53
58
|
|
54
|
-
def
|
55
|
-
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/figures")
|
56
|
-
|
59
|
+
def statistics # TESTED
|
60
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/figures", @@request)
|
61
|
+
self.return_result result: result, key: "figures"
|
57
62
|
end
|
58
63
|
|
59
|
-
#
|
60
|
-
|
61
|
-
|
64
|
+
def revision # TESTED
|
65
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/revision", @@request)
|
66
|
+
self.return_result result: result, key: "revision"
|
67
|
+
end
|
62
68
|
|
63
|
-
def checksum(withRevisions: nil, withData: nil)
|
69
|
+
def checksum(withRevisions: nil, withData: nil) # TESTED
|
64
70
|
query = {
|
65
71
|
"withRevisions": withRevisions,
|
66
72
|
"withData": withData
|
67
73
|
}.delete_if{|k,v| v.nil?}
|
68
|
-
|
69
|
-
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/checksum",
|
70
|
-
|
74
|
+
request = @@request.merge({ :query => query })
|
75
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/checksum", request)
|
76
|
+
self.return_result result: result, key: "checksum"
|
71
77
|
end
|
72
78
|
|
73
79
|
# === POST ===
|
74
80
|
|
75
|
-
def create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil)
|
81
|
+
def create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) # TESTED
|
82
|
+
type = 3 if type == "Edge"
|
83
|
+
type = nil if type == "Document"
|
76
84
|
body = {
|
77
85
|
"name" => collection,
|
78
86
|
"type" => type,
|
@@ -87,133 +95,148 @@ class ArangoC < ArangoS
|
|
87
95
|
"indexBuckets" => indexBuckets
|
88
96
|
}
|
89
97
|
body = body.delete_if{|k,v| v.nil?}.to_json
|
90
|
-
|
91
|
-
result = self.class.post("/_db/#{@database}/_api/collection",
|
92
|
-
self.return_result
|
98
|
+
request = @@request.merge({ :body => body })
|
99
|
+
result = self.class.post("/_db/#{@database}/_api/collection", request)
|
100
|
+
self.return_result result: result, checkType: true
|
93
101
|
end
|
94
102
|
alias create_collection create
|
95
103
|
alias create_document_collection create
|
96
104
|
alias create_vertex_collection create
|
97
105
|
|
98
|
-
def create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil)
|
106
|
+
def create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) # TESTED
|
99
107
|
self.create type: 3, journalSize: journalSize, keyOptions: keyOptions, waitForSync: waitForSync, doCompact: doCompact, isVolatile: isVolatile, shardKeys: shardKeys, numberOfShards: numberOfShards, isSystem: isSystem, indexBuckets: indexBuckets
|
100
108
|
end
|
101
109
|
|
102
|
-
def create_document(document: {}, waitForSync: nil, returnNew: nil)
|
103
|
-
if document.is_a? Hash
|
104
|
-
|
105
|
-
elsif document.is_a?
|
106
|
-
|
107
|
-
elsif document.is_a? Array
|
108
|
-
|
109
|
-
else
|
110
|
-
|
111
|
-
end
|
112
|
-
|
110
|
+
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
|
+
ArangoDocument.create(body: document, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
113
121
|
end
|
114
122
|
alias create_vertex create_document
|
115
123
|
|
116
|
-
def create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil)
|
117
|
-
if document.is_a? Hash
|
118
|
-
|
119
|
-
elsif document.is_a?
|
120
|
-
|
121
|
-
elsif document.is_a? Array
|
122
|
-
|
123
|
-
else
|
124
|
-
|
125
|
-
end
|
126
|
-
|
124
|
+
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
|
+
ArangoDocument.create_edge(body: document, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
127
135
|
end
|
128
136
|
|
129
137
|
# === DELETE ===
|
130
138
|
|
131
|
-
def destroy
|
132
|
-
result = self.class.delete("/_db/#{@database}/_api/collection/#{@collection}")
|
133
|
-
|
139
|
+
def destroy # TESTED
|
140
|
+
result = self.class.delete("/_db/#{@database}/_api/collection/#{@collection}", @@request)
|
141
|
+
self.return_result result: result, caseTrue: true
|
134
142
|
end
|
135
143
|
|
136
|
-
def truncate
|
137
|
-
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/truncate")
|
138
|
-
self.return_result
|
144
|
+
def truncate # TESTED
|
145
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/truncate", @@request)
|
146
|
+
self.return_result result: result
|
139
147
|
end
|
140
148
|
|
141
149
|
# === MODIFY ===
|
142
150
|
|
143
|
-
def load
|
144
|
-
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/load")
|
145
|
-
self.return_result
|
151
|
+
def load # TESTED
|
152
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/load", @@request)
|
153
|
+
self.return_result result: result
|
146
154
|
end
|
147
155
|
|
148
|
-
def unload
|
149
|
-
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/unload")
|
150
|
-
self.return_result
|
156
|
+
def unload # TESTED
|
157
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/unload", @@request)
|
158
|
+
self.return_result result: result
|
151
159
|
end
|
152
160
|
|
153
|
-
def change(waitForSync: nil, journalSize: nil)
|
161
|
+
def change(waitForSync: nil, journalSize: nil) # TESTED
|
154
162
|
body = {
|
155
163
|
"journalSize" => journalSize,
|
156
164
|
"waitForSync" => waitForSync
|
157
165
|
}
|
158
166
|
body = body.delete_if{|k,v| k.nil?}.to_json
|
159
|
-
|
160
|
-
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/properties",
|
161
|
-
self.return_result
|
167
|
+
request = @@request.merge({ :body => body })
|
168
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/properties", request)
|
169
|
+
self.return_result result: result
|
162
170
|
end
|
163
171
|
|
164
|
-
def rename(newName)
|
172
|
+
def rename(newName) # TESTED
|
165
173
|
body = { "name" => newName }
|
166
|
-
|
167
|
-
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rename",
|
168
|
-
@collection = newName unless result["error"]
|
169
|
-
self.return_result
|
174
|
+
request = @@request.merge({ :body => body.to_json })
|
175
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rename", request)
|
176
|
+
@collection = newName unless result.parsed_response["error"]
|
177
|
+
self.return_result result: result
|
178
|
+
end
|
179
|
+
|
180
|
+
def rotate
|
181
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rotate", @@request)
|
182
|
+
self.return_result result: result, caseTrue: true
|
170
183
|
end
|
171
184
|
|
172
185
|
# === SIMPLE FUNCTIONS ===
|
173
186
|
|
174
|
-
def documents(type: nil) # "path", "id", "key"
|
187
|
+
def documents(type: nil) # "path", "id", "key" # TESTED
|
175
188
|
body = {
|
176
189
|
"collection" => @collection,
|
177
190
|
"type" => type
|
178
191
|
}.delete_if{|k,v| v.nil?}.to_json
|
179
|
-
|
180
|
-
result = self.class.put("/_db/#{@database}/_api/simple/all-keys",
|
181
|
-
if
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
192
|
+
request = @@request.merge({ :body => body })
|
193
|
+
result = self.class.put("/_db/#{@database}/_api/simple/all-keys", request)
|
194
|
+
if @@async == "store"
|
195
|
+
result.headers["x-arango-async-id"]
|
196
|
+
else
|
197
|
+
result = result.parsed_response
|
198
|
+
if type.nil?
|
199
|
+
if @@verbose
|
200
|
+
result
|
187
201
|
else
|
188
|
-
result["
|
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
|
189
207
|
end
|
208
|
+
else
|
209
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
|
190
210
|
end
|
191
|
-
else
|
192
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
|
193
211
|
end
|
194
212
|
end
|
195
213
|
|
196
|
-
def allDocuments(skip: nil, limit: nil, batchSize: nil)
|
214
|
+
def allDocuments(skip: nil, limit: nil, batchSize: nil) # TESTED
|
197
215
|
body = {
|
198
216
|
"collection" => @collection,
|
199
217
|
"skip" => skip,
|
200
218
|
"limit" => limit,
|
201
219
|
"batchSize" => batchSize
|
202
220
|
}.delete_if{|k,v| v.nil?}.to_json
|
203
|
-
|
204
|
-
result = self.class.put("/_db/#{@database}/_api/simple/all",
|
205
|
-
if @@
|
206
|
-
result
|
221
|
+
request = @@request.merge({ :body => body })
|
222
|
+
result = self.class.put("/_db/#{@database}/_api/simple/all", request)
|
223
|
+
if @@async == "store"
|
224
|
+
result.headers["x-arango-async-id"]
|
207
225
|
else
|
208
|
-
|
209
|
-
|
226
|
+
result = result.parsed_response
|
227
|
+
if @@verbose
|
228
|
+
result
|
210
229
|
else
|
211
|
-
result["
|
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
|
212
235
|
end
|
213
236
|
end
|
214
237
|
end
|
215
238
|
|
216
|
-
def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil)
|
239
|
+
def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) # TESTED
|
217
240
|
body = {
|
218
241
|
"collection" => @collection,
|
219
242
|
"example" => match,
|
@@ -221,129 +244,423 @@ class ArangoC < ArangoS
|
|
221
244
|
"limit" => limit,
|
222
245
|
"batchSize" => batchSize
|
223
246
|
}.delete_if{|k,v| v.nil?}.to_json
|
224
|
-
|
225
|
-
result = self.class.put("/_db/#{@database}/_api/simple/by-example",
|
226
|
-
if @@
|
227
|
-
result
|
247
|
+
request = @@request.merge({ :body => body })
|
248
|
+
result = self.class.put("/_db/#{@database}/_api/simple/by-example", request)
|
249
|
+
if @@async == "store"
|
250
|
+
result.headers["x-arango-async-id"]
|
228
251
|
else
|
229
|
-
|
230
|
-
|
252
|
+
result = result.parsed_response
|
253
|
+
if @@verbose
|
254
|
+
result
|
231
255
|
else
|
232
|
-
result["
|
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
|
233
261
|
end
|
234
262
|
end
|
235
263
|
end
|
236
264
|
|
237
|
-
def documentMatch(match:)
|
265
|
+
def documentMatch(match:) # TESTED
|
238
266
|
body = {
|
239
267
|
"collection" => @collection,
|
240
268
|
"example" => match
|
241
269
|
}.delete_if{|k,v| v.nil?}.to_json
|
242
|
-
|
243
|
-
result = self.class.put("/_db/#{@database}/_api/simple/first-example",
|
244
|
-
if @@
|
245
|
-
result
|
270
|
+
request = @@request.merge({ :body => body })
|
271
|
+
result = self.class.put("/_db/#{@database}/_api/simple/first-example", request)
|
272
|
+
if @@async == "store"
|
273
|
+
result.headers["x-arango-async-id"]
|
246
274
|
else
|
247
|
-
|
248
|
-
|
275
|
+
result = result.parsed_response
|
276
|
+
if @@verbose
|
277
|
+
result
|
249
278
|
else
|
250
|
-
|
279
|
+
if result["error"]
|
280
|
+
result["errorMessage"]
|
281
|
+
else
|
282
|
+
ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
283
|
+
end
|
251
284
|
end
|
252
285
|
end
|
253
286
|
end
|
254
287
|
|
255
|
-
def documentByKeys(keys:)
|
256
|
-
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(
|
288
|
+
def documentByKeys(keys:) # TESTED
|
289
|
+
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDocument) ? x.key : nil} if keys.is_a? Array
|
257
290
|
keys = [keys] if keys.is_a? String
|
258
291
|
body = { "collection" => @collection, "keys" => keys }
|
259
|
-
|
260
|
-
result = self.class.put("/_db/#{@database}/_api/simple/lookup-by-keys",
|
261
|
-
if @@
|
262
|
-
result
|
292
|
+
request = @@request.merge({ :body => body.to_json })
|
293
|
+
result = self.class.put("/_db/#{@database}/_api/simple/lookup-by-keys", request)
|
294
|
+
if @@async == "store"
|
295
|
+
result.headers["x-arango-async-id"]
|
263
296
|
else
|
264
|
-
|
265
|
-
|
297
|
+
result = result.parsed_response
|
298
|
+
if @@verbose
|
299
|
+
result
|
266
300
|
else
|
267
|
-
result["
|
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
|
268
306
|
end
|
269
307
|
end
|
270
308
|
end
|
271
309
|
|
272
|
-
def random
|
273
|
-
body = { "collection" => @collection }
|
274
|
-
|
275
|
-
result = self.class.put("/_db/#{@database}/_api/simple/any",
|
276
|
-
if @@
|
277
|
-
result
|
310
|
+
def random # TESTED
|
311
|
+
body = { "collection" => @collection }.to_json
|
312
|
+
request = @@request.merge({ :body => body })
|
313
|
+
result = self.class.put("/_db/#{@database}/_api/simple/any", request)
|
314
|
+
if @@async == "store"
|
315
|
+
result.headers["x-arango-async-id"]
|
278
316
|
else
|
279
|
-
|
280
|
-
|
317
|
+
result = result.parsed_response
|
318
|
+
if @@verbose
|
319
|
+
result
|
281
320
|
else
|
282
|
-
|
321
|
+
if result["error"]
|
322
|
+
result["errorMessage"]
|
323
|
+
else
|
324
|
+
ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
325
|
+
end
|
283
326
|
end
|
284
327
|
end
|
285
328
|
end
|
286
329
|
|
287
|
-
def removeByKeys(keys:, options: nil)
|
288
|
-
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(
|
289
|
-
body = { "collection" => @collection, "keys" => keys, "options" => options }.delete_if{|k,v| v.nil?}
|
290
|
-
|
291
|
-
self.class.put("/_db/#{@database}/_api/simple/remove-by-keys",
|
330
|
+
def removeByKeys(keys:, options: nil) # TESTED
|
331
|
+
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDocument) ? x.key : nil}
|
332
|
+
body = { "collection" => @collection, "keys" => keys, "options" => options }.delete_if{|k,v| v.nil?}.to_json
|
333
|
+
request = @@request.merge({ :body => body })
|
334
|
+
result = self.class.put("/_db/#{@database}/_api/simple/remove-by-keys", request)
|
335
|
+
self.return_result result: result, key: "removed"
|
292
336
|
end
|
293
337
|
|
294
|
-
def removeMatch(match:, options: nil)
|
338
|
+
def removeMatch(match:, options: nil) # TESTED
|
295
339
|
body = {
|
296
340
|
"collection" => @collection,
|
297
341
|
"example" => match,
|
298
|
-
"options" =>
|
342
|
+
"options" => options
|
299
343
|
}.delete_if{|k,v| v.nil?}.to_json
|
300
|
-
|
301
|
-
self.class.put("/_db/#{@database}/_api/simple/remove-by-example",
|
344
|
+
request = @@request.merge({ :body => body })
|
345
|
+
result = self.class.put("/_db/#{@database}/_api/simple/remove-by-example", request)
|
346
|
+
self.return_result result: result, key: "deleted"
|
302
347
|
end
|
303
348
|
|
304
|
-
def replaceMatch(match:, newValue:, options: nil)
|
349
|
+
def replaceMatch(match:, newValue:, options: nil) # TESTED
|
305
350
|
body = {
|
306
351
|
"collection" => @collection,
|
307
352
|
"example" => match,
|
308
|
-
"options" =>
|
353
|
+
"options" => options,
|
309
354
|
"newValue" => newValue
|
310
355
|
}.delete_if{|k,v| v.nil?}.to_json
|
311
|
-
|
312
|
-
self.class.put("/_db/#{@database}/_api/simple/replace-by-example",
|
356
|
+
request = @@request.merge({ :body => body })
|
357
|
+
result = self.class.put("/_db/#{@database}/_api/simple/replace-by-example", request)
|
358
|
+
self.return_result result: result, key: "replaced"
|
313
359
|
end
|
314
360
|
|
315
|
-
def updateMatch(match:, newValue:, options: nil)
|
361
|
+
def updateMatch(match:, newValue:, options: nil) # TESTED
|
316
362
|
body = {
|
317
363
|
"collection" => @collection,
|
318
364
|
"example" => match,
|
319
|
-
"options" =>
|
365
|
+
"options" => options,
|
320
366
|
"newValue" => newValue
|
321
367
|
}.delete_if{|k,v| v.nil?}.to_json
|
322
|
-
|
323
|
-
self.class.put("/_db/#{@database}/_api/simple/update-by-example",
|
368
|
+
request = @@request.merge({ :body => body })
|
369
|
+
result = self.class.put("/_db/#{@database}/_api/simple/update-by-example", request)
|
370
|
+
self.return_result result: result, key: "updated"
|
324
371
|
end
|
325
372
|
|
326
|
-
# ===
|
373
|
+
# === IMPORT ===
|
374
|
+
|
375
|
+
def import(attributes:, values:, from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) # TESTED
|
376
|
+
query = {
|
377
|
+
"collection": @collection,
|
378
|
+
"fromPrefix": from,
|
379
|
+
"toPrefix": to,
|
380
|
+
"overwrite": overwrite,
|
381
|
+
"waitForSync": waitForSync,
|
382
|
+
"onDuplicate": onDuplicate,
|
383
|
+
"complete": complete,
|
384
|
+
"details": details
|
385
|
+
}.delete_if{|k,v| v.nil?}
|
386
|
+
body = "#{attributes}\n"
|
387
|
+
if values[0].is_a? Array
|
388
|
+
values.each{|x| body += "#{x}\n"}
|
389
|
+
else
|
390
|
+
body += "#{values}\n"
|
391
|
+
end
|
392
|
+
# print body
|
393
|
+
request = @@request.merge({ :body => body, :query => query })
|
394
|
+
result = self.class.post("/_db/#{@database}/_api/import", request)
|
395
|
+
if @@async == "store"
|
396
|
+
result.headers["x-arango-async-id"]
|
397
|
+
else
|
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
|
411
|
+
end
|
327
412
|
|
328
|
-
def
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
413
|
+
def importJSON(body:, type: "auto", from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) # TESTED
|
414
|
+
query = {
|
415
|
+
"collection": @collection,
|
416
|
+
"type": type,
|
417
|
+
"fromPrefix": from,
|
418
|
+
"toPrefix": to,
|
419
|
+
"overwrite": overwrite,
|
420
|
+
"waitForSync": waitForSync,
|
421
|
+
"onDuplicate": onDuplicate,
|
422
|
+
"complete": complete,
|
423
|
+
"details": details
|
424
|
+
}.delete_if{|k,v| v.nil?}
|
425
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
426
|
+
result = self.class.post("/_db/#{@database}/_api/import", request)
|
427
|
+
if @@async == "store"
|
428
|
+
result.headers["x-arango-async-id"]
|
429
|
+
else
|
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
|
336
441
|
end
|
337
|
-
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
# === EXPORT ===
|
446
|
+
|
447
|
+
def export(count: nil, restrict: nil, batchSize: nil, flush: nil, limit: nil, ttl: nil) # TESTED
|
448
|
+
query = { "collection": @collection }
|
449
|
+
body = {
|
450
|
+
"count" => count,
|
451
|
+
"restrict" => restrict,
|
452
|
+
"batchSize" => batchSize,
|
453
|
+
"flush" => flush,
|
454
|
+
"limit" => limit,
|
455
|
+
"ttl" => ttl
|
456
|
+
}.delete_if{|k,v| v.nil?}
|
457
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
458
|
+
result = self.class.post("/_db/#{@database}/_api/export", request)
|
459
|
+
if @@async == "store"
|
460
|
+
result.headers["x-arango-async-id"]
|
338
461
|
else
|
462
|
+
result = result.parsed_response
|
339
463
|
if result["error"]
|
340
|
-
result["errorMessage"]
|
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
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def exportNext # TESTED
|
485
|
+
unless @hasMoreExport
|
486
|
+
print "No other results"
|
487
|
+
else
|
488
|
+
query = { "collection": @collection }
|
489
|
+
request = @@request.merge({ :query => query })
|
490
|
+
result = self.class.put("/_db/#{@database}/_api/cursor/#{@idExport}", request)
|
491
|
+
if @@async == "store"
|
492
|
+
result.headers["x-arango-async-id"]
|
493
|
+
else
|
494
|
+
result = result.parsed_response
|
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
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
# === INDEXES ===
|
518
|
+
|
519
|
+
# def retrieveIndex(id:) # TESTED
|
520
|
+
# result = self.class.get("/_db/#{@database}/_api/index/#{@collection}/#{id}", @@request)
|
521
|
+
# if @@async == "store"
|
522
|
+
# result.headers["x-arango-async-id"]
|
523
|
+
# else
|
524
|
+
# result = result.parsed_response
|
525
|
+
# if @@verbose
|
526
|
+
# result
|
527
|
+
# else
|
528
|
+
# if result["error"]
|
529
|
+
# result["errorMessage"]
|
530
|
+
# else
|
531
|
+
# ArangoIndex.new(body: result, id: result["id"], database: @database, collection: @collection, type: result["type"], unique: result["unique"], fields: result["fields"])
|
532
|
+
# end
|
533
|
+
# end
|
534
|
+
# end
|
535
|
+
# end
|
536
|
+
|
537
|
+
def indexes # TESTED
|
538
|
+
query = { "collection": @collection }
|
539
|
+
request = @@request.merge({ :query => query })
|
540
|
+
result = self.class.get("/_db/#{@database}/_api/index", request)
|
541
|
+
if @@async == "store"
|
542
|
+
result.headers["x-arango-async-id"]
|
543
|
+
else
|
544
|
+
result = result.parsed_response
|
545
|
+
if @@verbose
|
546
|
+
result
|
547
|
+
else
|
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
|
558
|
+
end
|
559
|
+
|
560
|
+
def createIndex(body: {}, unique: nil, type:, fields:, id: nil) # TESTED
|
561
|
+
body["fields"] = fields.is_a?(Array) ? fields : [fields]
|
562
|
+
body["unique"] = unique unless unique.nil?
|
563
|
+
body["type"] = type unless type.nil?
|
564
|
+
body["id"] = id unless type.nil?
|
565
|
+
query = { "collection": @collection }
|
566
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
567
|
+
result = self.class.post("/_db/#{@database}/_api/index", request)
|
568
|
+
if @@async == "store"
|
569
|
+
result.headers["x-arango-async-id"]
|
570
|
+
else
|
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
|
582
|
+
end
|
583
|
+
#
|
584
|
+
# def deleteIndex(id:) # TESTED
|
585
|
+
# result = self.class.delete("/_db/#{@database}/_api/index/#{@collection}/#{id}", @@request)
|
586
|
+
# if @@async == "store"
|
587
|
+
# result.headers["x-arango-async-id"]
|
588
|
+
# else
|
589
|
+
# result = result.parsed_response
|
590
|
+
# if @@verbose
|
591
|
+
# result
|
592
|
+
# else
|
593
|
+
# if result["error"]
|
594
|
+
# result["errorMessage"]
|
595
|
+
# else
|
596
|
+
# true
|
597
|
+
# end
|
598
|
+
# end
|
599
|
+
# end
|
600
|
+
# end
|
601
|
+
|
602
|
+
# === REPLICATION ===
|
603
|
+
|
604
|
+
def data(from: nil, to: nil, chunkSize: nil, includeSystem: false, failOnUnknown: nil, ticks: nil, flush: nil) # TESTED
|
605
|
+
query = {
|
606
|
+
"collection": @collection,
|
607
|
+
"from": from,
|
608
|
+
"to": to,
|
609
|
+
"chunkSize": chunkSize,
|
610
|
+
"includeSystem": includeSystem,
|
611
|
+
"failOnUnknown": failOnUnknown,
|
612
|
+
"ticks": ticks,
|
613
|
+
"flush": flush
|
614
|
+
}.delete_if{|k,v| v.nil?}
|
615
|
+
request = @@request.merge({ :query => query })
|
616
|
+
result = self.class.get("/_db/#{@database}/_api/replication/dump", request)
|
617
|
+
if @@async == "store"
|
618
|
+
result.headers["x-arango-async-id"]
|
619
|
+
else
|
620
|
+
result = result.parsed_response
|
621
|
+
if @@verbose
|
622
|
+
result
|
341
623
|
else
|
342
|
-
result
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
624
|
+
if result["error"]
|
625
|
+
result["errorMessage"]
|
626
|
+
else
|
627
|
+
result
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
# === UTILITY ===
|
634
|
+
|
635
|
+
def return_result(result:, caseTrue: false, key: nil, checkType: false)
|
636
|
+
if @@async == "store"
|
637
|
+
result.headers["x-arango-async-id"]
|
638
|
+
else
|
639
|
+
result = result.parsed_response
|
640
|
+
if @@verbose || !result.is_a?(Hash)
|
641
|
+
resultTemp = result
|
642
|
+
unless result["errorMessage"]
|
643
|
+
result.delete("error")
|
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
|
347
664
|
end
|
348
665
|
end
|
349
666
|
end
|