Class: ArangoCollection
- Inherits:
-
ArangoServer
- Object
- ArangoServer
- ArangoCollection
- Defined in:
- lib/ArangoRB_Col.rb
Overview
COLLECTION ===
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#collection ⇒ Object
(also: #name)
readonly
Returns the value of attribute collection.
-
#idCache ⇒ Object
readonly
Returns the value of attribute idCache.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](document_name) ⇒ Object (also: #document)
-
#allDocuments(skip: nil, limit: nil, batchSize: nil) ⇒ Object
TESTED.
-
#change(waitForSync: nil, journalSize: nil) ⇒ Object
TESTED.
-
#checksum(withRevisions: nil, withData: nil) ⇒ Object
TESTED.
-
#count ⇒ Object
TESTED.
-
#create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) ⇒ Object
(also: #create_collection, #create_document_collection, #create_vertex_collection)
POST ===.
-
#create_document(document: {}, waitForSync: nil, returnNew: nil) ⇒ Object
(also: #create_vertex)
TESTED.
-
#create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil) ⇒ Object
TESTED.
-
#create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) ⇒ Object
TESTED.
-
#createIndex(body: {}, unique: nil, type:, fields:, id: nil) ⇒ Object
TESTED.
-
#data(from: nil, to: nil, chunkSize: nil, includeSystem: false, failOnUnknown: nil, ticks: nil, flush: nil) ⇒ Object
(also: #dump)
REPLICATION ===.
- #database ⇒ Object
-
#destroy ⇒ Object
DELETE ===.
-
#documentByKeys(keys:) ⇒ Object
TESTED.
-
#documentMatch(match:) ⇒ Object
TESTED.
-
#documents(type: nil) ⇒ Object
SIMPLE FUNCTIONS ===.
-
#documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) ⇒ Object
TESTED.
-
#export(count: nil, restrict: nil, batchSize: nil, flush: nil, limit: nil, ttl: nil) ⇒ Object
EXPORT ===.
-
#exportNext ⇒ Object
TESTED.
-
#import(attributes:, values:, from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
IMPORT ===.
-
#importJSON(body:, type: "auto", from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
TESTED.
-
#indexes ⇒ Object
def retrieveIndex(id:) # TESTED result = self.class.get(“/_db/#@database/_api/index/#@collection/#id”, @@request) if @@async == “store” result.headers else result = result.parsed_response if @@verbose result else if result result else ArangoIndex.new(body: result, id: result, database: @database, collection: @collection, type: result, unique: result, fields: result) end end end end.
-
#initialize(collection: @@collection, database: @@database, body: {}, type: nil) ⇒ ArangoCollection
constructor
TESTED.
-
#load ⇒ Object
MODIFY ===.
-
#properties ⇒ Object
TESTED.
-
#random ⇒ Object
TESTED.
-
#removeByKeys(keys:, options: nil) ⇒ Object
TESTED.
-
#removeMatch(match:, options: nil) ⇒ Object
TESTED.
-
#rename(newName) ⇒ Object
TESTED.
-
#replaceMatch(match:, newValue:, options: nil) ⇒ Object
TESTED.
-
#retrieve ⇒ Object
GET ===.
-
#return_result(result:, caseTrue: false, key: nil, checkType: false) ⇒ Object
UTILITY ===.
-
#revision ⇒ Object
TESTED.
- #rotate ⇒ Object
-
#statistics ⇒ Object
TESTED.
-
#to_hash ⇒ Object
(also: #to_h)
RETRIEVE ===.
-
#truncate ⇒ Object
TESTED.
-
#unload ⇒ Object
TESTED.
-
#updateMatch(match:, newValue:, options: nil) ⇒ Object
TESTED.
Methods inherited from ArangoServer
address, async, async=, batch, cancelAsync, changePropertyWAL, checkPort, cluster, cluster=, clusterRoundtrip, clusterStatistics, collection, collection=, createDumpBatch, database, database=, databaseVersion, databases, default_server, destroyAllAsync, destroyAsync, destroyCluster, destroyDumpBatch, destroyExpiredAsync, echo, endpoints, execute, executeCluster, executeClusterHead, executeClusterPut, fetchAsync, flushWAL, graph, graph=, log, pendingAsync, prolongDumpBatch, propertyWAL, reload, request, restart, retrieveAsync, retrieveDoneAsync, retrievePendingAsync, return_result, return_result_async, role, server, serverId, shutdown, sleep, statistics, tasks, test, time, transactions, updateCluster, user, user=, username, users, verbose, verbose=, version
Constructor Details
#initialize(collection: @@collection, database: @@database, body: {}, type: nil) ⇒ ArangoCollection
TESTED
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ArangoRB_Col.rb', line 4 def initialize(collection: @@collection, database: @@database, body: {}, type: nil) # TESTED if collection.is_a?(String) @collection = collection elsif collection.is_a?(ArangoCollection) @collection = collection.collection else raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}" end if database.is_a?(String) @database = database elsif database.is_a?(ArangoDatabase) @database = database.database else raise "database should be a String or an ArangoDatabase instance, not a #{database.class}" end if body.is_a?(Hash) @body = body else raise "body should be a Hash, not a #{body.class}" end if !@type.nil? && @type != "Document" && @type != "Edge" raise "type should be \"Document\" or \"Edge\"" else @type = type if @type == "Document" @body["type"] = 2 elsif @type == "Edge" @body["type"] = 3 end end @idCache = "COL_#{@collection}" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
40 41 42 |
# File 'lib/ArangoRB_Col.rb', line 40 def body @body end |
#collection ⇒ Object (readonly) Also known as: name
Returns the value of attribute collection.
40 41 42 |
# File 'lib/ArangoRB_Col.rb', line 40 def collection @collection end |
#idCache ⇒ Object (readonly)
Returns the value of attribute idCache.
40 41 42 |
# File 'lib/ArangoRB_Col.rb', line 40 def idCache @idCache end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
40 41 42 |
# File 'lib/ArangoRB_Col.rb', line 40 def type @type end |
Instance Method Details
#[](document_name) ⇒ Object Also known as: document
56 57 58 |
# File 'lib/ArangoRB_Col.rb', line 56 def [](document_name) ArangoDocument.new(key: document_name, collection: @collection, database: @database) end |
#allDocuments(skip: nil, limit: nil, batchSize: nil) ⇒ Object
TESTED
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/ArangoRB_Col.rb', line 210 def allDocuments(skip: nil, limit: nil, batchSize: nil) # TESTED body = { "collection" => @collection, "skip" => skip, "limit" => limit, "batchSize" => batchSize }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/all", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)} end |
#change(waitForSync: nil, journalSize: nil) ⇒ Object
TESTED
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ArangoRB_Col.rb', line 167 def change(waitForSync: nil, journalSize: nil) # TESTED body = { "journalSize" => journalSize, "waitForSync" => waitForSync } body = body.delete_if{|k,v| k.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/properties", request) self.return_result result: result end |
#checksum(withRevisions: nil, withData: nil) ⇒ Object
TESTED
93 94 95 96 97 98 99 100 101 |
# File 'lib/ArangoRB_Col.rb', line 93 def checksum(withRevisions: nil, withData: nil) # TESTED query = { "withRevisions": withRevisions, "withData": withData }.delete_if{|k,v| v.nil?} request = @@request.merge({ :query => query }) result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/checksum", request) self.return_result result: result, key: "checksum" end |
#count ⇒ Object
TESTED
78 79 80 81 |
# File 'lib/ArangoRB_Col.rb', line 78 def count # TESTED result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/count", @@request) self.return_result result: result, key: "count" end |
#create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) ⇒ Object Also known as: create_collection, create_document_collection, create_vertex_collection
POST ===
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ArangoRB_Col.rb', line 105 def create(type: nil, journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) # TESTED type = 3 if type == "Edge" type = nil if type == "Document" body = { "name" => collection, "type" => type, "journalSize" => journalSize, "keyOptions" => keyOptions, "waitForSync" => waitForSync, "doCompact" => doCompact, "isVolatile" => isVolatile, "shardKeys" => shardKeys, "numberOfShards" => numberOfShards, "isSystem" => isSystem, "indexBuckets" => indexBuckets } body = body.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.post("/_db/#{@database}/_api/collection", request) self.return_result result: result, checkType: true end |
#create_document(document: {}, waitForSync: nil, returnNew: nil) ⇒ Object Also known as: create_vertex
TESTED
134 135 136 |
# File 'lib/ArangoRB_Col.rb', line 134 def create_document(document: {}, waitForSync: nil, returnNew: nil) # TESTED ArangoDocument.create(body: document, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection) end |
#create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil) ⇒ Object
TESTED
139 140 141 |
# File 'lib/ArangoRB_Col.rb', line 139 def create_edge(document: {}, from:, to:, waitForSync: nil, returnNew: nil) # TESTED ArangoDocument.create_edge(body: document, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: @database, collection: @collection) end |
#create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) ⇒ Object
TESTED
130 131 132 |
# File 'lib/ArangoRB_Col.rb', line 130 def create_edge_collection(journalSize: nil, keyOptions: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: nil, indexBuckets: nil) # TESTED self.create type: 3, journalSize: journalSize, keyOptions: keyOptions, waitForSync: waitForSync, doCompact: doCompact, isVolatile: isVolatile, shardKeys: shardKeys, numberOfShards: numberOfShards, isSystem: isSystem, indexBuckets: indexBuckets end |
#createIndex(body: {}, unique: nil, type:, fields:, id: nil) ⇒ Object
TESTED
448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/ArangoRB_Col.rb', line 448 def createIndex(body: {}, unique: nil, type:, fields:, id: nil) # TESTED body["fields"] = fields.is_a?(Array) ? fields : [fields] body["unique"] = unique unless unique.nil? body["type"] = type unless type.nil? body["id"] = id unless type.nil? query = { "collection": @collection } request = @@request.merge({ :body => body.to_json, :query => query }) result = self.class.post("/_db/#{@database}/_api/index", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@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"]) end |
#data(from: nil, to: nil, chunkSize: nil, includeSystem: false, failOnUnknown: nil, ticks: nil, flush: nil) ⇒ Object Also known as: dump
REPLICATION ===
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/ArangoRB_Col.rb', line 482 def data(from: nil, to: nil, chunkSize: nil, includeSystem: false, failOnUnknown: nil, ticks: nil, flush: nil) # TESTED query = { "collection": @collection, "from": from, "to": to, "chunkSize": chunkSize, "includeSystem": includeSystem, "failOnUnknown": failOnUnknown, "ticks": ticks, "flush": flush }.delete_if{|k,v| v.nil?} request = @@request.merge({ :query => query }) result = self.class.get("/_db/#{@database}/_api/replication/dump", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response return nil if result.nil? @@verbose ? result : result["error"] ? result["errorMessage"] : result end |
#database ⇒ Object
61 62 63 |
# File 'lib/ArangoRB_Col.rb', line 61 def database ArangoDatabase.new(database: @database) end |
#destroy ⇒ Object
DELETE ===
145 146 147 148 |
# File 'lib/ArangoRB_Col.rb', line 145 def destroy # TESTED result = self.class.delete("/_db/#{@database}/_api/collection/#{@collection}", @@request) self.return_result result: result, caseTrue: true end |
#documentByKeys(keys:) ⇒ Object
TESTED
254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ArangoRB_Col.rb', line 254 def documentByKeys(keys:) # TESTED keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDocument) ? x.key : nil} if keys.is_a? Array keys = [keys] if keys.is_a? String body = { "collection" => @collection, "keys" => keys } request = @@request.merge({ :body => body.to_json }) result = self.class.put("/_db/#{@database}/_api/simple/lookup-by-keys", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["documents"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)} end |
#documentMatch(match:) ⇒ Object
TESTED
241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/ArangoRB_Col.rb', line 241 def documentMatch(match:) # TESTED body = { "collection" => @collection, "example" => match }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/first-example", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"]) end |
#documents(type: nil) ⇒ Object
SIMPLE FUNCTIONS ===
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ArangoRB_Col.rb', line 193 def documents(type: nil) # "path", "id", "key" # TESTED body = { "collection" => @collection, "type" => type }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/all-keys", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if type.nil? @@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)} else @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"] end end |
#documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) ⇒ Object
TESTED
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ArangoRB_Col.rb', line 225 def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) # TESTED body = { "collection" => @collection, "example" => match, "skip" => skip, "limit" => limit, "batchSize" => batchSize }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/by-example", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, body: x)} end |
#export(count: nil, restrict: nil, batchSize: nil, flush: nil, limit: nil, ttl: nil) ⇒ Object
EXPORT ===
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/ArangoRB_Col.rb', line 364 def export(count: nil, restrict: nil, batchSize: nil, flush: nil, limit: nil, ttl: nil) # TESTED query = { "collection" => @collection } body = { "count" => count, "restrict" => restrict, "batchSize" => batchSize, "flush" => flush, "limit" => limit, "ttl" => ttl }.delete_if{|k,v| v.nil?} request = @@request.merge({ :body => body.to_json, :query => query }) result = self.class.post("/_db/#{@database}/_api/export", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response return @@verbose ? result : result["errorMessage"] if result["error"] @countExport = result["count"] @hasMoreExport = result["hasMore"] @idExport = result["id"] if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key")) result = result["result"] else result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: x)} end result end |
#exportNext ⇒ Object
TESTED
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/ArangoRB_Col.rb', line 391 def exportNext # TESTED unless @hasMoreExport print "No other results" else query = { "collection": @collection } request = @@request.merge({ :query => query }) result = self.class.put("/_db/#{@database}/_api/export/#{@idExport}", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response return @@verbose ? result : result["errorMessage"] if result["error"] @countExport = result["count"] @hasMoreExport = result["hasMore"] @idExport = result["id"] if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key")) result = result["result"] else result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: x)} end result end end |
#import(attributes:, values:, from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
IMPORT ===
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ArangoRB_Col.rb', line 321 def import(attributes:, values:, from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) # TESTED query = { "collection": @collection, "fromPrefix": from, "toPrefix": to, "overwrite": overwrite, "waitForSync": waitForSync, "onDuplicate": onDuplicate, "complete": complete, "details": details }.delete_if{|k,v| v.nil?} body = "#{attributes}\n" values[0].is_a?(Array) ? values.each{|x| body += "#{x}\n"} : body += "#{values}\n" request = @@request.merge({ :body => body, :query => query }) result = self.class.post("/_db/#{@database}/_api/import", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result.delete_if{|k,v| k == "error" || k == "code"} end |
#importJSON(body:, type: "auto", from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
TESTED
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/ArangoRB_Col.rb', line 342 def importJSON(body:, type: "auto", from: nil, to: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) # TESTED query = { "collection": @collection, "type": type, "fromPrefix": from, "toPrefix": to, "overwrite": overwrite, "waitForSync": waitForSync, "onDuplicate": onDuplicate, "complete": complete, "details": details }.delete_if{|k,v| v.nil?} request = @@request.merge({ :body => body.to_json, :query => query }) result = self.class.post("/_db/#{@database}/_api/import", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result.delete_if{|k,v| k == "error" || k == "code"} end |
#indexes ⇒ Object
def retrieveIndex(id:) # TESTED
result = self.class.get("/_db/#{@database}/_api/index/#{@collection}/#{id}", @@request)
if @@async == "store"
result.headers["x-arango-async-id"]
else
result = result.parsed_response
if @@verbose
result
else
if result["error"]
result["errorMessage"]
else
ArangoIndex.new(body: result, id: result["id"], database: @database, collection: @collection, type: result["type"], unique: result["unique"], fields: result["fields"])
end
end
end
end
434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/ArangoRB_Col.rb', line 434 def indexes # TESTED query = { "collection": @collection } request = @@request.merge({ :query => query }) result = self.class.get("/_db/#{@database}/_api/index", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response return result if @@verbose return result["errorMessage"] if result["error"] result.delete_if{|k,v| k == "error" || k == "code"} 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"])} result end |
#load ⇒ Object
MODIFY ===
157 158 159 160 |
# File 'lib/ArangoRB_Col.rb', line 157 def load # TESTED result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/load", @@request) self.return_result result: result end |
#properties ⇒ Object
TESTED
72 73 74 75 76 |
# File 'lib/ArangoRB_Col.rb', line 72 def properties # TESTED result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/properties", @@request) result = self.return_result result: result return result.is_a?(ArangoCollection) ? result.body : result end |
#random ⇒ Object
TESTED
266 267 268 269 270 271 272 273 274 |
# File 'lib/ArangoRB_Col.rb', line 266 def random # TESTED body = { "collection" => @collection }.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/any", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["document"]["_key"], collection: @collection, body: result["document"]) end |
#removeByKeys(keys:, options: nil) ⇒ Object
TESTED
276 277 278 279 280 281 282 |
# File 'lib/ArangoRB_Col.rb', line 276 def removeByKeys(keys:, options: nil) # TESTED keys = keys.map{|x| x.is_a?(String) ? x : x.is_a?(ArangoDocument) ? x.key : nil} body = { "collection" => @collection, "keys" => keys, "options" => }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/remove-by-keys", request) self.return_result result: result, key: "removed" end |
#removeMatch(match:, options: nil) ⇒ Object
TESTED
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/ArangoRB_Col.rb', line 284 def removeMatch(match:, options: nil) # TESTED body = { "collection" => @collection, "example" => match, "options" => }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/remove-by-example", request) self.return_result result: result, key: "deleted" end |
#rename(newName) ⇒ Object
TESTED
178 179 180 181 182 183 184 |
# File 'lib/ArangoRB_Col.rb', line 178 def rename(newName) # TESTED body = { "name" => newName } request = @@request.merge({ :body => body.to_json }) result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rename", request) @collection = newName unless result.parsed_response["error"] self.return_result result: result end |
#replaceMatch(match:, newValue:, options: nil) ⇒ Object
TESTED
295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/ArangoRB_Col.rb', line 295 def replaceMatch(match:, newValue:, options: nil) # TESTED body = { "collection" => @collection, "example" => match, "options" => , "newValue" => newValue }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/replace-by-example", request) self.return_result result: result, key: "replaced" end |
#retrieve ⇒ Object
GET ===
67 68 69 70 |
# File 'lib/ArangoRB_Col.rb', line 67 def retrieve # TESTED result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}", @@request) self.return_result result: result, checkType: true end |
#return_result(result:, caseTrue: false, key: nil, checkType: false) ⇒ Object
UTILITY ===
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/ArangoRB_Col.rb', line 505 def return_result(result:, caseTrue: false, key: nil, checkType: false) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose || !result.is_a?(Hash) resultTemp = result unless result["errorMessage"] result.delete_if{|k,v| k == "error" || k == "code"} @body = result @type = result["type"] == 2 ? "Document" : "Edge" if(checkType) end resultTemp else return result["errorMessage"] if result["error"] return true if caseTrue result.delete_if{|k,v| k == "error" || k == "code"} @body = result @type = result["type"] == 2 ? "Document" : "Edge" if(checkType) key.nil? ? self : result[key] end end |
#revision ⇒ Object
TESTED
88 89 90 91 |
# File 'lib/ArangoRB_Col.rb', line 88 def revision # TESTED result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/revision", @@request) self.return_result result: result, key: "revision" end |
#rotate ⇒ Object
186 187 188 189 |
# File 'lib/ArangoRB_Col.rb', line 186 def rotate result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/rotate", @@request) self.return_result result: result, caseTrue: true end |
#statistics ⇒ Object
TESTED
83 84 85 86 |
# File 'lib/ArangoRB_Col.rb', line 83 def statistics # TESTED result = self.class.get("/_db/#{@database}/_api/collection/#{@collection}/figures", @@request) self.return_result result: result, key: "figures" end |
#to_hash ⇒ Object Also known as: to_h
RETRIEVE ===
45 46 47 48 49 50 51 52 53 |
# File 'lib/ArangoRB_Col.rb', line 45 def to_hash { "collection" => @collection, "database" => @database, "type" => @type, "body" => @body, "idCache" => @idCache }.delete_if{|k,v| v.nil?} end |
#truncate ⇒ Object
TESTED
150 151 152 153 |
# File 'lib/ArangoRB_Col.rb', line 150 def truncate # TESTED result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/truncate", @@request) self.return_result result: result end |
#unload ⇒ Object
TESTED
162 163 164 165 |
# File 'lib/ArangoRB_Col.rb', line 162 def unload # TESTED result = self.class.put("/_db/#{@database}/_api/collection/#{@collection}/unload", @@request) self.return_result result: result end |
#updateMatch(match:, newValue:, options: nil) ⇒ Object
TESTED
307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/ArangoRB_Col.rb', line 307 def updateMatch(match:, newValue:, options: nil) # TESTED body = { "collection" => @collection, "example" => match, "options" => , "newValue" => newValue }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.put("/_db/#{@database}/_api/simple/update-by-example", request) self.return_result result: result, key: "updated" end |