arango-driver 3.5.0.alpha0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +1073 -0
  4. data/arango_opal.js +15 -0
  5. data/lib/arango-driver.rb +61 -0
  6. data/lib/arango.rb +96 -0
  7. data/lib/arango/aql.rb +188 -0
  8. data/lib/arango/collection.rb +575 -0
  9. data/lib/arango/collection/documents.rb +122 -0
  10. data/lib/arango/collection/edges.rb +149 -0
  11. data/lib/arango/collection/importing.rb +57 -0
  12. data/lib/arango/collection/indexes.rb +53 -0
  13. data/lib/arango/collection/replication.rb +24 -0
  14. data/lib/arango/collection/user.rb +28 -0
  15. data/lib/arango/cursor.rb +67 -0
  16. data/lib/arango/database.rb +188 -0
  17. data/lib/arango/database/analyzer.rb +21 -0
  18. data/lib/arango/database/aql_functions.rb +54 -0
  19. data/lib/arango/database/aql_queries.rb +114 -0
  20. data/lib/arango/database/aql_query_cache.rb +27 -0
  21. data/lib/arango/database/collections.rb +100 -0
  22. data/lib/arango/database/foxx_services.rb +103 -0
  23. data/lib/arango/database/graph_access.rb +27 -0
  24. data/lib/arango/database/http_route.rb +9 -0
  25. data/lib/arango/database/replication.rb +96 -0
  26. data/lib/arango/database/stream_transactions.rb +25 -0
  27. data/lib/arango/database/tasks.rb +67 -0
  28. data/lib/arango/database/transactions.rb +15 -0
  29. data/lib/arango/database/user.rb +26 -0
  30. data/lib/arango/database/view_access.rb +37 -0
  31. data/lib/arango/document.rb +443 -0
  32. data/lib/arango/edge.rb +164 -0
  33. data/lib/arango/error.rb +97 -0
  34. data/lib/arango/error_db.rb +27 -0
  35. data/lib/arango/foxx.rb +255 -0
  36. data/lib/arango/graph.rb +202 -0
  37. data/lib/arango/graph/basics.rb +39 -0
  38. data/lib/arango/graph/edge_access.rb +56 -0
  39. data/lib/arango/graph/vertex_access.rb +33 -0
  40. data/lib/arango/helper/collection_assignment.rb +13 -0
  41. data/lib/arango/helper/database_assignment.rb +14 -0
  42. data/lib/arango/helper/request_method.rb +45 -0
  43. data/lib/arango/helper/return.rb +21 -0
  44. data/lib/arango/helper/satisfaction.rb +28 -0
  45. data/lib/arango/helper/server_assignment.rb +13 -0
  46. data/lib/arango/helper/traversal.rb +12 -0
  47. data/lib/arango/index.rb +103 -0
  48. data/lib/arango/replication.rb +231 -0
  49. data/lib/arango/request.rb +92 -0
  50. data/lib/arango/request_batch.rb +174 -0
  51. data/lib/arango/result.rb +130 -0
  52. data/lib/arango/search_view.rb +23 -0
  53. data/lib/arango/server.rb +68 -0
  54. data/lib/arango/server/administration.rb +296 -0
  55. data/lib/arango/server/agency.rb +23 -0
  56. data/lib/arango/server/async.rb +51 -0
  57. data/lib/arango/server/batch.rb +35 -0
  58. data/lib/arango/server/config.rb +76 -0
  59. data/lib/arango/server/databases.rb +71 -0
  60. data/lib/arango/server/monitoring.rb +17 -0
  61. data/lib/arango/server/opal_support.rb +95 -0
  62. data/lib/arango/server/tasks.rb +69 -0
  63. data/lib/arango/server/user.rb +22 -0
  64. data/lib/arango/task.rb +223 -0
  65. data/lib/arango/transaction.rb +113 -0
  66. data/lib/arango/traversal.rb +212 -0
  67. data/lib/arango/user.rb +174 -0
  68. data/lib/arango/version.rb +3 -0
  69. data/lib/arango/vertex.rb +112 -0
  70. data/lib/arango/view.rb +124 -0
  71. data/lib/arango/view/basics.rb +25 -0
  72. metadata +296 -0
@@ -0,0 +1,188 @@
1
+ # === DATABASE ===
2
+
3
+ module Arango
4
+ class Database
5
+ include Arango::Helper::Satisfaction
6
+ include Arango::Helper::Return
7
+
8
+ include Arango::Database::AQLFunctions
9
+ include Arango::Database::Collections
10
+ include Arango::Database::FoxxServices
11
+ include Arango::Database::GraphAccess
12
+ include Arango::Database::HTTPRoute
13
+ include Arango::Database::AQLQueries
14
+ include Arango::Database::AQLQueryCache
15
+ include Arango::Database::Replication
16
+ include Arango::Database::StreamTransactions
17
+ include Arango::Database::Tasks
18
+ include Arango::Database::Transactions
19
+ include Arango::Database::ViewAccess
20
+
21
+ class << self
22
+ # Retrieves all databases.
23
+ # @param server [Arango::Server]
24
+ # @return [Array<Arango::Database>]
25
+ def all(server:)
26
+ result = server.request(get: '_api/database').result
27
+ result.map{ |db| Arango::Database.new(db, server: server).reload }
28
+ end
29
+
30
+ # Retrieves all databases the current user can access.
31
+ # @param server [Arango::Server]
32
+ # @return [Array<Arango::Database>]
33
+ def all_user_databases(server:)
34
+ result = server.request(get: '_api/database/user').result
35
+ result.map{ |db| Arango::Database.new(db, server: server).reload }
36
+ end
37
+
38
+ # Get database from server.
39
+ # @param name [String] The name of the database
40
+ # @param server [Arango::Server]
41
+ # @return [Arango::Database] The instance of the database.
42
+ def get(name, server:)
43
+ Arango::Database.new(name, server: server).reload
44
+ end
45
+ alias fetch get
46
+ alias retrieve get
47
+
48
+ # Retrieves a list of all databases.
49
+ # @param server [Arango::Server]
50
+ # @return [Array<String>] List of database names.
51
+ def list(server:)
52
+ server.request(get: '_api/database').result
53
+ end
54
+
55
+ # Retrieves a list of all databases the current user can access.
56
+ # @param server [Arango::Server]
57
+ # @return [Array<String>] List of database names.
58
+ def list_user_databases(server:)
59
+ server.request(get: '_api/database/user').result
60
+ end
61
+
62
+ # Removes a database.
63
+ # @param name [String] The name of the database
64
+ # @param server [Arango::Server]
65
+ # @return nil
66
+ def drop(name, server:)
67
+ server.request(delete: "_api/database/#{name}")
68
+ nil
69
+ end
70
+ alias delete drop
71
+ alias destroy drop
72
+
73
+ # Check if database exists.
74
+ # @param name [String] Name of the database.
75
+ # @param server [Arango::Server]
76
+ # @return [Boolean]
77
+ def exist?(name, server:)
78
+ list(server: server).include?(name)
79
+ end
80
+ end
81
+
82
+ # Instantiate a new database. All params except name and server are optional.
83
+ # @param name [String]
84
+ # @param server [Arango::Server]
85
+ # @param id
86
+ # @param is_system
87
+ # @param path
88
+ # @return [Arango::Database]
89
+ def initialize(name, id: nil, is_system: false, path: '', server: Arango.current_server)
90
+ send(:arango_server=, server)
91
+ @name = name
92
+ @is_system = is_system
93
+ @path = path
94
+ @id = id
95
+ end
96
+
97
+ # Whether or not the current database is the _system database
98
+ # @return [Boolean]
99
+ attr_reader :is_system
100
+
101
+ # The name of the database
102
+ # @return [String]
103
+ attr_reader :name
104
+
105
+ # The filesystem path of the current database
106
+ # @return [String]
107
+ attr_reader :path
108
+
109
+ attr_accessor :arango_server
110
+
111
+ # Creates the database on the server.
112
+ # @return [Arango::Database] self
113
+ def create
114
+ # TODO users: users
115
+ body = { name: @name }
116
+ @arango_server.request(post: '_api/database', body: body)
117
+ self
118
+ end
119
+
120
+ # Reload database properties.
121
+ # @return [Arango::Database] self
122
+ def reload
123
+ result = request(get: '_api/database/current')
124
+ _update_attributes(result.result)
125
+ self
126
+ end
127
+ alias refresh reload
128
+ alias retrieve reload
129
+
130
+ # Remove database from the server.
131
+ # @return nil
132
+ def drop
133
+ self.class.drop(@name, server: @arango_server)
134
+ nil
135
+ end
136
+ alias delete drop
137
+ alias destroy drop
138
+
139
+ # Returns the database version that this server requires.
140
+ # @return [String]
141
+ def target_version
142
+ request(get: '_admin/database/target-version').version
143
+ end
144
+
145
+ def request(get: nil, head: nil, patch: nil, post: nil, put: nil, delete: nil, body: nil, headers: nil, query: nil, block: nil)
146
+ @arango_server.request(get: get, head: head, patch: patch, post: post, put: put, delete: delete,
147
+ db: @name, body: body, headers: headers, query: query, block: block)
148
+ end
149
+
150
+ def execute_request(get: nil, head: nil, patch: nil, post: nil, put: nil, delete: nil, body: nil, headers: nil, query: nil, block: nil)
151
+ @arango_server.request(get: get, head: head, patch: patch, post: post, put: put, delete: delete,
152
+ db: @name, body: body, headers: headers, query: query, block: block)
153
+ end
154
+
155
+ def execute_requests(requests)
156
+ batch = Arango::RequestBatch.new(database: self)
157
+ requests.each { |request_h| batch.add_request(**request_h) }
158
+ batch.execute
159
+ end
160
+
161
+ def batch_request(request_hash)
162
+ promise = Promise.new
163
+ request_hash[:promise] = promise
164
+ batch = _promise_batch
165
+ batch.add_request(**request_hash)
166
+ promise
167
+ end
168
+
169
+ def execute_batched_requests
170
+ batch = @_promise_batch
171
+ @_promise_batch = nil
172
+ batch.execute
173
+ nil
174
+ end
175
+
176
+ private
177
+
178
+ def _promise_batch
179
+ @_promise_batch ||= Arango::RequestBatch.new(database: self)
180
+ end
181
+
182
+ def _update_attributes(result)
183
+ %i[id isSystem name path].each do |key|
184
+ instance_variable_set("@#{key.to_s.underscore}", result[key]) if result.key?(key)
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,21 @@
1
+ module Arango
2
+ class Database
3
+ module Analyzer
4
+ def create_analyzer
5
+
6
+ end
7
+
8
+ def analyzer
9
+
10
+ end
11
+
12
+ def analyzers
13
+
14
+ end
15
+
16
+ def delete_analyzer
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,54 @@
1
+ module Arango
2
+ class Database
3
+ module AQLFunctions
4
+
5
+ def list_aql_functions(namespace: nil)
6
+ query = nil
7
+ query = { namespace: namespace } unless namespace.nil?
8
+ result = execute_request(get: "_api/aqlfunction", query: query)
9
+ result.result.map { |r| Arango::Result.new(r) }
10
+ end
11
+
12
+ def create_aql_function(name, code: nil, is_deterministic: nil, &block)
13
+ if block_given?
14
+ source_block = Parser::CurrentRuby.parse(block.source).children.last
15
+ source_block = source_block.children.last if source_block.type == :block
16
+ source_code = Unparser.unparse(source_block)
17
+ ruby_header = <<~RUBY
18
+ args = `original_arguments`
19
+ RUBY
20
+ compiled_ruby= Opal.compile(ruby_header + source_code, parse_comments: false)
21
+ if compiled_ruby.start_with?('/*')
22
+ start_of_code = compiled_ruby.index('*/') + 3
23
+ compiled_ruby = compiled_ruby[start_of_code..-1]
24
+ end
25
+ code = <<~JAVASCRIPT
26
+ function() {
27
+ "use strict";
28
+ require('opal');
29
+ var original_arguments = Array.prototype.slice.call(arguments);
30
+ for (var i=0; i<original_arguments.length; i++) {
31
+ if (typeof original_arguments[i] === "object" && !(original_arguments[i] instanceof Array)) {
32
+ original_arguments[i] = Opal.Hash.$new(original_arguments[i]);
33
+ }
34
+ }
35
+ var result = #{compiled_ruby}
36
+ if (typeof result['$to_n'] === "function") { result = result['$to_n'](); }
37
+ return result;
38
+ }
39
+ JAVASCRIPT
40
+ end
41
+ body = { code: code, name: name, isDeterministic: is_deterministic }
42
+ result = execute_request(post: "_api/aqlfunction", body: body)
43
+ result.response_code == 200 || result.response_code == 201
44
+ end
45
+
46
+ def drop_aql_function(name, group: nil)
47
+ query = nil
48
+ query = { group: group } unless group.nil?
49
+ result = request(delete: "_api/aqlfunction/#{name}", query: query)
50
+ result.response_code == 200
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,114 @@
1
+ module Arango
2
+ class Database
3
+ module AQLQueries
4
+ def new_aql(query:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
5
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
6
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
7
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
8
+ Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
9
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
10
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
11
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
12
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
13
+ block: block, &ruby_block)
14
+ end
15
+
16
+ def new_query(query, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
17
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
18
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
19
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
20
+ Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
21
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
22
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
23
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
24
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
25
+ block: block, &ruby_block)
26
+ end
27
+
28
+ def execute_aql(query:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
29
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
30
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
31
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
32
+ aql = Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
33
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
34
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
35
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
36
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
37
+ block: block, &ruby_block)
38
+ aql.execute
39
+ end
40
+
41
+ def execute_query(query, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
42
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
43
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
44
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
45
+ aql = Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
46
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
47
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
48
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
49
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
50
+ block: block, &ruby_block)
51
+ aql.execute
52
+ end
53
+
54
+ def batch_execute_aql(query:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
55
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
56
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
57
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
58
+ aql = Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
59
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
60
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
61
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
62
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
63
+ block: block, &ruby_block)
64
+ aql.batch_execute
65
+ end
66
+
67
+ def batch_execute_query(query, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil,
68
+ intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil,
69
+ max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil,
70
+ skip_inaccessible_collections: nil, ttl: nil, block: nil, &ruby_block)
71
+ aql = Arango::AQL.new(database: self, query: query, batch_size: batch_size, bind_vars: bind_vars, cache: cache, count: count,
72
+ fail_on_warning: fail_on_warning, full_count: full_count, intermediate_commit_count: intermediate_commit_count,
73
+ intermediate_commit_size: intermediate_commit_size, max_plans: max_plans, max_transaction_size: max_transaction_size,
74
+ max_warning_count: max_warning_count, memory_limit: memory_limit, optimizer_rules: optimizer_rules, profile: profile,
75
+ satellite_sync_wait: satellite_sync_wait, skip_inaccessible_collections: skip_inaccessible_collections, ttl: ttl,
76
+ block: block, &ruby_block)
77
+ aql.batch_execute
78
+ end
79
+
80
+ def query_tracking_properties
81
+ execute_request(get: "_api/query/properties")
82
+ end
83
+
84
+ def set_query_tracking_properties(props)
85
+ body = props.to_h
86
+ body.transform_keys! { |k| k.to_s.camelize(:lower).to_sym }
87
+ execute_request(put: "_api/query/properties", body: props.to_h)
88
+ end
89
+
90
+ def running_queries
91
+ result = execute_request(get: "_api/query/current")
92
+ result.map { |query_hash| Arango::AQL.from_result(query_hash) }
93
+ end
94
+
95
+ def slow_queries
96
+ result = execute_request(get: "_api/query/slow")
97
+ result.map { |query_hash| Arango::AQL.from_result(query_hash) }
98
+ end
99
+
100
+ def clear_slow_queries_list
101
+ result = execute_request(delete: "_api/query/slow")
102
+ result.response_code == 200
103
+ end
104
+
105
+ def kill_query(aql_id)
106
+ id = if id.class == String then id
107
+ elsif id.class == Arango::AQL then id.id
108
+ end
109
+ result = execute_request(delete: "_api/query/#{id}")
110
+ result == 200
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,27 @@
1
+ module Arango
2
+ class Database
3
+ module AQLQueryCache
4
+
5
+ def clear_query_cache
6
+ result = execute_request(delete: "_api/query-cache")
7
+ result.response_code == 200
8
+ end
9
+
10
+ def get_query_cache
11
+ result = execute_request(get: "_api/query-cache/entries")
12
+ result.map { |entry| Arango::Result.new(entry) }
13
+ end
14
+
15
+ def query_cache_properties
16
+ execute_request(get: "_api/query-cache/properties")
17
+ end
18
+
19
+ def set_query_cache_properties(props)
20
+ body = props.to_h
21
+ body.transform_keys! { |k| k.to_s.camelize(:lower).to_sym }
22
+ result = execute_request(put: "_api/query-cache/properties", body: body)
23
+ result.response_code == 200
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,100 @@
1
+ module Arango
2
+ class Database
3
+ module Collections
4
+ # Retrieves all collections from the database.
5
+ # @param exclude_system [Boolean] Optional, default true, exclude system collections.
6
+ # @return [Array<Arango::Collection>]
7
+ def all_collections(exclude_system: true)
8
+ Arango::Collection.all(exclude_system: exclude_system, database: self)
9
+ end
10
+ def batch_all_collections(exclude_system: true)
11
+ Arango::Collection.batch_all(exclude_system: exclude_system, database: self)
12
+ end
13
+
14
+ # Creates a new collection.
15
+ # @param name [String] The name of the collection.
16
+ # @param type [Symbol] One of :document or :edge, the collection type, optional, default: :document.
17
+ # @return [Arango::Collection] The instance of the collection created.
18
+ def create_collection(name, type: :document, is_system: false)
19
+ Arango::Collection.new(name, type: type, database: self, is_system: is_system).create
20
+ end
21
+ def batch_create_collection(name, type: :document, is_system: false)
22
+ Arango::Collection.new(name, type: type, database: self, is_system: is_system).batch_create
23
+ end
24
+
25
+ # Creates a new edge collection.
26
+ # @param name [String] The name of the collection.
27
+ # @return [Arango::Collection] The instance of the collection created.
28
+ def create_edge_collection(name)
29
+ Arango::Collection.new(name, type: :edge, database: self).create
30
+ end
31
+ def batch_create_edge_collection(name)
32
+ Arango::Collection.new(name, type: :edge, database: self).batch_create
33
+ end
34
+
35
+ # Get collection from the database.
36
+ # @param name [String] The name of the collection.
37
+ # @return [Arango::Database]
38
+ def get_collection(name)
39
+ Arango::Collection.get(name, database: self)
40
+ end
41
+ def batch_get_collection(name)
42
+ Arango::Collection.batch_get(name, database: self)
43
+ end
44
+ alias fetch_collection get_collection
45
+ alias retrieve_collection get_collection
46
+ alias batch_fetch_collection batch_get_collection
47
+ alias batch_retrieve_collection batch_get_collection
48
+
49
+ # Instantiates a new collection.
50
+ # @param name [String] The name of the collection.
51
+ # @param type [Symbol] One of :document or :edge, the collection type, optional, default: :document.
52
+ # @return [Arango::Collection]
53
+ def new_collection(name, type: :document)
54
+ Arango::Collection.new(name, type: type, database: self)
55
+ end
56
+
57
+ # Instantiates a new edge collection.
58
+ # @param name [String] The name of the collection.
59
+ # @return [Arango::Collection]
60
+ def new_edge_collection(name)
61
+ Arango::Collection.new(name, type: :edge, database: self)
62
+ end
63
+
64
+ # Retrieves a list of all collections.
65
+ # @param exclude_system [Boolean] Optional, default true, exclude system collections.
66
+ # @return [Array<String>] List of collection names.
67
+ def list_collections(exclude_system: true)
68
+ Arango::Collection.list(exclude_system: exclude_system, database: self)
69
+ end
70
+ def batch_list_collections(exclude_system: true)
71
+ Arango::Collection.batch_list(exclude_system: exclude_system, database: self)
72
+ end
73
+
74
+ # Removes a collection.
75
+ # @param name [String] The name of the collection.
76
+ # @return nil
77
+ def drop_collection(name)
78
+ Arango::Collection.drop(name, database: self)
79
+ end
80
+ def batch_drop_collection(name)
81
+ Arango::Collection.batch_drop(name, database: self)
82
+ end
83
+ alias delete_collection drop_collection
84
+ alias destroy_collection drop_collection
85
+ alias batch_delete_collection batch_drop_collection
86
+ alias batch_destroy_collection batch_drop_collection
87
+
88
+ # Check if collection exists.
89
+ # @param name [String] Name of the collection
90
+ # @return [Boolean]
91
+ def exist_collection?(name, exclude_system: true)
92
+ Arango::Collection.exist?(name, database: self, exclude_system: exclude_system)
93
+ end
94
+ def batch_exist_collection?(name, exclude_system: true)
95
+ Arango::Collection.batch_exist?(name, database: self, exclude_system: exclude_system)
96
+ end
97
+ alias collection_exist? exist_collection?
98
+ end
99
+ end
100
+ end