arangorb 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +20 -18
- data/Gemfile +3 -0
- data/README.md +1079 -908
- data/lib/AQL.rb +155 -0
- data/lib/Batch.rb +97 -0
- data/lib/Cache.rb +71 -0
- data/lib/Collection.rb +852 -0
- data/lib/Database.rb +417 -0
- data/lib/Document.rb +346 -0
- data/lib/Edge.rb +104 -0
- data/lib/Error.rb +125 -0
- data/lib/Foxx.rb +277 -0
- data/lib/Graph.rb +325 -0
- data/lib/Index.rb +126 -0
- data/lib/Replication.rb +235 -0
- data/lib/Request.rb +143 -0
- data/lib/Server.rb +466 -0
- data/lib/Task.rb +120 -0
- data/lib/Transaction.rb +115 -0
- data/lib/Traversal.rb +224 -0
- data/lib/User.rb +197 -0
- data/lib/Vertex.rb +127 -0
- data/lib/View.rb +151 -0
- data/lib/arangorb.rb +23 -15
- data/lib/helpers/Error.rb +28 -0
- data/lib/helpers/Return.rb +53 -0
- metadata +64 -45
- data/lib/ArangoRB_AQL.rb +0 -181
- data/lib/ArangoRB_Cache.rb +0 -174
- data/lib/ArangoRB_Col.rb +0 -526
- data/lib/ArangoRB_DB.rb +0 -363
- data/lib/ArangoRB_Doc.rb +0 -319
- data/lib/ArangoRB_Edg.rb +0 -184
- data/lib/ArangoRB_Gra.rb +0 -201
- data/lib/ArangoRB_Index.rb +0 -135
- data/lib/ArangoRB_Replication.rb +0 -261
- data/lib/ArangoRB_Ser.rb +0 -446
- data/lib/ArangoRB_Task.rb +0 -129
- data/lib/ArangoRB_Tra.rb +0 -169
- data/lib/ArangoRB_Tran.rb +0 -68
- data/lib/ArangoRB_User.rb +0 -157
- data/lib/ArangoRB_Ver.rb +0 -162
- data/spec/arangoRB_helper.rb +0 -4
- data/spec/arangoRestart_helper.rb +0 -14
- data/spec/arangorb-1.3.0.gem +0 -0
- data/spec/lib/0.1.0/arangoAQL_helper.rb +0 -64
- data/spec/lib/0.1.0/arangoC_helper.rb +0 -170
- data/spec/lib/0.1.0/arangoDB_helper.rb +0 -119
- data/spec/lib/0.1.0/arangoDoc_helper.rb +0 -79
- data/spec/lib/0.1.0/arangoE_helper.rb +0 -50
- data/spec/lib/0.1.0/arangoG_helper.rb +0 -78
- data/spec/lib/0.1.0/arangoS_helper.rb +0 -37
- data/spec/lib/0.1.0/arangoT_helper.rb +0 -48
- data/spec/lib/0.1.0/arangoV_helper.rb +0 -65
- data/spec/lib/1.0.0/arangoC_helper.rb +0 -73
- data/spec/lib/1.0.0/arangoDB_helper.rb +0 -48
- data/spec/lib/1.0.0/arangoI_helper.rb +0 -43
- data/spec/lib/1.0.0/arangoS_helper.rb +0 -192
- data/spec/lib/1.0.0/arangoTa_helper.rb +0 -49
- data/spec/lib/1.0.0/arangoTr_helper.rb +0 -15
- data/spec/lib/1.0.0/arangoU_helper.rb +0 -72
- data/spec/lib/1.1.0/arangoRB_helper.rb +0 -144
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +0 -19
- data/spec/lib/1.2.0/arangoCache_helper.rb +0 -66
- data/spec/lib/1.3.0/arangoHash_helper.rb +0 -30
- data/spec/lib/arangoRB_0.1.0_helper.rb +0 -9
- data/spec/lib/arangoRB_1.0.0_helper.rb +0 -6
- data/spec/lib/arangoRB_1.1.0_helper.rb +0 -2
- data/spec/lib/arangoRB_1.2.0_helper.rb +0 -2
- data/spec/spec_helper.rb +0 -42
data/lib/ArangoRB_Edg.rb
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
# === GRAPH EDGE ===
|
2
|
-
|
3
|
-
class ArangoEdge < ArangoDocument
|
4
|
-
def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}, from: nil, to: nil) # TESTED
|
5
|
-
if collection.is_a?(String)
|
6
|
-
@collection = collection
|
7
|
-
elsif collection.is_a?(ArangoCollection)
|
8
|
-
@collection = collection.collection
|
9
|
-
else
|
10
|
-
raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
|
11
|
-
end
|
12
|
-
|
13
|
-
if graph.is_a?(String)
|
14
|
-
@graph = graph
|
15
|
-
elsif graph.is_a?(ArangoGraph)
|
16
|
-
@graph = graph.graph
|
17
|
-
else
|
18
|
-
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
19
|
-
end
|
20
|
-
|
21
|
-
if database.is_a?(String)
|
22
|
-
@database = database
|
23
|
-
elsif database.is_a?(ArangoDatabase)
|
24
|
-
@database = database.database
|
25
|
-
else
|
26
|
-
raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
|
27
|
-
end
|
28
|
-
|
29
|
-
if key.is_a?(String) || key.nil?
|
30
|
-
@key = key
|
31
|
-
unless key.nil?
|
32
|
-
body["_key"] = @key
|
33
|
-
@id = "#{@collection}/#{@key}"
|
34
|
-
end
|
35
|
-
elsif key.is_a?(ArangoDocument)
|
36
|
-
@key = key.key
|
37
|
-
@id = key.id
|
38
|
-
else
|
39
|
-
raise "key should be a String, not a #{key.class}"
|
40
|
-
end
|
41
|
-
|
42
|
-
if body.is_a?(Hash)
|
43
|
-
@body = body
|
44
|
-
else
|
45
|
-
raise "body should be a Hash, not a #{body.class}"
|
46
|
-
end
|
47
|
-
|
48
|
-
if from.is_a?(String)
|
49
|
-
@body["_from"] = from
|
50
|
-
elsif from.is_a?(ArangoDocument)
|
51
|
-
@body["_from"] = from.id
|
52
|
-
elsif from.nil?
|
53
|
-
else
|
54
|
-
raise "from should be a String or an ArangoDocument instance, not a #{from.class}"
|
55
|
-
end
|
56
|
-
|
57
|
-
if to.is_a?(String)
|
58
|
-
@body["_to"] = to
|
59
|
-
elsif to.is_a?(ArangoDocument)
|
60
|
-
@body["_to"] = to.id
|
61
|
-
elsif to.nil?
|
62
|
-
else
|
63
|
-
raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
|
64
|
-
end
|
65
|
-
|
66
|
-
@idCache = "EDG_#{@id}"
|
67
|
-
end
|
68
|
-
|
69
|
-
attr_reader :key, :id, :body, :idCache
|
70
|
-
|
71
|
-
# === RETRIEVE ===
|
72
|
-
|
73
|
-
def to_hash
|
74
|
-
{
|
75
|
-
"key" => @key,
|
76
|
-
"id" => @id,
|
77
|
-
"collection" => @collection,
|
78
|
-
"database" => @database,
|
79
|
-
"body" => @body,
|
80
|
-
"idCache" => @idCache
|
81
|
-
}.delete_if{|k,v| v.nil?}
|
82
|
-
end
|
83
|
-
alias to_h to_hash
|
84
|
-
|
85
|
-
def graph
|
86
|
-
ArangoGraph.new(graph: @graph, database: @database)
|
87
|
-
end
|
88
|
-
|
89
|
-
# === GET ===
|
90
|
-
|
91
|
-
def retrieve # TESTED
|
92
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", @@request)
|
93
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
94
|
-
return true if @@async
|
95
|
-
result = result.parsed_response
|
96
|
-
if @@verbose
|
97
|
-
@body = result["edge"] unless result["error"]
|
98
|
-
result
|
99
|
-
else
|
100
|
-
return result["errorMessage"] if result["error"]
|
101
|
-
@body = result["edge"]
|
102
|
-
self
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# === POST ====
|
107
|
-
|
108
|
-
def create(body: {}, from: @body["_from"], to: @body["_to"], waitForSync: nil) # TESTED
|
109
|
-
query = {"waitForSync" => waitForSync}.delete_if{|k,v| v.nil?}
|
110
|
-
body["_key"] = @key if body["_key"].nil? && !@key.nil?
|
111
|
-
body["_from"] = from.is_a?(String) ? from : from.id
|
112
|
-
body["_to"] = to.is_a?(String) ? to : to.id
|
113
|
-
request = @@request.merge({ :body => body.to_json, :query => query })
|
114
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@collection}", request)
|
115
|
-
return_result result: result, body: body
|
116
|
-
end
|
117
|
-
alias create_document create
|
118
|
-
alias create_vertex create
|
119
|
-
|
120
|
-
# === MODIFY ===
|
121
|
-
|
122
|
-
def replace(body: {}, waitForSync: nil) # TESTED
|
123
|
-
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
124
|
-
request = @@request.merge({ :body => body.to_json, :query => query })
|
125
|
-
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
|
126
|
-
return_result result: result, body: body
|
127
|
-
end
|
128
|
-
|
129
|
-
def update(body: {}, waitForSync: nil, keepNull: nil) # TESTED
|
130
|
-
query = {"waitForSync" => waitForSync, "keepNull" => keepNull}.delete_if{|k,v| v.nil?}
|
131
|
-
request = @@request.merge({ :body => body.to_json, :query => query })
|
132
|
-
result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
|
133
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
134
|
-
return true if @@async
|
135
|
-
result = result.parsed_response
|
136
|
-
if @@verbose
|
137
|
-
unless result["error"]
|
138
|
-
@key = result["_key"]
|
139
|
-
@id = "#{@collection}/#{@key}"
|
140
|
-
@body = body
|
141
|
-
end
|
142
|
-
result
|
143
|
-
else
|
144
|
-
return result["errorMessage"] if result["error"]
|
145
|
-
@key = result["edge"]["_key"]
|
146
|
-
@id = "#{@collection}/#{@key}"
|
147
|
-
@body = @body.merge(body)
|
148
|
-
@body = @body.merge(result["edge"])
|
149
|
-
self
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# === DELETE ===
|
154
|
-
|
155
|
-
def destroy(body: nil, waitForSync: nil) # TESTED
|
156
|
-
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
157
|
-
request = @@request.merge({ :query => query })
|
158
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
|
159
|
-
return_result result: result, caseTrue: true
|
160
|
-
end
|
161
|
-
|
162
|
-
# === UTILITY ===
|
163
|
-
|
164
|
-
def return_result(result:, body: {}, caseTrue: false)
|
165
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
166
|
-
return true if @@async
|
167
|
-
result = result.parsed_response
|
168
|
-
if @@verbose
|
169
|
-
unless result["error"]
|
170
|
-
@key = result["edge"]["_key"]
|
171
|
-
@id = "#{@collection}/#{@key}"
|
172
|
-
@body = body
|
173
|
-
end
|
174
|
-
result
|
175
|
-
else
|
176
|
-
return result["errorMessage"] if result["error"]
|
177
|
-
return true if caseTrue
|
178
|
-
@key = result["edge"]["_key"]
|
179
|
-
@id = "#{@collection}/#{@key}"
|
180
|
-
@body = body
|
181
|
-
self
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
data/lib/ArangoRB_Gra.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
# ==== GRAPH ====
|
2
|
-
|
3
|
-
class ArangoGraph < ArangoServer
|
4
|
-
def initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: []) # TESTED
|
5
|
-
if database.is_a?(String)
|
6
|
-
@database = database
|
7
|
-
elsif database.is_a?(ArangoDatabase)
|
8
|
-
@database = database.database
|
9
|
-
else
|
10
|
-
raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
|
11
|
-
end
|
12
|
-
|
13
|
-
if graph.is_a?(String)
|
14
|
-
@graph = graph
|
15
|
-
elsif database.is_a?(ArangoGraph)
|
16
|
-
@graph = graph.graph
|
17
|
-
else
|
18
|
-
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
19
|
-
end
|
20
|
-
|
21
|
-
if edgeDefinitions.is_a?(Array)
|
22
|
-
@edgeDefinitions = edgeDefinitions
|
23
|
-
else
|
24
|
-
raise "edgeDefinitions should be an Array, not a #{edgeDefinitions.class}"
|
25
|
-
end
|
26
|
-
|
27
|
-
if orphanCollections.is_a?(Array)
|
28
|
-
@orphanCollections = orphanCollections
|
29
|
-
else
|
30
|
-
raise "orphanCollections should be an Array, not a #{orphanCollections.class}"
|
31
|
-
end
|
32
|
-
|
33
|
-
@idCache = "GRA_#{@graph}"
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_reader :graph, :edgeDefinitions, :orphanCollections, :database, :idCache
|
37
|
-
alias name graph
|
38
|
-
|
39
|
-
# === RETRIEVE ===
|
40
|
-
|
41
|
-
def to_hash
|
42
|
-
{
|
43
|
-
"graph" => @graph,
|
44
|
-
"collection" => @collection,
|
45
|
-
"database" => @database,
|
46
|
-
"edgeDefinitions" => @edgeDefinitions,
|
47
|
-
"orphanCollections" => @orphanCollections,
|
48
|
-
"idCache" => @idCache
|
49
|
-
}.delete_if{|k,v| v.nil?}
|
50
|
-
end
|
51
|
-
alias to_h to_hash
|
52
|
-
|
53
|
-
def database
|
54
|
-
ArangoDatabase.new(database: @database)
|
55
|
-
end
|
56
|
-
|
57
|
-
# === GET ===
|
58
|
-
|
59
|
-
def retrieve # TESTED
|
60
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}", @@request)
|
61
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
62
|
-
return true if @@async
|
63
|
-
result = result.parsed_response
|
64
|
-
return result if @@verbose
|
65
|
-
return result["errorMessage"] if result["error"]
|
66
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
67
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
68
|
-
self
|
69
|
-
end
|
70
|
-
|
71
|
-
# === POST ===
|
72
|
-
|
73
|
-
def create # TESTED
|
74
|
-
body = { "name" => @graph, "edgeDefinitions" => @edgeDefinitions, "orphanCollections" => @orphanCollections }
|
75
|
-
request = @@request.merge({ :body => body.to_json })
|
76
|
-
result = self.class.post("/_db/#{@database}/_api/gharial", request)
|
77
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
78
|
-
return true if @@async
|
79
|
-
result = result.parsed_response
|
80
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : self
|
81
|
-
end
|
82
|
-
|
83
|
-
# === DELETE ===
|
84
|
-
|
85
|
-
def destroy # TESTED
|
86
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}", @@request)
|
87
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
88
|
-
return true if @@async
|
89
|
-
result = result.parsed_response
|
90
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
91
|
-
end
|
92
|
-
|
93
|
-
# === VERTEX COLLECTION ===
|
94
|
-
|
95
|
-
def vertexCollections # TESTED
|
96
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex", @@request)
|
97
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
98
|
-
return true if @@async
|
99
|
-
result = result.parsed_response
|
100
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)}
|
101
|
-
end
|
102
|
-
|
103
|
-
def addVertexCollection(collection:) # TESTED
|
104
|
-
collection = collection.is_a?(String) ? collection : collection.collection
|
105
|
-
body = { "collection" => collection }.to_json
|
106
|
-
request = @@request.merge({ :body => body })
|
107
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex", request)
|
108
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
109
|
-
return true if @@async
|
110
|
-
result = result.parsed_response
|
111
|
-
if @@verbose
|
112
|
-
@orphanCollections << collection unless result["error"]
|
113
|
-
result
|
114
|
-
else
|
115
|
-
return result["errorMessage"] if result["error"]
|
116
|
-
@orphanCollections << collection
|
117
|
-
self
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def removeVertexCollection(collection:) # TESTED
|
122
|
-
collection = collection.is_a?(String) ? collection : collection.collection
|
123
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{collection}", @@request)
|
124
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
125
|
-
return true if @@async
|
126
|
-
result = result.parsed_response
|
127
|
-
if @@verbose
|
128
|
-
@orphanCollections -= [collection] unless result["error"]
|
129
|
-
result
|
130
|
-
else
|
131
|
-
return result["errorMessage"] if result["error"]
|
132
|
-
@orphanCollections -= [collection]
|
133
|
-
self
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# === EDGE COLLECTION ===
|
138
|
-
|
139
|
-
def edgeCollections # TESTED
|
140
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge", @@request)
|
141
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
142
|
-
return true if @@async
|
143
|
-
result = result.parsed_response
|
144
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)}
|
145
|
-
end
|
146
|
-
|
147
|
-
def addEdgeCollection(collection:, from:, to:, replace: false) # TESTED
|
148
|
-
from = from.is_a?(String) ? [from] : from.is_a?(ArangoCollection) ? [from.collection] : from
|
149
|
-
to = to.is_a?(String) ? [to] : to.is_a?(ArangoCollection) ? [to.collection] : to
|
150
|
-
body = {}
|
151
|
-
collection = collection.is_a?(String) ? collection : collection.collection
|
152
|
-
body["collection"] = collection
|
153
|
-
body["from"] = from.map{|f| f.is_a?(String) ? f : f.id }
|
154
|
-
body["to"] = to.map{|t| t.is_a?(String) ? t : t.id }
|
155
|
-
request = @@request.merge({ :body => body.to_json })
|
156
|
-
if replace
|
157
|
-
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", request)
|
158
|
-
else
|
159
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge", request)
|
160
|
-
end
|
161
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
162
|
-
return true if @@async
|
163
|
-
result = result.parsed_response
|
164
|
-
if @@verbose
|
165
|
-
unless result["error"]
|
166
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
167
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
168
|
-
end
|
169
|
-
result
|
170
|
-
else
|
171
|
-
return result["errorMessage"] if result["error"]
|
172
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
173
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
174
|
-
self
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def replaceEdgeCollection(collection:, from:, to:) # TESTED
|
179
|
-
self.addEdgeCollection(collection: collection, from: from, to: to, replace: true)
|
180
|
-
end
|
181
|
-
|
182
|
-
def removeEdgeCollection(collection:) # TESTED
|
183
|
-
collection = collection.is_a?(String) ? collection : collection.collection
|
184
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", @@request)
|
185
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
186
|
-
return true if @@async
|
187
|
-
result = result.parsed_response
|
188
|
-
if @@verbose
|
189
|
-
unless result["error"]
|
190
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
191
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
192
|
-
end
|
193
|
-
result
|
194
|
-
else
|
195
|
-
return result["errorMessage"] if result["error"]
|
196
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
197
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
198
|
-
self
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
data/lib/ArangoRB_Index.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# === INDEXES ===
|
2
|
-
|
3
|
-
class ArangoIndex < ArangoServer
|
4
|
-
def initialize(collection: @@collection, database: @@database, body: {}, id: nil, type: nil, unique: nil, fields:, sparse: nil) # TESTED
|
5
|
-
if collection.is_a?(String)
|
6
|
-
@collection = collection
|
7
|
-
elsif collection.is_a?(ArangoCollection)
|
8
|
-
@collection = collection.collection
|
9
|
-
else
|
10
|
-
raise "collection should be a String or a ArangoCollection instance, not a #{collection.class}"
|
11
|
-
end
|
12
|
-
|
13
|
-
if database.is_a?(String)
|
14
|
-
@database = database
|
15
|
-
elsif database.is_a?(ArangoDatabase)
|
16
|
-
@database = database.database
|
17
|
-
else
|
18
|
-
raise "database should be a String or a ArangoDatabase instance, not a #{database.class}"
|
19
|
-
end
|
20
|
-
|
21
|
-
if body.is_a?(Hash)
|
22
|
-
@body = body
|
23
|
-
else
|
24
|
-
raise "body should be a Hash, not a #{body.class}"
|
25
|
-
end
|
26
|
-
|
27
|
-
unless id.nil?
|
28
|
-
@key = id.split("/")[1]
|
29
|
-
@id = id
|
30
|
-
end
|
31
|
-
@type = type
|
32
|
-
@sparse = sparse
|
33
|
-
@unique = unique unless unique.nil?
|
34
|
-
|
35
|
-
if fields.is_a?(String)
|
36
|
-
@fields = [fields]
|
37
|
-
elsif fields.is_a?(Array)
|
38
|
-
@fields = fields
|
39
|
-
else
|
40
|
-
raise "fields should be a String or an Array, not a #{database.class}"
|
41
|
-
end
|
42
|
-
|
43
|
-
@idCache = "IND_#{@id}"
|
44
|
-
end
|
45
|
-
|
46
|
-
attr_reader :body, :type, :id, :unique, :fields, :key, :sparse, :idCache
|
47
|
-
|
48
|
-
### RETRIEVE ###
|
49
|
-
|
50
|
-
def to_hash
|
51
|
-
{
|
52
|
-
"key" => @key,
|
53
|
-
"id" => @id,
|
54
|
-
"collection" => @collection,
|
55
|
-
"database" => @database,
|
56
|
-
"body" => @body,
|
57
|
-
"type" => @type,
|
58
|
-
"sparse" => @sparse,
|
59
|
-
"unique" => @unique,
|
60
|
-
"fields" => @fields,
|
61
|
-
"idCache" => @idCache
|
62
|
-
}.delete_if{|k,v| v.nil?}
|
63
|
-
end
|
64
|
-
alias to_h to_hash
|
65
|
-
|
66
|
-
def database
|
67
|
-
ArangoDatabase.new(database: @database)
|
68
|
-
end
|
69
|
-
|
70
|
-
def collection
|
71
|
-
ArangoCollection.new(collection: @collection, database: @database)
|
72
|
-
end
|
73
|
-
|
74
|
-
def retrieve # TESTED
|
75
|
-
result = self.class.get("/_db/#{@database}/_api/index/#{@id}", @@request)
|
76
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
77
|
-
return true if @@async
|
78
|
-
result = result.parsed_response
|
79
|
-
return result if @@verbose
|
80
|
-
return result["errorMessage"] if result["error"]
|
81
|
-
result.delete_if{|k,v| k == "error" || k == "code"}
|
82
|
-
@body = result
|
83
|
-
@type = result["type"]
|
84
|
-
@unique = result["unique"]
|
85
|
-
@fields = result["fields"]
|
86
|
-
@sparse = result["sparse"]
|
87
|
-
self
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.indexes(database: @@database, collection: @@collection) # TESTED
|
91
|
-
database = database.database if database.is_a?(ArangoDatabase)
|
92
|
-
collection = collection.collection if collection.is_a?(ArangoCollection)
|
93
|
-
query = { "collection": collection }
|
94
|
-
request = @@request.merge({ :query => query })
|
95
|
-
result = get("/_db/#{database}/_api/index", request)
|
96
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
97
|
-
return true if @@async
|
98
|
-
result = result.parsed_response
|
99
|
-
return result if @@verbose
|
100
|
-
return result["errorMessage"] if result["error"]
|
101
|
-
result.delete_if{|k,v| k == "error" || k == "code"}
|
102
|
-
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"], sparse: x["sparse"])}
|
103
|
-
result
|
104
|
-
end
|
105
|
-
|
106
|
-
def create # TESTED
|
107
|
-
body = @body.merge({
|
108
|
-
"fields" => @fields,
|
109
|
-
"unique" => @unique,
|
110
|
-
"type" => @type,
|
111
|
-
"id" => @id
|
112
|
-
}.delete_if{|k,v| v.nil?})
|
113
|
-
query = { "collection": @collection }
|
114
|
-
request = @@request.merge({ :body => body.to_json, :query => query })
|
115
|
-
result = self.class.post("/_db/#{@database}/_api/index", request)
|
116
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
117
|
-
return true if @@async
|
118
|
-
result = result.parsed_response
|
119
|
-
return result if @@verbose
|
120
|
-
return result["errorMessage"] if result["error"]
|
121
|
-
result.delete_if{|k,v| k == "error" || k == "code"}
|
122
|
-
@body = result
|
123
|
-
@id = result["id"]
|
124
|
-
@key = @id.split("/")[1]
|
125
|
-
self
|
126
|
-
end
|
127
|
-
|
128
|
-
def destroy # TESTED
|
129
|
-
result = self.class.delete("/_db/#{@database}/_api/index/#{id}", @@request)
|
130
|
-
return result.headers["x-arango-async-id"] if @@async == "store"
|
131
|
-
return true if @@async
|
132
|
-
result = result.parsed_response
|
133
|
-
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
134
|
-
end
|
135
|
-
end
|