Class: Arango::Collection
- Inherits:
-
Object
- Object
- Arango::Collection
- Includes:
- Database_Return, Helper_Error, Helper_Return
- Defined in:
- lib/Collection.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
DEFINE ===.
-
#cache_name ⇒ Object
readonly
DEFINE ===.
-
#countExport ⇒ Object
readonly
DEFINE ===.
-
#database ⇒ Object
readonly
DEFINE ===.
-
#graph ⇒ Object
DEFINE ===.
-
#hasMoreExport ⇒ Object
readonly
DEFINE ===.
-
#hasMoreSimple ⇒ Object
readonly
DEFINE ===.
-
#id ⇒ Object
readonly
DEFINE ===.
-
#idExport ⇒ Object
readonly
DEFINE ===.
-
#idSimple ⇒ Object
readonly
DEFINE ===.
-
#isSystem ⇒ Object
readonly
DEFINE ===.
-
#name ⇒ Object
Returns the value of attribute name.
-
#server ⇒ Object
readonly
DEFINE ===.
-
#status ⇒ Object
readonly
DEFINE ===.
-
#type ⇒ Object
DEFINE ===.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](document_name) ⇒ Object
DOCUMENT ==.
- #addUserAccess(grant:, user:) ⇒ Object
- #allDocuments(skip: nil, limit: nil, batchSize: nil) ⇒ Object
- #change(waitForSync: nil, journalSize: nil) ⇒ Object
- #checksum(withRevisions: nil, withData: nil) ⇒ Object
- #count ⇒ Object
-
#create(journalSize: nil, replicationFactor: nil, allowUserKeys: nil, typeKeyGenerator: nil, incrementKeyGenerator: nil, offsetKeyGenerator: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: @isSystem, type: @type, indexBuckets: nil, distributeShardsLike: nil, shardingStrategy: nil) ⇒ Object
POST ==.
- #createDocuments(document: [], waitForSync: nil, returnNew: nil, silent: nil) ⇒ Object
- #createEdges(document: {}, from:, to:, waitForSync: nil, returnNew: nil, silent: nil) ⇒ Object
-
#data(batchId:, from: nil, to: nil, chunkSize: nil, includeSystem: nil, failOnUnknown: nil, ticks: nil, flush: nil) ⇒ Object
(also: #dump)
REPLICATION ===.
-
#destroy ⇒ Object
DELETE ===.
- #destroyDocuments(document: {}, waitForSync: nil, returnOld: nil, ignoreRevs: nil) ⇒ Object
- #document(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
- #documentByKeys(keys:) ⇒ Object
- #documentByName(names:, returnOld: nil, silent: nil, waitForSync: nil) ⇒ Object
- #documentMatch(match:) ⇒ Object
-
#documents(type: "document") ⇒ Object
“path”, “id”, “key”.
- #documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) ⇒ Object
- #edge(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
-
#export(count: nil, restrict: nil, batchSize: nil, flush: nil, flushWait: nil, limit: nil, ttl: nil) ⇒ Object
EXPORT ===.
- #exportNext ⇒ Object
- #fulltext(index:, attribute:, query:, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
-
#import(attributes:, values:, fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
IMPORT ===.
- #importJSON(body:, type: "auto", fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
-
#index(body: {}, id: nil, type: "hash", unique: nil, fields:, sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil) ⇒ Object
INDEXES ===.
- #indexes ⇒ Object
-
#initialize(name:, database:, graph: nil, body: {}, type: :document, isSystem: nil, cache_name: nil) ⇒ Collection
constructor
A new instance of Collection.
-
#load ⇒ Object
MODIFY ===.
- #loadIndexesIntoMemory ⇒ Object
- #near(distance: nil, longitude:, latitude:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
- #next ⇒ Object
- #properties ⇒ Object
- #random ⇒ Object
-
#range(right:, attribute:, limit: nil, closed: true, skip: nil, left:, warning: @server.warning) ⇒ Object
SIMPLE DEPRECATED ===.
- #removeByKeys(keys:, returnOld: nil, silent: nil, waitForSync: nil) ⇒ Object
- #removeMatch(match:, limit: nil, waitForSync: nil) ⇒ Object
- #rename(newName:) ⇒ Object
- #replaceDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) ⇒ Object
- #replaceMatch(match:, newValue:, limit: nil, waitForSync: nil) ⇒ Object
-
#retrieve ⇒ Object
GET ===.
- #revision ⇒ Object
- #revokeUserAccess(user:) ⇒ Object
- #rotate ⇒ Object
- #statistics ⇒ Object
-
#to_h ⇒ Object
TO HASH ===.
- #truncate ⇒ Object
- #unload ⇒ Object
- #updateDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) ⇒ Object
- #updateMatch(match:, newValue:, keepNull: nil, mergeObjects: nil, limit: nil, waitForSync: nil) ⇒ Object
- #userAccess(user:) ⇒ Object
-
#vertex(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
GRAPH ===.
- #within(distance: nil, longitude:, latitude:, radius:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
- #withinRectangle(longitude1:, latitude1:, longitude2:, latitude2:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
Methods included from Database_Return
Methods included from Helper_Return
#return_delete, #return_directly?, #return_element
Methods included from Helper_Error
#satisfy_category?, #satisfy_class?, #warning_deprecated
Constructor Details
#initialize(name:, database:, graph: nil, body: {}, type: :document, isSystem: nil, cache_name: nil) ⇒ Collection
Returns a new instance of Collection.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/Collection.rb', line 29 def initialize(name:, database:, graph: nil, body: {}, type: :document, isSystem: nil, cache_name: nil) @name = name assign_database(database) assign_graph(graph) assign_type(type) unless cache_name.nil? @cache_name = cache_name @server.cache.save(:collection, cache_name, self) end body[:type] ||= type == :document ? 2 : 3 body[:status] ||= nil body[:isSystem] ||= isSystem body[:id] ||= nil assign_attributes(body) end |
Instance Attribute Details
#body ⇒ Object
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def body @body end |
#cache_name ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def cache_name @cache_name end |
#countExport ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def countExport @countExport end |
#database ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def database @database end |
#graph ⇒ Object
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def graph @graph end |
#hasMoreExport ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def hasMoreExport @hasMoreExport end |
#hasMoreSimple ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def hasMoreSimple @hasMoreSimple end |
#id ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def id @id end |
#idExport ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def idExport @idExport end |
#idSimple ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def idSimple @idSimple end |
#isSystem ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def isSystem @isSystem end |
#name ⇒ Object
Returns the value of attribute name.
51 52 53 |
# File 'lib/Collection.rb', line 51 def name @name end |
#server ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def server @server end |
#status ⇒ Object (readonly)
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def status @status end |
#type ⇒ Object
DEFINE ===
48 49 50 |
# File 'lib/Collection.rb', line 48 def type @type end |
Class Method Details
.new(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/Collection.rb', line 9 def self.new(*args) hash = args[0] super unless hash.is_a?(Hash) database = hash[:database] if database.is_a?(Arango::Database) && database.server.active_cache cache_name = "#{database.name}/#{hash[:name]}" cached = database.server.cache.cache.dig(:database, cache_name) if cached.nil? hash[:cache_name] = cache_name return super else body = hash[:body] || {} [:type, :isSystem].each{|k| body[k] ||= hash[k]} cached.assign_attributes(body) return cached end end super end |
Instance Method Details
#[](document_name) ⇒ Object
DOCUMENT ==
242 243 244 |
# File 'lib/Collection.rb', line 242 def [](document_name) Arango::Document.new(name: document_name, collection: self) end |
#addUserAccess(grant:, user:) ⇒ Object
812 813 814 815 |
# File 'lib/Collection.rb', line 812 def addUserAccess(grant:, user:) user = check_user(user) user.add_collection_access(grant: grant, database: @database.name, collection: @name) end |
#allDocuments(skip: nil, limit: nil, batchSize: nil) ⇒ Object
445 446 447 448 449 450 451 452 453 |
# File 'lib/Collection.rb', line 445 def allDocuments(skip: nil, limit: nil, batchSize: nil) body = { "collection": @name, "skip": skip, "limit": limit, "batchSize": batchSize } generic_document_search("_api/simple/all", body) end |
#change(waitForSync: nil, journalSize: nil) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/Collection.rb', line 220 def change(waitForSync: nil, journalSize: nil) body = { "journalSize": journalSize, "waitForSync": waitForSync } result = @database.request("PUT", "_api/collection/#{@name}/properties", body: body) return_element(result) end |
#checksum(withRevisions: nil, withData: nil) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/Collection.rb', line 137 def checksum(withRevisions: nil, withData: nil) query = { "withRevisions": withRevisions, "withData": withData } @database.request("GET", "_api/collection/#{@name}/checksum", query: query, key: :checksum) end |
#count ⇒ Object
125 126 127 |
# File 'lib/Collection.rb', line 125 def count @database.request("GET", "_api/collection/#{@name}/count", key: :count) end |
#create(journalSize: nil, replicationFactor: nil, allowUserKeys: nil, typeKeyGenerator: nil, incrementKeyGenerator: nil, offsetKeyGenerator: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: @isSystem, type: @type, indexBuckets: nil, distributeShardsLike: nil, shardingStrategy: nil) ⇒ Object
POST ==
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/Collection.rb', line 148 def create(journalSize: nil, replicationFactor: nil, allowUserKeys: nil, typeKeyGenerator: nil, incrementKeyGenerator: nil, offsetKeyGenerator: nil, waitForSync: nil, doCompact: nil, isVolatile: nil, shardKeys: nil, numberOfShards: nil, isSystem: @isSystem, type: @type, indexBuckets: nil, distributeShardsLike: nil, shardingStrategy: nil) satisfy_category?(typeKeyGenerator, [nil, "traditional", "autoincrement"]) satisfy_category?(type, ["Edge", "Document", 2, 3, nil, :edge, :document]) satisfy_category?(shardingStrategy, [nil, "community-compat", "enterprise-compat", "enterprise-smart-edge-compat", "hash", "enterprise-hash-smart-edge"]) keyOptions = { "allowUserKeys": allowUserKeys, "type": typeKeyGenerator, "increment": incrementKeyGenerator, "offset": offsetKeyGenerator } keyOptions.delete_if{|k,v| v.nil?} keyOptions = nil if keyOptions.empty? type = case type when 2, "Document", nil, :document 2 when 3, "Edge", :edge 3 end body = { "name": @name, "type": type, "replicationFactor": replicationFactor, "journalSize": journalSize, "keyOptions": keyOptions, "waitForSync": waitForSync, "doCompact": doCompact, "isVolatile": isVolatile, "shardKeys": shardKeys, "numberOfShards": numberOfShards, "isSystem": isSystem, "indexBuckets": indexBuckets, "distributeShardsLike": distributeShardsLike, "shardingStrategy": shardingStrategy } body = @body.merge(body) result = @database.request("POST", "_api/collection", body: body) return_element(result) end |
#createDocuments(document: [], waitForSync: nil, returnNew: nil, silent: nil) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/Collection.rb', line 320 def createDocuments(document: [], waitForSync: nil, returnNew: nil, silent: nil) document = [document] unless document.is_a? Array document = document.map{|x| return_body(x)} query = { "waitForSync": waitForSync, "returnNew": returnNew, "silent": silent } results = @database.request("POST", "_api/document/#{@name}", body: document, query: query) return results if return_directly?(results) || silent results.map.with_index do |result, index| body2 = result.clone if returnNew body2.delete(:new) body2 = body2.merge(result[:new]) end real_body = document[index] real_body = real_body.merge(body2) Arango::Document.new(name: result[:_key], collection: self, body: real_body) end end |
#createEdges(document: {}, from:, to:, waitForSync: nil, returnNew: nil, silent: nil) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/Collection.rb', line 344 def createEdges(document: {}, from:, to:, waitForSync: nil, returnNew: nil, silent: nil) edges = [] from = [from] unless from.is_a? Array to = [to] unless to.is_a? Array document = [document] unless document.is_a? Array document = document.map{|x| return_body(x, :edge)} from = from.map{|x| return_id(x)} to = to.map{|x| return_id(x)} document.each do |b| from.each do |f| to.each do |t| b[:_from] = f b[:_to] = t edges << b.clone end end end createDocuments(document: edges, waitForSync: waitForSync, returnNew: returnNew, silent: silent) end |
#data(batchId:, from: nil, to: nil, chunkSize: nil, includeSystem: nil, failOnUnknown: nil, ticks: nil, flush: nil) ⇒ Object Also known as: dump
REPLICATION ===
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
# File 'lib/Collection.rb', line 787 def data(batchId:, from: nil, to: nil, chunkSize: nil, includeSystem: nil, failOnUnknown: nil, ticks: nil, flush: nil) query = { "collection": @name, "batchId": batchId, "from": from, "to": to, "chunkSize": chunkSize, "includeSystem": includeSystem, "failOnUnknown": failOnUnknown, "ticks": ticks, "flush": flush } @database.request("GET", "_api/replication/dump", query: query) end |
#destroy ⇒ Object
DELETE ===
193 194 195 196 |
# File 'lib/Collection.rb', line 193 def destroy result = @database.request("DELETE", "_api/collection/#{@name}") return return_delete(result) end |
#destroyDocuments(document: {}, waitForSync: nil, returnOld: nil, ignoreRevs: nil) ⇒ Object
416 417 418 419 420 421 422 423 424 425 |
# File 'lib/Collection.rb', line 416 def destroyDocuments(document: {}, waitForSync: nil, returnOld: nil, ignoreRevs: nil) document.each{|x| x = x.body if x.is_a?(Arango::Document)} query = { "waitForSync": waitForSync, "returnOld": returnOld, "ignoreRevs": ignoreRevs } @database.request("DELETE", "_api/document/#{@id}", query: query, body: document) end |
#document(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
246 247 248 249 |
# File 'lib/Collection.rb', line 246 def document(name: nil, body: {}, rev: nil, from: nil, to: nil) Arango::Document.new(name: name, collection: self, body: body, rev: rev, from: from, to: to) end |
#documentByKeys(keys:) ⇒ Object
474 475 476 477 478 479 480 481 482 483 |
# File 'lib/Collection.rb', line 474 def documentByKeys(keys:) keys = [keys] unless keys.is_a?(Array) keys = keys.map{|x| x.is_a?(Arango::Document) ? x.name : x} body = { "collection": @name, "keys": keys } result = @database.request("PUT", "_api/simple/lookup-by-keys", body: body) return result if return_directly?(result) result[:documents].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |
#documentByName(names:, returnOld: nil, silent: nil, waitForSync: nil) ⇒ Object
485 486 487 |
# File 'lib/Collection.rb', line 485 def documentByName(names:) documentByKeys(keys: names) end |
#documentMatch(match:) ⇒ Object
466 467 468 469 470 471 472 |
# File 'lib/Collection.rb', line 466 def documentMatch(match:) body = { "collection": @name, "example": match } generic_document_search("_api/simple/first-example", body, true) end |
#documents(type: "document") ⇒ Object
“path”, “id”, “key”
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/Collection.rb', line 251 def documents(type: "document") # "path", "id", "key" @returnDocument = false if type == "document" @returnDocument = true type = "key" end satisfy_category?(type, ["path", "id", "key", "document"]) body = { "type": type, "collection": @name } result = @database.request("PUT", "_api/simple/all-keys", body: body) @hasMoreSimple = result[:hasMore] @idSimple = result[:id] return result if return_directly?(result) return result[:result] unless @returnDocument if @returnDocument result[:result].map{|key| Arango::Document.new(name: key, collection: self)} end end |
#documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) ⇒ Object
455 456 457 458 459 460 461 462 463 464 |
# File 'lib/Collection.rb', line 455 def documentsMatch(match:, skip: nil, limit: nil, batchSize: nil) body = { "collection": @name, "example": match, "skip": skip, "limit": limit, "batchSize": batchSize } generic_document_search("_api/simple/by-example", body) end |
#edge(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
840 841 842 843 844 845 846 847 848 849 850 |
# File 'lib/Collection.rb', line 840 def edge(name: nil, body: {}, rev: nil, from: nil, to: nil) if @type == :document raise Arango::Error.new err: :is_a_document_collection, data: {"type": @type} end if @graph.nil? Arango::Document.new(name: name, body: body, rev: rev, collection: self) else Arango::Edge.new(name: name, body: body, rev: rev, from: from, to: to, collection: self) end end |
#export(count: nil, restrict: nil, batchSize: nil, flush: nil, flushWait: nil, limit: nil, ttl: nil) ⇒ Object
EXPORT ===
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/Collection.rb', line 719 def export(count: nil, restrict: nil, batchSize: nil, flush: nil, flushWait: nil, limit: nil, ttl: nil) query = { "collection": @name } body = { "count": count, "restrict": restrict, "batchSize": batchSize, "flush": flush, "flushWait": flushWait, "limit": limit, "ttl": ttl } result = @database.request("POST", "_api/export", body: body, query: query) return reuslt if @server.async != false @countExport = result[:count] @hasMoreExport = result[:hasMore] @idExport = result[:id] if return_directly?(result) || result[:result][0].nil? || !result[:result][0].is_a?(Hash) || !result[:result][0].key?(:_key) return result[:result] else return result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end end |
#exportNext ⇒ Object
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/Collection.rb', line 745 def exportNext unless @hasMoreExport raise Arango::Error.new err: :no_other_export_next, data: {"hasMoreExport": @hasMoreExport} else query = { "collection": @name } result = @database.request("PUT", "_api/export/#{@idExport}", query: query) return result if @server.async != false @countExport = result[:count] @hasMoreExport = result[:hasMore] @idExport = result[:id] if return_directly?(result) || result[:result][0].nil? || !result[:result][0].is_a?(Hash) || !result[:result][0].key?(:_key) return result[:result] else return result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end end end |
#fulltext(index:, attribute:, query:, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/Collection.rb', line 653 def fulltext(index:, attribute:, query:, limit: nil, skip: nil, warning: @server.warning) warning_deprecated(warning, "fulltext") body = { "index": index, "attribute": attribute, "query": query, "limit": limit, "skip": skip } result = @database.request("PUT", "_api/simple/fulltext", body: body) return result if return_directly?(result) result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |
#import(attributes:, values:, fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
IMPORT ===
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/Collection.rb', line 671 def import(attributes:, values:, fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) satisfy_category?(onDuplicate, [nil, "error", "update", "replace", "ignore"]) satisfy_category?(overwrite, [nil, "yes", "true", true]) satisfy_category?(complete, [nil, "yes", "true", true]) satisfy_category?(details, [nil, "yes", "true", true]) query = { "collection": @name, "fromPrefix": fromPrefix, "toPrefix": toPrefix, "overwrite": overwrite, "waitForSync": waitForSync, "onDuplicate": onDuplicate, "complete": complete, "details": details } body = "#{attributes}\n" values[0].is_a?(Array) ? values.each{|x| body += "#{x}\n"} : body += "#{values}\n" @database.request("POST", "_api/import", query: query, body: body, skip_to_json: true) end |
#importJSON(body:, type: "auto", fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) ⇒ Object
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/Collection.rb', line 694 def importJSON(body:, type: "auto", fromPrefix: nil, toPrefix: nil, overwrite: nil, waitForSync: nil, onDuplicate: nil, complete: nil, details: nil) satisfy_category?(type, ["auto", "list", "documents"]) satisfy_category?(onDuplicate, [nil, "error", "update", "replace", "ignore"]) satisfy_category?(overwrite, [nil, "yes", "true", true]) satisfy_category?(complete, [nil, "yes", "true", true]) satisfy_category?(details, [nil, "yes", "true", true]) query = { "collection": @name, "type": type, "fromPrefix": fromPrefix, "toPrefix": toPrefix, "overwrite": overwrite, "waitForSync": waitForSync, "onDuplicate": onDuplicate, "complete": complete, "details": details } @database.request("POST", "_api/import", query: query, body: body) end |
#index(body: {}, id: nil, type: "hash", unique: nil, fields:, sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil) ⇒ Object
INDEXES ===
767 768 769 770 771 772 |
# File 'lib/Collection.rb', line 767 def index(body: {}, id: nil, type: "hash", unique: nil, fields:, sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil) Arango::Index.new(collection: self, body: body, id: id, type: type, unique: unique, fields: fields, sparse: sparse, geoJson: geoJson, minLength: minLength, deduplicate: deduplicate) end |
#indexes ⇒ Object
774 775 776 777 778 779 780 781 782 783 |
# File 'lib/Collection.rb', line 774 def indexes query = { "collection": @name } result = @database.request("GET", "_api/index", query: query) return result if return_directly?(result) result[:indexes].map do |x| Arango::Index.new(body: x, id: x[:id], collection: self, type: x[:type], unique: x[:unique], fields: x[:fields], sparse: x[:sparse]) end end |
#load ⇒ Object
MODIFY ===
205 206 207 208 |
# File 'lib/Collection.rb', line 205 def load result = @database.request("PUT", "_api/collection/#{@name}/load") return_element(result) end |
#loadIndexesIntoMemory ⇒ Object
215 216 217 218 |
# File 'lib/Collection.rb', line 215 def loadIndexesIntoMemory @database.request("PUT", "_api/collection/#{@name}/loadIndexesIntoMemory") return true end |
#near(distance: nil, longitude:, latitude:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/Collection.rb', line 593 def near(distance: nil, longitude:, latitude:, geo: nil, limit: nil, skip: nil, warning: @server.warning) warning_deprecated(warning, "near") body = { "distance": distance, "longitude": longitude, "collection": @name, "limit": limit, "latitude": latitude, "skip": skip, "geo": geo } result = @database.request("PUT", "_api/simple/near", body: body) return result if return_directly?(result) result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |
#next ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/Collection.rb', line 269 def next if @hasMoreSimple result = @database.request("PUT", "_api/cursor/#{@idSimple}") @hasMoreSimple = result[:hasMore] @idSimple = result[:id] return result if return_directly?(result) return result[:result] unless @returnDocument if @returnDocument result[:result].map{|key| Arango::Document.new(name: key, collection: self)} end else raise Arango::Error.new err: :no_other_simple_next, data: {"hasMoreSimple": @hasMoreSimple} end end |
#properties ⇒ Object
121 122 123 |
# File 'lib/Collection.rb', line 121 def properties @database.request("GET", "_api/collection/#{@name}/properties") end |
#random ⇒ Object
489 490 491 492 |
# File 'lib/Collection.rb', line 489 def random body = { "collection": @name } generic_document_search("_api/simple/any", body, true) end |
#range(right:, attribute:, limit: nil, closed: true, skip: nil, left:, warning: @server.warning) ⇒ Object
SIMPLE DEPRECATED ===
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/Collection.rb', line 574 def range(right:, attribute:, limit: nil, closed: true, skip: nil, left:, warning: @server.warning) warning_deprecated(warning, "range") body = { "right": right, "attribute": attribute, "collection": @name, "limit": limit, "closed": closed, "skip": skip, "left": left } result = @database.request("PUT", "_api/simple/range", body: body) return result if return_directly?(result) result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |
#removeByKeys(keys:, returnOld: nil, silent: nil, waitForSync: nil) ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/Collection.rb', line 494 def removeByKeys(keys:, returnOld: nil, silent: nil, waitForSync: nil) = { "returnOld": returnOld, "silent": silent, "waitForSync": waitForSync } .delete_if{|k,v| v.nil?} = nil if .empty? if keys.is_a? Array keys = keys.map{|x| x.is_a?(String) ? x : x.key} end body = { "collection": @name, "keys": keys, "options": } result = @database.request("PUT", "_api/simple/remove-by-keys", body: body) return result if return_directly?(result) if returnOld == true && silent != true result.each do |r| Arango::Document.new(name: r[:_key], collection: self, body: r) end else return result end end |
#removeMatch(match:, limit: nil, waitForSync: nil) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/Collection.rb', line 522 def removeMatch(match:, limit: nil, waitForSync: nil) = { "limit": limit, "waitForSync": waitForSync } .delete_if{|k,v| v.nil?} = nil if .empty? body = { "collection": @name, "example" => match, "options" => } @database.request("PUT", "_api/simple/remove-by-example", body: body, key: :deleted) end |
#rename(newName:) ⇒ Object
229 230 231 232 233 |
# File 'lib/Collection.rb', line 229 def rename(newName:) body = { "name": newName } result = @database.request("PUT", "_api/collection/#{@name}/rename", body: body) return_element(result) end |
#replaceDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/Collection.rb', line 365 def replaceDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) document.each{|x| x = x.body if x.is_a?(Arango::Document)} query = { "waitForSync": waitForSync, "returnNew": returnNew, "returnOld": returnOld, "ignoreRevs": ignoreRevs } result = @database.request("PUT", "_api/document/#{@name}", body: document, query: query) return results if return_directly?(result) results.map.with_index do |result, index| body2 = result.clone if returnNew == true body2.delete(:new) body2 = body2.merge(result[:new]) end real_body = document[index] real_body = real_body.merge(body2) Arango::Document.new(name: result[:_key], collection: self, body: real_body) end end |
#replaceMatch(match:, newValue:, limit: nil, waitForSync: nil) ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/Collection.rb', line 537 def replaceMatch(match:, newValue:, limit: nil, waitForSync: nil) = { "limit": limit, "waitForSync": waitForSync } .delete_if{|k,v| v.nil?} = nil if .empty? body = { "collection": @name, "example": match, "options": , "newValue": newValue } @database.request("PUT", "_api/simple/replace-by-example", body: body, key: :replaced) end |
#retrieve ⇒ Object
GET ===
116 117 118 119 |
# File 'lib/Collection.rb', line 116 def retrieve result = @database.request("GET", "_api/collection/#{@name}") return_element(result) end |
#revision ⇒ Object
133 134 135 |
# File 'lib/Collection.rb', line 133 def revision @database.request("GET", "_api/collection/#{@name}/revision", key: :revision) end |
#revokeUserAccess(user:) ⇒ Object
817 818 819 820 |
# File 'lib/Collection.rb', line 817 def revokeUserAccess(user:) user = check_user(user) user.clear_collection_access(database: @database.name, collection: @name) end |
#rotate ⇒ Object
235 236 237 238 |
# File 'lib/Collection.rb', line 235 def rotate @database.request("PUT", "_api/collection/#{@name}/rotate") return true end |
#statistics ⇒ Object
129 130 131 |
# File 'lib/Collection.rb', line 129 def statistics @database.request("GET", "_api/collection/#{@name}/figures", key: :figures) end |
#to_h ⇒ Object
TO HASH ===
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/Collection.rb', line 101 def to_h { "name": @name, "type": @type, "status": @status, "id": @id, "isSystem": @isSystem, "body": @body, "cache_name": @cache_name, "database": @database.name }.delete_if{|k,v| v.nil?} end |
#truncate ⇒ Object
198 199 200 201 |
# File 'lib/Collection.rb', line 198 def truncate result = @database.request("PUT", "_api/collection/#{@name}/truncate") return_element(result) end |
#unload ⇒ Object
210 211 212 213 |
# File 'lib/Collection.rb', line 210 def unload result = @database.request("PUT", "_api/collection/#{@name}/unload") return_element(result) end |
#updateDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) ⇒ Object
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/Collection.rb', line 389 def updateDocuments(document: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) document.each{|x| x = x.body if x.is_a?(Arango::Document)} query = { "waitForSync": waitForSync, "returnNew": returnNew, "returnOld": returnOld, "ignoreRevs": ignoreRevs, "keepNull": keepNull, "mergeObject": mergeObjects } result = @database.request("PATCH", "_api/document/#{@name}", body: document, query: query, keepNull: keepNull) return results if return_directly?(result) results.map.with_index do |result, index| body2 = result.clone if returnNew body2.delete(:new) body2 = body2.merge(result[:new]) end real_body = document[index] real_body = real_body.merge(body2) Arango::Document.new(name: result[:_key], collection: self, body: real_body) end end |
#updateMatch(match:, newValue:, keepNull: nil, mergeObjects: nil, limit: nil, waitForSync: nil) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/Collection.rb', line 553 def updateMatch(match:, newValue:, keepNull: nil, mergeObjects: nil, limit: nil, waitForSync: nil) = { "keepNull": keepNull, "mergeObjects": mergeObjects, "limit": limit, "waitForSync": waitForSync } .delete_if{|k,v| v.nil?} = nil if .empty? body = { "collection": @name, "example": match, "options": , "newValue": newValue } @database.request("PUT", "_api/simple/update-by-example", body: body, key: :updated) end |
#userAccess(user:) ⇒ Object
822 823 824 825 |
# File 'lib/Collection.rb', line 822 def userAccess(user:) user = check_user(user) user.collection_access(database: @database.name, collection: @name) end |
#vertex(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object
GRAPH ===
829 830 831 832 833 834 835 836 837 838 |
# File 'lib/Collection.rb', line 829 def vertex(name: nil, body: {}, rev: nil, from: nil, to: nil) if @type == :edge raise Arango::Error.new err: :is_a_edge_collection, data: {"type": @type} end if @graph.nil? Arango::Document.new(name: name, body: body, rev: rev, collection: self) else Arango::Vertex.new(name: name, body: body, rev: rev, collection: self) end end |
#within(distance: nil, longitude:, latitude:, radius:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/Collection.rb', line 612 def within(distance: nil, longitude:, latitude:, radius:, geo: nil, limit: nil, skip: nil, warning: @server.warning) warning_deprecated(warning, "within") body = { "distance": distance, "longitude": longitude, "collection": @name, "limit": limit, "latitude": latitude, "skip": skip, "geo": geo, "radius": radius } result = @database.request("PUT", "_api/simple/within", body: body) return result if return_directly?(result) result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |
#withinRectangle(longitude1:, latitude1:, longitude2:, latitude2:, geo: nil, limit: nil, skip: nil, warning: @server.warning) ⇒ Object
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/Collection.rb', line 632 def withinRectangle(longitude1:, latitude1:, longitude2:, latitude2:, geo: nil, limit: nil, skip: nil, warning: @server.warning) warning_deprecated(warning, "withinRectangle") body = { "longitude1": longitude1, "latitude1": latitude1, "longitude2": longitude2, "latitude2": latitude2, "collection": @name, "limit": limit, "skip": skip, "geo": geo, "radius": radius } result = @database.request("PUT", "_api/simple/within-rectangle", body: body) return result if return_directly?(result) result[:result].map do |x| Arango::Document.new(name: x[:_key], collection: self, body: x) end end |