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,122 @@
1
+ module Arango
2
+ class Collection
3
+ module Documents
4
+ def new_document(document, wait_for_sync: nil)
5
+ Arango::Document.new(document, collection: self, wait_for_sync: wait_for_sync)
6
+ end
7
+
8
+ def create_document(document, wait_for_sync: nil)
9
+ Arango::Document.new(document, collection: self, wait_for_sync: wait_for_sync).create
10
+ end
11
+ def batch_create_document(document, wait_for_sync: nil)
12
+ Arango::Document.new(document, collection: self, wait_for_sync: wait_for_sync).batch_create
13
+ end
14
+
15
+ def create_documents(array_of_property_hashes, wait_for_sync: nil)
16
+ Arango::Document.create_documents(array_of_property_hashes, collection: self, wait_for_sync: wait_for_sync)
17
+ end
18
+ def batch_create_documents(array_of_property_hashes, wait_for_sync: nil)
19
+ Arango::Document.batch_create_documents(array_of_property_hashes, collection: self, wait_for_sync: wait_for_sync)
20
+ end
21
+
22
+ def exist_document?(*args)
23
+ Arango::Document.exist?(*args, collection: self)
24
+ end
25
+ def batch_exist_document?(*args)
26
+ Arango::Document.batch_exist?(*args, collection: self)
27
+ end
28
+ alias document_exist? exist_document?
29
+ alias batch_document_exist? batch_exist_document?
30
+
31
+ def get_document(key)
32
+ Arango::Document.get(key, collection: self)
33
+ end
34
+ def batch_get_document(key)
35
+ Arango::Document.batch_get(key, collection: self)
36
+ end
37
+ alias fetch_document get_document
38
+ alias retrieve_document get_document
39
+ alias batch_fetch_document batch_get_document
40
+ alias batch_retrieve_document batch_get_document
41
+
42
+ def get_documents(keys)
43
+ Arango::Document.get_documents(keys, collection: self)
44
+ end
45
+ def batch_get_documents(name)
46
+ Arango::Document.batch_get_documents(name: name, collection: self)
47
+ end
48
+ alias fetch_documents get_documents
49
+ alias retrieve_documents get_documents
50
+ alias batch_fetch_documents batch_get_documents
51
+ alias batch_retrieve_documents batch_get_documents
52
+
53
+ def all_documents(offset: 0, limit: nil, batch_size: nil)
54
+ return nil if type == :edge
55
+ Arango::Document.all(offset: offset, limit: limit, batch_size: batch_size, collection: self)
56
+ end
57
+ def batch_all_documents(offset: 0, limit: nil, batch_size: nil)
58
+ return nil if type == :edge
59
+ Arango::Document.batch_all(offset: offset, limit: limit, batch_size: batch_size, collection: self)
60
+ end
61
+
62
+ def list_documents(offset: 0, limit: nil, batch_size: nil)
63
+ Arango::Document.list(offset: offset, limit: limit, batch_size: batch_size, collection: self)
64
+ end
65
+ def batch_list_documents(offset: 0, limit: nil, batch_size: nil)
66
+ Arango::Document.batch_list(offset: offset, limit: limit, batch_size: batch_size, collection: self)
67
+ end
68
+
69
+ def replace_document(document)
70
+ Arango::Document.replace(document)
71
+ end
72
+ def batch_replace_document(document)
73
+ Arango::Document.batch_replace(document)
74
+ end
75
+
76
+ def replace_documents(documents_array, wait_for_sync: nil, ignore_revs: nil, return_old: nil, return_new: nil)
77
+ Arango::Document.replace_documents(documents_array)
78
+ end
79
+ def batch_replace_documents(documents_array, wait_for_sync: nil, ignore_revs: nil, return_old: nil, return_new: nil)
80
+ Arango::Document.batch_replace_documents(documents_array)
81
+ end
82
+
83
+ def save_document(document)
84
+ Arango::Document.save(document)
85
+ end
86
+ def batch_save_document(document)
87
+ Arango::Document.batch_save(document)
88
+ end
89
+ alias update_document save_document
90
+
91
+ def save_documents(documents_array, wait_for_sync: nil, ignore_revs: nil)
92
+ Arango::Document.save_documents(documents_array)
93
+ end
94
+ def batch_save_documents(documents_array, wait_for_sync: nil, ignore_revs: nil)
95
+ Arango::Document.batch_save_documents(documents_array)
96
+ end
97
+ alias update_documents save_documents
98
+
99
+ def drop_document(document)
100
+ Arango::Document.drop(document, collection: self)
101
+ end
102
+ def batch_drop_document(document)
103
+ Arango::Document.batch_drop(document, collection: self)
104
+ end
105
+ alias delete_document drop_document
106
+ alias destroy_document drop_document
107
+ alias batch_delete_document batch_drop_document
108
+ alias batch_destroy_document batch_drop_document
109
+
110
+ def drop_documents(documents_array)
111
+ Arango::Document.drop_documents(documents_array, collection: self)
112
+ end
113
+ def batch_drop_documents(documents_array)
114
+ Arango::Document.batch_drop_documents(documents_array, collection: self)
115
+ end
116
+ alias delete_documents drop_documents
117
+ alias destroy_documents drop_documents
118
+ alias batch_delete_documents batch_drop_documents
119
+ alias batch_destroy_documents batch_drop_documents
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,149 @@
1
+ module Arango
2
+ module Collection
3
+ module Edges
4
+ # === GRAPH ===
5
+ def graph=(graph)
6
+ satisfy_class?(graph, [Arango::Graph, NilClass])
7
+ if !graph.nil? && graph.database.name != @database.name
8
+ raise Arango::Error.new err: :database_graph_no_same_as_collection_database,
9
+ data: { graph_database_name: graph.database.name, collection_database_name: @database.name}
10
+ end
11
+ @graph = graph
12
+ end
13
+ alias assign_graph graph=
14
+
15
+ def vertex(name: nil, body: {}, rev: nil, from: nil, to: nil)
16
+ if @type == :edge
17
+ raise Arango::Error.new err: :is_a_edge_collection, data: {type: @type}
18
+ end
19
+ if @graph.nil?
20
+ Arango::Document.new(name: name, body: body, rev: rev, collection: self)
21
+ else
22
+ Arango::Vertex.new(name: name, body: body, rev: rev, collection: self)
23
+ end
24
+ end
25
+
26
+ def edge(name: nil, body: {}, rev: nil, from: nil, to: nil)
27
+ if @type == :document
28
+ raise Arango::Error.new err: :is_a_document_collection, data: {type: @type}
29
+ end
30
+ if @graph.nil?
31
+ Arango::Document.new(name: name, body: body, rev: rev, collection: self)
32
+ else
33
+ Arango::Edge.new(name: name, body: body, rev: rev, from: from, to: to,
34
+ collection: self)
35
+ end
36
+ end
37
+
38
+ def edge_exist?
39
+
40
+ end
41
+ alias edge_exists? edge_exist?
42
+
43
+ def edge(name: nil, body: {}, rev: nil, from: nil, to: nil)
44
+ Arango::Document.new(name: name, collection: self, body: body, rev: rev,
45
+ from: from, to: to)
46
+ end
47
+
48
+ def edges(type: "edge") # "path", "id", "key"
49
+ @return_edge = false
50
+ if type == "edge"
51
+ @return_edge = true
52
+ type = "key"
53
+ end
54
+ satisfy_category?(type, %w[path id key edge])
55
+ body = { type: type, collection: @name }
56
+ result = @database.request("PUT", "_api/simple/all-keys", body: body)
57
+
58
+ @has_more_simple = result[:hasMore]
59
+ @id_simple = result[:id]
60
+ return result if return_directly?(result)
61
+ return result[:result] unless @return_edge
62
+ if @return_edge
63
+ result[:result].map{|key| Arango::Document.new(name: key, collection: self)}
64
+ end
65
+ end
66
+
67
+ def insert_edge
68
+
69
+ end
70
+
71
+ def insert_edges
72
+
73
+ end
74
+
75
+ def replace_edge
76
+
77
+ end
78
+
79
+ def replace_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil,
80
+ return_old: nil, return_new: nil)
81
+ edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
82
+ query = {
83
+ waitForSync: wait_for_sync,
84
+ returnNew: return_new,
85
+ returnOld: return_old,
86
+ ignoreRevs: ignore_revs
87
+ }
88
+ result = @database.request("PUT", "_api/edge/#{@name}", body: edge,
89
+ query: query)
90
+ return results if return_directly?(result)
91
+ results.map.with_index do |result, index|
92
+ body2 = result.clone
93
+ if return_new == true
94
+ body2.delete(:new)
95
+ body2 = body2.merge(result[:new])
96
+ end
97
+ real_body = edge[index]
98
+ real_body = real_body.merge(body2)
99
+ Arango::Document.new(name: result[:_key], collection: self, body: real_body)
100
+ end
101
+ end
102
+
103
+ def update_edge
104
+
105
+ end
106
+
107
+ def update_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil,
108
+ return_old: nil, return_new: nil, keep_null: nil, merge_objects: nil)
109
+ edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
110
+ query = {
111
+ waitForSync: wait_for_sync,
112
+ returnNew: return_new,
113
+ returnOld: return_old,
114
+ ignoreRevs: ignore_revs,
115
+ keepNull: keep_null,
116
+ mergeObject: merge_objects
117
+ }
118
+ result = @database.request("PATCH", "_api/edge/#{@name}", body: edge,
119
+ query: query, keep_null: keep_null)
120
+ return results if return_directly?(result)
121
+ results.map.with_index do |result, index|
122
+ body2 = result.clone
123
+ if return_new
124
+ body2.delete(:new)
125
+ body2 = body2.merge(result[:new])
126
+ end
127
+ real_body = edge[index]
128
+ real_body = real_body.merge(body2)
129
+ Arango::Document.new(name: result[:_key], collection: self,
130
+ body: real_body)
131
+ end
132
+ end
133
+
134
+ def destroy_edge
135
+
136
+ end
137
+ def destroy_edges(edge: {}, wait_for_sync: nil, return_old: nil,
138
+ ignore_revs: nil)
139
+ edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
140
+ query = {
141
+ waitForSync: wait_for_sync,
142
+ returnOld: return_old,
143
+ ignoreRevs: ignore_revs
144
+ }
145
+ @database.request("DELETE", "_api/edge/#{@id}", query: query, body: edge)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,57 @@
1
+ module Arango
2
+ class Collection
3
+ module Importing
4
+ # === IMPORT ===
5
+
6
+ def import_documents
7
+
8
+ end
9
+
10
+ ## maybe not
11
+ def import(attributes:, values:, fromPrefix: nil,
12
+ toPrefix: nil, overwrite: nil, wait_for_sync: nil,
13
+ onDuplicate: nil, complete: nil, details: nil)
14
+ satisfy_category?(onDuplicate, [nil, "error", "update", "replace", "ignore"])
15
+ satisfy_category?(overwrite, [nil, "yes", "true", true])
16
+ satisfy_category?(complete, [nil, "yes", "true", true])
17
+ satisfy_category?(details, [nil, "yes", "true", true])
18
+ query = {
19
+ collection: @name,
20
+ fromPrefix: fromPrefix,
21
+ toPrefix: toPrefix,
22
+ overwrite: overwrite,
23
+ waitForSync: wait_for_sync,
24
+ onDuplicate: onDuplicate,
25
+ complete: complete,
26
+ details: details
27
+ }
28
+ body = "#{attributes}\n"
29
+ values[0].is_a?(Array) ? values.each{|x| body += "#{x}\n"} : body += "#{values}\n"
30
+ @database.request("POST", "_api/import", query: query, body: body)
31
+ end
32
+
33
+ def import_json(body:, type: "auto", fromPrefix: nil,
34
+ toPrefix: nil, overwrite: nil, wait_for_sync: nil,
35
+ onDuplicate: nil, complete: nil, details: nil)
36
+ satisfy_category?(type, %w[auto list documents])
37
+ satisfy_category?(onDuplicate, [nil, "error", "update", "replace", "ignore"])
38
+ satisfy_category?(overwrite, [nil, "yes", "true", true])
39
+ satisfy_category?(complete, [nil, "yes", "true", true])
40
+ satisfy_category?(details, [nil, "yes", "true", true])
41
+ query = {
42
+ collection: @name,
43
+ type: type,
44
+ fromPrefix: fromPrefix,
45
+ toPrefix: toPrefix,
46
+ overwrite: overwrite,
47
+ waitForSync: wait_for_sync,
48
+ onDuplicate: onDuplicate,
49
+ complete: complete,
50
+ details: details
51
+ }
52
+ @database.request("POST", "_api/import", query: query,
53
+ body: body)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ module Arango
2
+ class Collection
3
+ module Indexes
4
+ # === INDEXES ===
5
+
6
+ def ensure_hash_index
7
+
8
+ end
9
+
10
+ def ensure_skip_list_index
11
+
12
+ end
13
+
14
+ def ensure_geo_index
15
+
16
+ end
17
+
18
+ def ensure_fulltext_index
19
+
20
+ end
21
+
22
+ def ensure_persistent_index
23
+
24
+ end
25
+
26
+ def ensure_ttl_index
27
+
28
+ end
29
+
30
+ def index(body: {}, id: nil, type: "hash", unique: nil, fields:,
31
+ sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil)
32
+ Arango::Index.new(collection: self, body: body, id: id, type: type,
33
+ unique: unique, fields: fields, sparse: sparse, geo_json: geoJson,
34
+ min_length: minLength, deduplicate: deduplicate)
35
+ end
36
+
37
+ def indexes
38
+ query = { collection: @name }
39
+ result = @database.request("GET", "_api/index", query: query)
40
+ return result if return_directly?(result)
41
+ result[:indexes].map do |x|
42
+ Arango::Index.new(body: x, id: x[:id], collection: self,
43
+ type: x[:type], unique: x[:unique], fields: x[:fields],
44
+ sparse: x[:sparse])
45
+ end
46
+ end
47
+
48
+ def delete_index
49
+
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ module Arango
2
+ class Collection
3
+ module Replication
4
+ # === REPLICATION ===
5
+
6
+ def data(batchId:, from: nil, to: nil, chunkSize: nil,
7
+ includeSystem: nil, failOnUnknown: nil, ticks: nil, flush: nil)
8
+ query = {
9
+ collection: @name,
10
+ batchId: batchId,
11
+ from: from,
12
+ to: to,
13
+ chunkSize: chunkSize,
14
+ includeSystem: includeSystem,
15
+ failOnUnknown: failOnUnknown,
16
+ ticks: ticks,
17
+ flush: flush
18
+ }
19
+ @database.request("GET", "_api/replication/dump", query: query)
20
+ end
21
+ alias dump data
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Arango
2
+ class Collection
3
+ module User
4
+ # === USER ACCESS ===
5
+
6
+ def check_user(user)
7
+ user = Arango::User.new(user: user) if user.is_a?(String)
8
+ return user
9
+ end
10
+ private :check_user
11
+
12
+ def add_user_access(grant:, user:)
13
+ user = check_user(user)
14
+ user.add_collection_access(grant: grant, database: @database.name, collection: @name)
15
+ end
16
+
17
+ def revoke_user_access(user:)
18
+ user = check_user(user)
19
+ user.clear_collection_access(database: @database.name, collection: @name)
20
+ end
21
+
22
+ def user_access(user:)
23
+ user = check_user(user)
24
+ user.collection_access(database: @database.name, collection: @name)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,67 @@
1
+ module Arango
2
+ class Cursor
3
+ def has_next?
4
+
5
+ end
6
+
7
+ def next
8
+
9
+ end
10
+
11
+ def first
12
+
13
+ end
14
+
15
+ def each
16
+
17
+ end
18
+
19
+ def map
20
+
21
+ end
22
+
23
+ def filter
24
+
25
+ end
26
+
27
+ def any_match?
28
+
29
+ end
30
+
31
+ def all_match?
32
+
33
+ end
34
+
35
+ def none_match?
36
+
37
+ end
38
+
39
+ def inject
40
+
41
+ end
42
+
43
+ def remaining_as_list
44
+
45
+ end
46
+
47
+ def all_count
48
+ # get_count
49
+ end
50
+
51
+ def count
52
+
53
+ end
54
+
55
+ def stats
56
+
57
+ end
58
+
59
+ def warnings
60
+
61
+ end
62
+
63
+ def is_cached?
64
+
65
+ end
66
+ end
67
+ end