arangorb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ArangoRB.gemspec +18 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +501 -0
- data/lib/ArangoRB_AQL.rb +202 -0
- data/lib/ArangoRB_Col.rb +350 -0
- data/lib/ArangoRB_DB.rb +170 -0
- data/lib/ArangoRB_Doc.rb +297 -0
- data/lib/ArangoRB_Edg.rb +157 -0
- data/lib/ArangoRB_Gra.rb +168 -0
- data/lib/ArangoRB_Ser.rb +64 -0
- data/lib/ArangoRB_Tra.rb +132 -0
- data/lib/ArangoRB_Ver.rb +138 -0
- data/lib/arangorb.rb +10 -0
- data/spec/arangoRB_helper.rb +9 -0
- data/spec/lib/arangoAQL_helper.rb +83 -0
- data/spec/lib/arangoC_helper.rb +149 -0
- data/spec/lib/arangoDB_helper.rb +119 -0
- data/spec/lib/arangoDoc_helper.rb +92 -0
- data/spec/lib/arangoE_helper.rb +70 -0
- data/spec/lib/arangoG_helper.rb +92 -0
- data/spec/lib/arangoS_helper.rb +28 -0
- data/spec/lib/arangoT_helper.rb +67 -0
- data/spec/lib/arangoV_helper.rb +81 -0
- data/spec/spec_helper.rb +6 -0
- metadata +92 -0
data/lib/ArangoRB_AQL.rb
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
# === AQL ===
|
2
|
+
|
3
|
+
class ArangoAQL < ArangoS
|
4
|
+
def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database)
|
5
|
+
if query.is_a?(String)
|
6
|
+
@query = query
|
7
|
+
elsif query.is_a?(ArangoAQL)
|
8
|
+
@query = query.query
|
9
|
+
else
|
10
|
+
raise "query should be String or ArangoAQL instance, not a #{query.class}"
|
11
|
+
end
|
12
|
+
@database = database
|
13
|
+
@batchSize = batchSize
|
14
|
+
@ttl = ttl
|
15
|
+
@cache = cache
|
16
|
+
@options = options
|
17
|
+
@bindVars = bindVars
|
18
|
+
|
19
|
+
@count = 0
|
20
|
+
@hasMore = false
|
21
|
+
@id = ""
|
22
|
+
@result = []
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :query, :batchSize, :ttl, :cache, :options, :bindVars
|
26
|
+
attr_reader :count, :database, :count, :hasMore, :id, :result
|
27
|
+
alias size batchSize
|
28
|
+
alias size= batchSize=
|
29
|
+
|
30
|
+
# === EXECUTE QUERY ===
|
31
|
+
|
32
|
+
def execute(count: true)
|
33
|
+
body = {
|
34
|
+
"query" => @query,
|
35
|
+
"count" => count,
|
36
|
+
"batchSize" => @batchSize,
|
37
|
+
"ttl" => @count,
|
38
|
+
"cache" => @cache,
|
39
|
+
"options" => @options,
|
40
|
+
"bindVars" => @bindVars
|
41
|
+
}.delete_if{|k,v| v.nil?}
|
42
|
+
new_Document = { :body => body.to_json }
|
43
|
+
result = self.class.post("/_db/#{@database}/_api/cursor", new_Document).parsed_response
|
44
|
+
if result["error"]
|
45
|
+
return @@verbose ? result : result["errorMessage"]
|
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"
|
67
|
+
else
|
68
|
+
result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}")
|
69
|
+
if result["error"]
|
70
|
+
return @@verbose ? result : result["errorMessage"]
|
71
|
+
else
|
72
|
+
@count = result["count"]
|
73
|
+
@hasMore = result["hasMore"]
|
74
|
+
@id = result["id"]
|
75
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
76
|
+
@result = result["result"]
|
77
|
+
else
|
78
|
+
@result = result["result"].map{|x| ArangoDoc.new(
|
79
|
+
key: x["_key"],
|
80
|
+
collection: x["_id"].split("/")[0],
|
81
|
+
database: @database,
|
82
|
+
body: x
|
83
|
+
)}
|
84
|
+
end
|
85
|
+
return @@verbose ? result : self
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# === PROPERTY QUERY ===
|
91
|
+
|
92
|
+
def explain
|
93
|
+
body = {
|
94
|
+
"query" => @query,
|
95
|
+
"options" => @options,
|
96
|
+
"bindVars" => @bindVars
|
97
|
+
}.delete_if{|k,v| v.nil?}
|
98
|
+
new_Document = { :body => body.to_json }
|
99
|
+
result = self.class.post("/_db/#{@database}/_api/explain", new_Document).parsed_response
|
100
|
+
return_result(result)
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse
|
104
|
+
body = { "query" => @query }
|
105
|
+
new_Document = { :body => body.to_json }
|
106
|
+
result = self.class.post("/_db/#{@database}/_api/query", new_Document).parsed_response
|
107
|
+
return_result(result)
|
108
|
+
end
|
109
|
+
|
110
|
+
def properties
|
111
|
+
result = self.class.get("/_db/#{@database}/_api/query/properties").parsed_response
|
112
|
+
return_result(result)
|
113
|
+
end
|
114
|
+
|
115
|
+
def current
|
116
|
+
self.class.get("/_db/#{@database}/_api/query/current").parsed_response
|
117
|
+
end
|
118
|
+
|
119
|
+
def slow
|
120
|
+
self.class.get("/_db/#{@database}/_api/query/slow").parsed_response
|
121
|
+
end
|
122
|
+
|
123
|
+
# === DELETE ===
|
124
|
+
|
125
|
+
def stopSlow
|
126
|
+
result = self.class.delete("/_db/#{@database}/_api/query/slow").parsed_response
|
127
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
128
|
+
end
|
129
|
+
|
130
|
+
def kill(id: @id)
|
131
|
+
result = self.class.delete("/_db/#{@database}/_api/query/#{id}").parsed_response
|
132
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
133
|
+
end
|
134
|
+
|
135
|
+
def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil)
|
136
|
+
body = {
|
137
|
+
"slowQueryThreshold" => slowQueryThreshold,
|
138
|
+
"enabled" => enabled,
|
139
|
+
"maxSlowQueries" => maxSlowQueries,
|
140
|
+
"trackSlowQueries" => trackSlowQueries,
|
141
|
+
"maxQueryStringLength" => maxQueryStringLength
|
142
|
+
}.delete_if{|k,v| v.nil?}
|
143
|
+
new_Document = { :body => body.to_json }
|
144
|
+
result = self.class.put("/_db/#{@database}/_api/query/properties", new_Document).parsed_response
|
145
|
+
return_result(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
|
185
|
+
end
|
186
|
+
|
187
|
+
# === UTILITY ===
|
188
|
+
|
189
|
+
def return_result(result)
|
190
|
+
if @@verbose
|
191
|
+
result
|
192
|
+
else
|
193
|
+
if result["error"]
|
194
|
+
result["errorMessage"]
|
195
|
+
else
|
196
|
+
result.delete("error")
|
197
|
+
result.delete("code")
|
198
|
+
result
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
data/lib/ArangoRB_Col.rb
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
# === COLLECTION ===
|
2
|
+
|
3
|
+
class ArangoC < ArangoS
|
4
|
+
def initialize(collection: @@collection, database: @@database, body: {}, type: nil)
|
5
|
+
if collection.is_a?(String)
|
6
|
+
@collection = collection
|
7
|
+
else
|
8
|
+
raise "collection should be a String, not a #{collection.class}"
|
9
|
+
end
|
10
|
+
|
11
|
+
if database.is_a?(String)
|
12
|
+
@database = database
|
13
|
+
else
|
14
|
+
raise "database should be a String, not a #{database.class}"
|
15
|
+
end
|
16
|
+
|
17
|
+
if body.is_a?(Hash)
|
18
|
+
@body = body
|
19
|
+
else
|
20
|
+
raise "body should be a String, not a #{body.class}"
|
21
|
+
end
|
22
|
+
|
23
|
+
if !@type.nil? && @type != "Document" && @type != "Edge"
|
24
|
+
raise "type should be \"Document\" or \"Edge\""
|
25
|
+
else
|
26
|
+
@type = type
|
27
|
+
if @type == "Document"
|
28
|
+
@body["type"] = 2
|
29
|
+
elsif @type == "Edge"
|
30
|
+
@body["type"] = 3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :database, :collection, :body, :type
|
36
|
+
|
37
|
+
# === GET ===
|
38
|
+
|
39
|
+
def retrieve
|
40
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}").parsed_response
|
41
|
+
self.return_result(result, true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def properties
|
45
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/properties").parsed_response
|
46
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result
|
47
|
+
end
|
48
|
+
|
49
|
+
def count
|
50
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/count").parsed_response
|
51
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["count"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def stats
|
55
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/figures").parsed_response
|
56
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["figures"]
|
57
|
+
end
|
58
|
+
|
59
|
+
# def revisions
|
60
|
+
# self.class.get("/_db/#{@database}/_api/collection/#{@collection}/revisions").parsed_response
|
61
|
+
# end
|
62
|
+
|
63
|
+
def checksum(withRevisions: nil, withData: nil)
|
64
|
+
query = {
|
65
|
+
"withRevisions": withRevisions,
|
66
|
+
"withData": withData
|
67
|
+
}.delete_if{|k,v| v.nil?}
|
68
|
+
new_Document = { :query => query }
|
69
|
+
result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/checksum", new_Document).parsed_response
|
70
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["checksum"]
|
71
|
+
end
|
72
|
+
|
73
|
+
# === POST ===
|
74
|
+
|
75
|
+
def create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil)
|
76
|
+
body = {
|
77
|
+
"name" => collection,
|
78
|
+
"type" => type,
|
79
|
+
"journalSize" => journalSize,
|
80
|
+
"keyOptions" => keyOptions,
|
81
|
+
"waitForSync" => waitForSync,
|
82
|
+
"doCompact" => doCompact,
|
83
|
+
"isVolatile" => isVolatile,
|
84
|
+
"shardKeys" => shardKeys,
|
85
|
+
"numberOfShards" => numberOfShards,
|
86
|
+
"isSystem" => isSystem,
|
87
|
+
"indexBuckets" => indexBuckets
|
88
|
+
}
|
89
|
+
body = body.delete_if{|k,v| v.nil?}.to_json
|
90
|
+
new_Collection = { :body => body }
|
91
|
+
result = self.class.post("/_db/#{@database}/_api/collection", new_Collection).parsed_response
|
92
|
+
self.return_result(result, true)
|
93
|
+
end
|
94
|
+
alias create_collection create
|
95
|
+
alias create_document_collection create
|
96
|
+
alias create_vertex_collection create
|
97
|
+
|
98
|
+
def create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil)
|
99
|
+
self.create type: 3, journalSize: journalSize, keyOptions: keyOptions, waitForSync: waitForSync, doCompact: doCompact, isVolatile: isVolatile, shardKeys: shardKeys, numberOfShards: numberOfShards, isSystem: isSystem, indexBuckets: indexBuckets
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_document(document: {}, waitForSync: nil, returnNew: nil)
|
103
|
+
if document.is_a? Hash
|
104
|
+
body = document
|
105
|
+
elsif document.is_a? ArangoDoc
|
106
|
+
body = document.body
|
107
|
+
elsif document.is_a? Array
|
108
|
+
body = document.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDoc) ? x.body : nil}
|
109
|
+
else
|
110
|
+
raise "document should be Hash, an ArangoDoc instance or an Array of Hashes or ArangoDoc instances"
|
111
|
+
end
|
112
|
+
ArangoDoc.create(body: body, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
113
|
+
end
|
114
|
+
alias create_vertex create_document
|
115
|
+
|
116
|
+
def create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil)
|
117
|
+
if document.is_a? Hash
|
118
|
+
body = document
|
119
|
+
elsif document.is_a? ArangoDoc
|
120
|
+
body = document.body
|
121
|
+
elsif document.is_a? Array
|
122
|
+
body = document.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDoc) ? x.body : nil}
|
123
|
+
else
|
124
|
+
raise "document should be Hash, an ArangoDoc instance or an Array of Hashes or ArangoDoc instances"
|
125
|
+
end
|
126
|
+
ArangoDoc.create_edge(body: body, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection)
|
127
|
+
end
|
128
|
+
|
129
|
+
# === DELETE ===
|
130
|
+
|
131
|
+
def destroy
|
132
|
+
result = self.class.delete("/_db/#{@database}/_api/collection/#{@collection}").parsed_response
|
133
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
134
|
+
end
|
135
|
+
|
136
|
+
def truncate
|
137
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/truncate").parsed_response
|
138
|
+
self.return_result(result)
|
139
|
+
end
|
140
|
+
|
141
|
+
# === MODIFY ===
|
142
|
+
|
143
|
+
def load
|
144
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/load").parsed_response
|
145
|
+
self.return_result(result)
|
146
|
+
end
|
147
|
+
|
148
|
+
def unload
|
149
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/unload").parsed_response
|
150
|
+
self.return_result(result)
|
151
|
+
end
|
152
|
+
|
153
|
+
def change(waitForSync: nil, journalSize: nil)
|
154
|
+
body = {
|
155
|
+
"journalSize" => journalSize,
|
156
|
+
"waitForSync" => waitForSync
|
157
|
+
}
|
158
|
+
body = body.delete_if{|k,v| k.nil?}.to_json
|
159
|
+
new_Collection = { :body => body }
|
160
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/properties", new_Collection).parsed_response
|
161
|
+
self.return_result(result)
|
162
|
+
end
|
163
|
+
|
164
|
+
def rename(newName)
|
165
|
+
body = { "name" => newName }
|
166
|
+
new_Collection = { :body => body.to_json }
|
167
|
+
result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rename", new_Collection).parsed_response
|
168
|
+
@collection = newName unless result["error"]
|
169
|
+
self.return_result(result)
|
170
|
+
end
|
171
|
+
|
172
|
+
# === SIMPLE FUNCTIONS ===
|
173
|
+
|
174
|
+
def documents(type: nil) # "path", "id", "key"
|
175
|
+
body = {
|
176
|
+
"collection" => @collection,
|
177
|
+
"type" => type
|
178
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
179
|
+
collection_to_look = { :body => body }
|
180
|
+
result = self.class.put("/_db/#{@database}/_api/simple/all-keys", collection_to_look).parsed_response
|
181
|
+
if type.nil?
|
182
|
+
if @@verbose
|
183
|
+
result
|
184
|
+
else
|
185
|
+
if result["error"]
|
186
|
+
result["errorMessage"]
|
187
|
+
else
|
188
|
+
result["result"].map{|x| value = self.class.get(x).parsed_response; ArangoDoc.new(key: value["_key"], collection: @collection, body: value)}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
else
|
192
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def allDocuments(skip: nil, limit: nil, batchSize: nil)
|
197
|
+
body = {
|
198
|
+
"collection" => @collection,
|
199
|
+
"skip" => skip,
|
200
|
+
"limit" => limit,
|
201
|
+
"batchSize" => batchSize
|
202
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
203
|
+
collection_to_look = { :body => body }
|
204
|
+
result = self.class.put("/_db/#{@database}/_api/simple/all", collection_to_look).parsed_response
|
205
|
+
if @@verbose
|
206
|
+
result
|
207
|
+
else
|
208
|
+
if result["error"]
|
209
|
+
result["errorMessage"]
|
210
|
+
else
|
211
|
+
result["result"].map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, body: x)}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil)
|
217
|
+
body = {
|
218
|
+
"collection" => @collection,
|
219
|
+
"example" => match,
|
220
|
+
"skip" => skip,
|
221
|
+
"limit" => limit,
|
222
|
+
"batchSize" => batchSize
|
223
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
224
|
+
collection_to_look = { :body => body }
|
225
|
+
result = self.class.put("/_db/#{@database}/_api/simple/by-example", collection_to_look).parsed_response
|
226
|
+
if @@verbose
|
227
|
+
result
|
228
|
+
else
|
229
|
+
if result["error"]
|
230
|
+
result["errorMessage"]
|
231
|
+
else
|
232
|
+
result["result"].map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, body: x)}
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def documentMatch(match:)
|
238
|
+
body = {
|
239
|
+
"collection" => @collection,
|
240
|
+
"example" => match
|
241
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
242
|
+
collection_to_look = { :body => body }
|
243
|
+
result = self.class.put("/_db/#{@database}/_api/simple/first-example", collection_to_look).parsed_response
|
244
|
+
if @@verbose
|
245
|
+
result
|
246
|
+
else
|
247
|
+
if result["error"]
|
248
|
+
result["errorMessage"]
|
249
|
+
else
|
250
|
+
ArangoDoc.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def documentByKeys(keys:)
|
256
|
+
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDoc) ? x.key : nil} if keys.is_a? Array
|
257
|
+
keys = [keys] if keys.is_a? String
|
258
|
+
body = { "collection" => @collection, "keys" => keys }
|
259
|
+
collection_to_look = { :body => body.to_json }
|
260
|
+
result = self.class.put("/_db/#{@database}/_api/simple/lookup-by-keys", collection_to_look).parsed_response
|
261
|
+
if @@verbose
|
262
|
+
result
|
263
|
+
else
|
264
|
+
if result["error"]
|
265
|
+
result["errorMessage"]
|
266
|
+
else
|
267
|
+
result["documents"].map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, body: x)}
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def random
|
273
|
+
body = { "collection" => @collection }
|
274
|
+
collection_to_look = { :body => body.to_json }
|
275
|
+
result = self.class.put("/_db/#{@database}/_api/simple/any", collection_to_look)
|
276
|
+
if @@verbose
|
277
|
+
result
|
278
|
+
else
|
279
|
+
if result["error"]
|
280
|
+
result["errorMessage"]
|
281
|
+
else
|
282
|
+
ArangoDoc.new(key: result["document"]["_key"], collection: @collection, body: result["document"])
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def removeByKeys(keys:, options: nil)
|
288
|
+
keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDoc) ? x.key : nil}
|
289
|
+
body = { "collection" => @collection, "keys" => keys, "options" => options }.delete_if{|k,v| v.nil?}
|
290
|
+
collection_to_look = { :body => body.to_json }
|
291
|
+
self.class.put("/_db/#{@database}/_api/simple/remove-by-keys", collection_to_look).parsed_response
|
292
|
+
end
|
293
|
+
|
294
|
+
def removeMatch(match:, options: nil)
|
295
|
+
body = {
|
296
|
+
"collection" => @collection,
|
297
|
+
"example" => match,
|
298
|
+
"options" => option
|
299
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
300
|
+
collection_to_look = { :body => body }
|
301
|
+
self.class.put("/_db/#{@database}/_api/simple/remove-by-example", collection_to_look).parsed_response
|
302
|
+
end
|
303
|
+
|
304
|
+
def replaceMatch(match:, newValue:, options: nil)
|
305
|
+
body = {
|
306
|
+
"collection" => @collection,
|
307
|
+
"example" => match,
|
308
|
+
"options" => option,
|
309
|
+
"newValue" => newValue
|
310
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
311
|
+
collection_to_look = { :body => body }
|
312
|
+
self.class.put("/_db/#{@database}/_api/simple/replace-by-example", collection_to_look).parsed_response
|
313
|
+
end
|
314
|
+
|
315
|
+
def updateMatch(match:, newValue:, options: nil)
|
316
|
+
body = {
|
317
|
+
"collection" => @collection,
|
318
|
+
"example" => match,
|
319
|
+
"options" => option,
|
320
|
+
"newValue" => newValue
|
321
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
322
|
+
collection_to_look = { :body => body }
|
323
|
+
self.class.put("/_db/#{@database}/_api/simple/update-by-example", collection_to_look).parsed_response
|
324
|
+
end
|
325
|
+
|
326
|
+
# === UTILITY ===
|
327
|
+
|
328
|
+
def return_result(result, checkType=false)
|
329
|
+
if @@verbose
|
330
|
+
resultTemp = result
|
331
|
+
unless result["errorMessage"]
|
332
|
+
result.delete("error")
|
333
|
+
result.delete("code")
|
334
|
+
@body = result
|
335
|
+
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
336
|
+
end
|
337
|
+
resultTemp
|
338
|
+
else
|
339
|
+
if result["error"]
|
340
|
+
result["errorMessage"]
|
341
|
+
else
|
342
|
+
result.delete("error")
|
343
|
+
result.delete("code")
|
344
|
+
@body = result
|
345
|
+
@type = result["type"] == 2 ? "Document" : "Edge" if(checkType)
|
346
|
+
self
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|