arangorb 1.2.0 → 1.3.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 +18 -18
- data/Gemfile +8 -7
- data/LICENSE +21 -21
- data/README.md +906 -867
- data/lib/ArangoRB_AQL.rb +181 -160
- data/lib/ArangoRB_Cache.rb +174 -174
- data/lib/ArangoRB_Col.rb +526 -499
- data/lib/ArangoRB_DB.rb +363 -339
- data/lib/ArangoRB_Doc.rb +319 -298
- data/lib/ArangoRB_Edg.rb +184 -169
- data/lib/ArangoRB_Gra.rb +201 -180
- data/lib/ArangoRB_Index.rb +135 -115
- data/lib/ArangoRB_Replication.rb +261 -0
- data/lib/ArangoRB_Ser.rb +446 -441
- data/lib/ArangoRB_Task.rb +129 -113
- data/lib/ArangoRB_Tra.rb +169 -142
- data/lib/ArangoRB_Tran.rb +68 -53
- data/lib/ArangoRB_User.rb +149 -136
- data/lib/ArangoRB_Ver.rb +162 -147
- data/lib/arangorb.rb +16 -15
- data/spec/arangoRB_helper.rb +4 -4
- data/spec/arangoRestart_helper.rb +14 -14
- data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
- data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
- data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
- data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
- data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
- data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
- data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
- data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
- data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
- data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
- data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
- data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
- data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
- data/spec/spec_helper.rb +41 -41
- metadata +6 -5
data/lib/ArangoRB_Edg.rb
CHANGED
@@ -1,169 +1,184 @@
|
|
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
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
CHANGED
@@ -1,180 +1,201 @@
|
|
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
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
result =
|
64
|
-
return result
|
65
|
-
result
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
result
|
109
|
-
if @@
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
result
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
return
|
143
|
-
result = result.parsed_response
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
result
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
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
|