arangorb 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +2 -2
- data/README.md +418 -123
- data/lib/ArangoRB_AQL.rb +90 -103
- data/lib/ArangoRB_Col.rb +476 -159
- data/lib/ArangoRB_DB.rb +305 -79
- data/lib/ArangoRB_Doc.rb +112 -114
- data/lib/ArangoRB_Edg.rb +81 -62
- data/lib/ArangoRB_Gra.rb +125 -76
- data/lib/ArangoRB_Index.rb +144 -0
- data/lib/ArangoRB_Ser.rb +439 -18
- data/lib/ArangoRB_Task.rb +136 -0
- data/lib/ArangoRB_Tra.rb +47 -42
- data/lib/ArangoRB_Tran.rb +48 -0
- data/lib/ArangoRB_User.rb +152 -0
- data/lib/ArangoRB_Ver.rb +74 -57
- data/lib/arangorb.rb +4 -0
- data/spec/arangoRB_helper.rb +2 -9
- data/spec/arangoRestart_helper.rb +14 -0
- data/spec/lib/{arangoAQL_helper.rb → 0.1.0/arangoAQL_helper.rb} +2 -21
- data/spec/lib/{arangoC_helper.rb → 0.1.0/arangoC_helper.rb} +40 -19
- data/spec/lib/{arangoDB_helper.rb → 0.1.0/arangoDB_helper.rb} +13 -13
- data/spec/lib/{arangoDoc_helper.rb → 0.1.0/arangoDoc_helper.rb} +10 -23
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -0
- data/spec/lib/{arangoG_helper.rb → 0.1.0/arangoG_helper.rb} +7 -21
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -0
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -0
- data/spec/lib/{arangoV_helper.rb → 0.1.0/arangoV_helper.rb} +6 -22
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -0
- data/spec/lib/1.0.0/arangoDB_helper.rb +81 -0
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -0
- data/spec/lib/1.0.0/arangoS_helper.rb +196 -0
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -0
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -0
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -0
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -0
- data/spec/spec_helper.rb +34 -0
- metadata +28 -15
- data/spec/lib/arangoE_helper.rb +0 -70
- data/spec/lib/arangoS_helper.rb +0 -28
- data/spec/lib/arangoT_helper.rb +0 -67
data/lib/ArangoRB_Gra.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
# ==== GRAPH ====
|
2
2
|
|
3
|
-
class
|
4
|
-
def initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: [])
|
3
|
+
class ArangoGraph < ArangoServer
|
4
|
+
def initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: []) # TESTED
|
5
5
|
if database.is_a?(String)
|
6
6
|
@database = database
|
7
|
+
elsif database.is_a?(ArangoDatabase)
|
8
|
+
@database = database.database
|
7
9
|
else
|
8
|
-
raise "database should be a String, not a #{
|
10
|
+
raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
|
9
11
|
end
|
10
12
|
|
11
13
|
if graph.is_a?(String)
|
12
14
|
@graph = graph
|
13
|
-
|
15
|
+
elsif database.is_a?(ArangoGraph)
|
16
|
+
@graph = graph.graph
|
14
17
|
else
|
15
|
-
raise "graph should be a String, not a #{graph.class}"
|
18
|
+
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
16
19
|
end
|
17
20
|
|
18
21
|
if edgeDefinitions.is_a?(Array)
|
@@ -32,136 +35,182 @@ class ArangoG < ArangoS
|
|
32
35
|
|
33
36
|
# === GET ===
|
34
37
|
|
35
|
-
def retrieve
|
36
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}")
|
37
|
-
if @@
|
38
|
-
result
|
38
|
+
def retrieve # TESTED
|
39
|
+
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}", @@request)
|
40
|
+
if @@async == "store"
|
41
|
+
result.headers["x-arango-async-id"]
|
39
42
|
else
|
40
|
-
|
41
|
-
|
43
|
+
result = result.parsed_response
|
44
|
+
if @@verbose
|
45
|
+
result
|
42
46
|
else
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
if result["error"]
|
48
|
+
result["errorMessage"]
|
49
|
+
else
|
50
|
+
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
51
|
+
@orphanCollections = result["graph"]["orphanCollections"]
|
52
|
+
self
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
58
|
# === POST ===
|
51
59
|
|
52
|
-
def create
|
60
|
+
def create # TESTED
|
53
61
|
body = { "name" => @graph, "edgeDefinitions" => @edgeDefinitions, "orphanCollections" => @orphanCollections }
|
54
|
-
|
55
|
-
result = self.class.post("/_db/#{@database}/_api/gharial",
|
56
|
-
@@
|
62
|
+
request = @@request.merge({ :body => body.to_json })
|
63
|
+
result = self.class.post("/_db/#{@database}/_api/gharial", request)
|
64
|
+
if @@async == "store"
|
65
|
+
result.headers["x-arango-async-id"]
|
66
|
+
else
|
67
|
+
result = result.parsed_response
|
68
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : self
|
69
|
+
end
|
57
70
|
end
|
58
71
|
|
59
72
|
# === DELETE ===
|
60
73
|
|
61
|
-
def destroy
|
62
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}")
|
63
|
-
@@
|
74
|
+
def destroy # TESTED
|
75
|
+
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}", @@request)
|
76
|
+
if @@async == "store"
|
77
|
+
result.headers["x-arango-async-id"]
|
78
|
+
else
|
79
|
+
result = result.parsed_response
|
80
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : true
|
81
|
+
end
|
64
82
|
end
|
65
83
|
|
66
84
|
# === VERTEX COLLECTION ===
|
67
85
|
|
68
|
-
def vertexCollections
|
69
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex")
|
70
|
-
@@
|
86
|
+
def vertexCollections # TESTED
|
87
|
+
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex", @@request)
|
88
|
+
if @@async == "store"
|
89
|
+
result.headers["x-arango-async-id"]
|
90
|
+
else
|
91
|
+
result = result.parsed_response
|
92
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)}
|
93
|
+
end
|
71
94
|
end
|
72
95
|
|
73
|
-
def addVertexCollection(collection:)
|
96
|
+
def addVertexCollection(collection:) # TESTED
|
74
97
|
collection = collection.is_a?(String) ? collection : collection.collection
|
75
|
-
body = { "collection" => collection }
|
76
|
-
|
77
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex",
|
78
|
-
if @@
|
79
|
-
result
|
98
|
+
body = { "collection" => collection }.to_json
|
99
|
+
request = @@request.merge({ :body => body })
|
100
|
+
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex", request)
|
101
|
+
if @@async == "store"
|
102
|
+
result.headers["x-arango-async-id"]
|
80
103
|
else
|
81
|
-
|
82
|
-
|
104
|
+
result = result.parsed_response
|
105
|
+
if @@verbose
|
106
|
+
result
|
83
107
|
else
|
84
|
-
|
85
|
-
|
108
|
+
if result["error"]
|
109
|
+
result["errorMessage"]
|
110
|
+
else
|
111
|
+
@orphanCollections << collection
|
112
|
+
self
|
113
|
+
end
|
86
114
|
end
|
87
115
|
end
|
88
116
|
end
|
89
117
|
|
90
|
-
def removeVertexCollection(collection:)
|
118
|
+
def removeVertexCollection(collection:) # TESTED
|
91
119
|
collection = collection.is_a?(String) ? collection : collection.collection
|
92
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{collection}")
|
93
|
-
if @@
|
94
|
-
result
|
120
|
+
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{collection}", @@request)
|
121
|
+
if @@async == "store"
|
122
|
+
result.headers["x-arango-async-id"]
|
95
123
|
else
|
96
|
-
|
97
|
-
|
124
|
+
result = result.parsed_response
|
125
|
+
if @@verbose
|
126
|
+
result
|
98
127
|
else
|
99
|
-
|
100
|
-
|
128
|
+
if result["error"]
|
129
|
+
result["errorMessage"]
|
130
|
+
else
|
131
|
+
@orphanCollections -= [collection]
|
132
|
+
self
|
133
|
+
end
|
101
134
|
end
|
102
135
|
end
|
103
136
|
end
|
104
137
|
|
105
138
|
# === EDGE COLLECTION ===
|
106
139
|
|
107
|
-
def edgeCollections
|
108
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge")
|
109
|
-
@@
|
140
|
+
def edgeCollections # TESTED
|
141
|
+
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge", @@request)
|
142
|
+
if @@async == "store"
|
143
|
+
result.headers["x-arango-async-id"]
|
144
|
+
else
|
145
|
+
result = result.parsed_response
|
146
|
+
@@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)}
|
147
|
+
end
|
110
148
|
end
|
111
149
|
|
112
|
-
def addEdgeCollection(collection:, from:, to:, replace: false)
|
113
|
-
from = from.is_a?(String) ? [from] : from.is_a?(
|
114
|
-
to = to.is_a?(String) ? [to] : to.is_a?(
|
150
|
+
def addEdgeCollection(collection:, from:, to:, replace: false) # TESTED
|
151
|
+
from = from.is_a?(String) ? [from] : from.is_a?(ArangoCollection) ? [from.collection] : from
|
152
|
+
to = to.is_a?(String) ? [to] : to.is_a?(ArangoCollection) ? [to.collection] : to
|
115
153
|
body = {}
|
116
154
|
collection = collection.is_a?(String) ? collection : collection.collection
|
117
155
|
body["collection"] = collection
|
118
156
|
body["from"] = from.map{|f| f.is_a?(String) ? f : f.id }
|
119
157
|
body["to"] = to.map{|t| t.is_a?(String) ? t : t.id }
|
120
|
-
|
158
|
+
request = @@request.merge({ :body => body.to_json })
|
121
159
|
|
122
160
|
if replace
|
123
|
-
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}",
|
161
|
+
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", request)
|
124
162
|
else
|
125
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge",
|
163
|
+
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge", request)
|
126
164
|
end
|
127
165
|
|
128
|
-
if @@
|
129
|
-
|
130
|
-
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
131
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
132
|
-
end
|
133
|
-
result
|
166
|
+
if @@async == "store"
|
167
|
+
result.headers["x-arango-async-id"]
|
134
168
|
else
|
135
|
-
|
136
|
-
|
169
|
+
result = result.parsed_response
|
170
|
+
if @@verbose
|
171
|
+
unless result["error"]
|
172
|
+
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
173
|
+
@orphanCollections = result["graph"]["orphanCollections"]
|
174
|
+
end
|
175
|
+
result
|
137
176
|
else
|
138
|
-
|
139
|
-
|
140
|
-
|
177
|
+
if result["error"]
|
178
|
+
result["errorMessage"]
|
179
|
+
else
|
180
|
+
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
181
|
+
@orphanCollections = result["graph"]["orphanCollections"]
|
182
|
+
self
|
183
|
+
end
|
141
184
|
end
|
142
185
|
end
|
143
186
|
end
|
144
187
|
|
145
|
-
def replaceEdgeCollection(collection:, from:, to:)
|
188
|
+
def replaceEdgeCollection(collection:, from:, to:) # TESTED
|
146
189
|
self.addEdgeCollection(collection: collection, from: from, to: to, replace: true)
|
147
190
|
end
|
148
191
|
|
149
|
-
def removeEdgeCollection(collection:)
|
192
|
+
def removeEdgeCollection(collection:) # TESTED
|
150
193
|
collection = collection.is_a?(String) ? collection : collection.collection
|
151
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}")
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
@orphanCollections = result["graph"]["orphanCollections"]
|
156
|
-
end
|
157
|
-
result
|
194
|
+
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", @@request)
|
195
|
+
|
196
|
+
if @@async == "store"
|
197
|
+
result.headers["x-arango-async-id"]
|
158
198
|
else
|
159
|
-
|
160
|
-
|
199
|
+
result = result.parsed_response
|
200
|
+
if @@verbose
|
201
|
+
unless result["error"]
|
202
|
+
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
203
|
+
@orphanCollections = result["graph"]["orphanCollections"]
|
204
|
+
end
|
205
|
+
result
|
161
206
|
else
|
162
|
-
|
163
|
-
|
164
|
-
|
207
|
+
if result["error"]
|
208
|
+
result["errorMessage"]
|
209
|
+
else
|
210
|
+
@edgeDefinitions = result["graph"]["edgeDefinitions"]
|
211
|
+
@orphanCollections = result["graph"]["orphanCollections"]
|
212
|
+
self
|
213
|
+
end
|
165
214
|
end
|
166
215
|
end
|
167
216
|
end
|
@@ -0,0 +1,144 @@
|
|
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
|
+
end
|
43
|
+
|
44
|
+
attr_reader :database, :collection, :body, :type, :id, :unique, :fields, :key, :sparse
|
45
|
+
|
46
|
+
def retrieve # TESTED
|
47
|
+
result = self.class.get("/_db/#{@database}/_api/index/#{@id}", @@request)
|
48
|
+
if @@async == "store"
|
49
|
+
result.headers["x-arango-async-id"]
|
50
|
+
else
|
51
|
+
result = result.parsed_response
|
52
|
+
if @@verbose
|
53
|
+
result
|
54
|
+
else
|
55
|
+
if result["error"]
|
56
|
+
result["errorMessage"]
|
57
|
+
else
|
58
|
+
result.delete("error")
|
59
|
+
result.delete("code")
|
60
|
+
@body = result
|
61
|
+
@type = result["type"]
|
62
|
+
@unique = result["unique"]
|
63
|
+
@fields = result["fields"]
|
64
|
+
@sparse = result["sparse"]
|
65
|
+
self
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.indexes(database: @@database, collection: @@collection) # TESTED
|
72
|
+
database = database.database if database.is_a?(ArangoDatabase)
|
73
|
+
collection = collection.collection if collection.is_a?(ArangoCollection)
|
74
|
+
query = { "collection": collection }
|
75
|
+
request = @@request.merge({ :query => query })
|
76
|
+
result = get("/_db/#{database}/_api/index", request)
|
77
|
+
if @@async == "store"
|
78
|
+
result.headers["x-arango-async-id"]
|
79
|
+
else
|
80
|
+
result = result.parsed_response
|
81
|
+
if @@verbose
|
82
|
+
result
|
83
|
+
else
|
84
|
+
if result["error"]
|
85
|
+
result["errorMessage"]
|
86
|
+
else
|
87
|
+
result.delete("error")
|
88
|
+
result.delete("code")
|
89
|
+
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"])}
|
90
|
+
result
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create # TESTED
|
97
|
+
body = @body.merge({
|
98
|
+
"fields" => @fields,
|
99
|
+
"unique" => @unique,
|
100
|
+
"type" => @type,
|
101
|
+
"id" => @id
|
102
|
+
}.delete_if{|k,v| v.nil?})
|
103
|
+
query = { "collection": @collection }
|
104
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
105
|
+
result = self.class.post("/_db/#{@database}/_api/index", request)
|
106
|
+
if @@async == "store"
|
107
|
+
result.headers["x-arango-async-id"]
|
108
|
+
else
|
109
|
+
result = result.parsed_response
|
110
|
+
if @@verbose
|
111
|
+
result
|
112
|
+
else
|
113
|
+
if result["error"]
|
114
|
+
result["errorMessage"]
|
115
|
+
else
|
116
|
+
result.delete("error")
|
117
|
+
result.delete("code")
|
118
|
+
@body = result
|
119
|
+
@id = result["id"]
|
120
|
+
@key = @id.split("/")[1]
|
121
|
+
self
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def destroy # TESTED
|
128
|
+
result = self.class.delete("/_db/#{@database}/_api/index/#{id}", @@request)
|
129
|
+
if @@async == "store"
|
130
|
+
result.headers["x-arango-async-id"]
|
131
|
+
else
|
132
|
+
result = result.parsed_response
|
133
|
+
if @@verbose
|
134
|
+
result
|
135
|
+
else
|
136
|
+
if result["error"]
|
137
|
+
result["errorMessage"]
|
138
|
+
else
|
139
|
+
true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|