arangorb 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ArangoRB.gemspec +18 -18
  3. data/Gemfile +8 -7
  4. data/LICENSE +21 -21
  5. data/README.md +906 -867
  6. data/lib/ArangoRB_AQL.rb +181 -160
  7. data/lib/ArangoRB_Cache.rb +174 -174
  8. data/lib/ArangoRB_Col.rb +526 -499
  9. data/lib/ArangoRB_DB.rb +363 -339
  10. data/lib/ArangoRB_Doc.rb +319 -298
  11. data/lib/ArangoRB_Edg.rb +184 -169
  12. data/lib/ArangoRB_Gra.rb +201 -180
  13. data/lib/ArangoRB_Index.rb +135 -115
  14. data/lib/ArangoRB_Replication.rb +261 -0
  15. data/lib/ArangoRB_Ser.rb +446 -441
  16. data/lib/ArangoRB_Task.rb +129 -113
  17. data/lib/ArangoRB_Tra.rb +169 -142
  18. data/lib/ArangoRB_Tran.rb +68 -53
  19. data/lib/ArangoRB_User.rb +149 -136
  20. data/lib/ArangoRB_Ver.rb +162 -147
  21. data/lib/arangorb.rb +16 -15
  22. data/spec/arangoRB_helper.rb +4 -4
  23. data/spec/arangoRestart_helper.rb +14 -14
  24. data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
  25. data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
  26. data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
  27. data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
  28. data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
  29. data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
  30. data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
  31. data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
  32. data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
  33. data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
  34. data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
  35. data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
  36. data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
  37. data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
  38. data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
  39. data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
  40. data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
  41. data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
  42. data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
  43. data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
  44. data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
  45. data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
  46. data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
  47. data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
  48. data/spec/spec_helper.rb +41 -41
  49. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9083016d3d65b87f4f4b039e1b1a8c294e92fb8
4
- data.tar.gz: 4edf6c5fb4644ec569172b3e5291b445a4c9945c
3
+ metadata.gz: d54851cdef40b35916f72673a1501f5d5f74871a
4
+ data.tar.gz: 4b453ff4829696fa34e9b8d5db2c09ce73069a95
5
5
  SHA512:
6
- metadata.gz: 3b19660e6341a311663c7106ec0d4665c24afcd9cf5400a8f34ece5467ef95a299bb745a8ee5a64fee181efd92a5d5b367b17525c6dfb44775476c90c7277dbe
7
- data.tar.gz: 4e128d0d611404a35591867dce29402c5d24534f4361070fbd105fbac60b7f4a09a4ba3670dff3c380e0c841377420bb5493abb7f01b92105e81429edb398a01
6
+ metadata.gz: dca119efd2bdc23accf16a0e3169f3a67e95fb1cee43924d2156aa3a6f205d8c6890751b2508afc10971694195ef944bc493250a51d1703dee2c1b6779ac85af
7
+ data.tar.gz: 14b701df1c161236be807c53e67e9a52a9bab3d13e8f51035ebabdbe38731bd5e2fa140b8f6187ac2ba28aaf342b30a7b2995ee336f70d50f97352715caa9403
@@ -1,18 +1,18 @@
1
- # lib = File.expand_path('../lib', __FILE__)
2
- # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "rake"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'arangorb'
7
- s.version = '1.2.0'
8
- s.authors = ['Stefano Martin']
9
- s.email = ['stefano@seluxit.com']
10
- s.homepage = 'https://github.com/StefanoMartin/ArangoRB'
11
- s.license = 'MIT'
12
- s.summary = 'A simple ruby client for ArangoDB'
13
- s.description = "ArangoRB is an experimental Ruby gems based on ArangoDB's HTTP API. ArangoDB is a powerful mixed database based on documents and graphs"
14
- s.platform = Gem::Platform::RUBY
15
- s.require_paths = ['lib']
16
- s.files = FileList['lib/*', 'spec/**/*', 'ArangoRB.gemspec', 'Gemfile', 'LICENSE', 'README.md'].to_a
17
- s.add_dependency 'httparty', '~> 0.14', '>= 0.14.0'
18
- end
1
+ # lib = File.expand_path('../lib', __FILE__)
2
+ # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rake"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'arangorb'
7
+ s.version = '1.3.0'
8
+ s.authors = ['Stefano Martin']
9
+ s.email = ['stefano@seluxit.com']
10
+ s.homepage = 'https://github.com/StefanoMartin/ArangoRB'
11
+ s.license = 'MIT'
12
+ s.summary = 'A simple ruby client for ArangoDB'
13
+ s.description = "Ruby driver for ArangoDB's HTTP API"
14
+ s.platform = Gem::Platform::RUBY
15
+ s.require_paths = ['lib']
16
+ s.files = FileList['lib/*', 'spec/**/*', 'ArangoRB.gemspec', 'Gemfile', 'LICENSE', 'README.md'].to_a
17
+ s.add_dependency 'httparty', '~> 0.14', '>= 0.14.0'
18
+ end
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
- source "https://rubygems.org"
2
-
3
- gem "httparty", "~>0.14.0"
4
-
5
- group :development, :test do
6
- gem "rspec", "~>3.5"
7
- end
1
+ source "https://rubygems.org"
2
+
3
+ gem "httparty", "~>0.14.0"
4
+
5
+ group :development, :test do
6
+ gem "rspec", "~>3.5"
7
+ gem "awesome_print", "~>1.7"
8
+ end
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 StefanoMartin
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 StefanoMartin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,867 +1,906 @@
1
- ArangoRB [![Gem Version](https://badge.fury.io/rb/arangorb.svg)](https://badge.fury.io/rb/arangorb)
2
- ===============================
3
-
4
- [ArangoDatabase](https://www.arangodb.com/) is a native multi-model database with flexible data models for document, graphs, and key-values.
5
- ArangoRB is a Gem to use ArangoDatabase with Ruby. ArangoRB is based on the [HTTP API of ArangoDB](https://docs.arangodb.com/3.0/HTTP/index.html).
6
-
7
- ArangoRB has been tested with ArangoDatabase 3.0 on Ruby 2.3.1. It requires the gem "HTTParty"
8
-
9
- To install ArangoRB: `gem install arangorb`
10
-
11
- To use it in your application: `require "arangorb"`
12
-
13
- This Gem was created from [Seluxit ApS](http://seluxit.com/).
14
-
15
- ## Classes used
16
-
17
- ArangoRB has the following classes.
18
-
19
- * [ArangoServer](#ArangoServer): to manage the global variables for the management of the database
20
- * [ArangoDatabase](#ArangoDatabase): to manage Databases
21
- * [ArangoCollection](#ArangoCollection): to manage Collections
22
- * [ArangoDocument](#ArangoDocument): to manage Documents
23
- * [ArangoVertex](#ArangoVertex): to manage Vertexes
24
- * [ArangoEdge](#ArangoEdge): to manage Edges
25
- * [ArangoGraph](#ArangoGraph): to manage Graphs
26
- * [ArangoTraversal](#ArangoTraversal): to manage Traversal operations
27
- * [ArangoAQL](#arangoaql): to manage AQL instances
28
- * [ArangoUser](#ArangoUser): to manage Users
29
- * [ArangoIndex](#ArangoIndex): to manage Indexes
30
- * [ArangoTask](#ArangoTask): to manage Tasks
31
- * [ArangoTransaction](#ArangoTransaction): to manage Transactions
32
- * [ArangoCache](#ArangoCache): to manage a cache on your Computer
33
-
34
- <a name="ArangoServer"></a>
35
- ## ArangoServer
36
-
37
- ArangoServer is used to manage the default Database, Collection, User and Graph.
38
- It is used to give your login credentials and it is the mandatory step to start your database.
39
- Further it helps to manage the Server connected with ArangoDB.
40
-
41
- To setup your credentials use:
42
-
43
- ``` ruby
44
- ArangoServer.default_server user: "MyUsername", password: "MyPassword", server: "localhost", port: "8529"
45
- ```
46
-
47
- If not declared, the default values are user: "root", password: "", server: "localhost", port: "8529".
48
-
49
- ### Default variables
50
-
51
- Databases, Graphs and Collections used in your program can be defined each time. But often it is convenient to have some default one.
52
- If this is the case, the user can use ArangoServer to define some default values.
53
-
54
- ``` ruby
55
- ArangoServer.database = "MyDatabase" # Setup default Database
56
- ArangoServer.graph = "MyGraph" # Setup default Graph
57
- ArangoServer.collection = "MyCollection" # Setup default Collection
58
- ArangoServer.user = "MyUser" # Setup default User
59
- ```
60
-
61
- By default the default database is "\_system".
62
-
63
- ### Verbose
64
-
65
- For Debugging reasons the user can receive the original JSON file from the database by setting verbose on true (false by default).
66
-
67
- ``` ruby
68
- ArangoServer.verbose = true
69
- ```
70
-
71
- Remember that verbose is only for testing reason: to work efficiently verbose should be false.
72
-
73
- ### Information
74
-
75
- Basic informations can be retrieved with these command.
76
-
77
- ``` ruby
78
- ArangoServer.database # Check name default Database
79
- ArangoServer.graph # Check name default Graph
80
- ArangoServer.collection # Check name default Collection
81
- ArangoServer.user # Check name default User
82
- ArangoServer.address # Check address used to connect with the server
83
- ArangoServer.username # Check name used to connect with the server
84
- ArangoServer.verbose # Check if verbose is true or false
85
- ArangoServer.async # Check the status of async
86
- ArangoServer.request # Check the default request sent to the server
87
- ```
88
-
89
- To retrieve lists
90
-
91
- ``` ruby
92
- ArangoServer.endpoints # Lists of endpoints used
93
- ArangoServer.users # Lists of available users
94
- ArangoServer.databases # Lists of available databases
95
- ArangoServer.tasks # Lists of available tasks
96
- ```
97
-
98
- To monitoring the server you can use the following commands
99
-
100
- ``` ruby
101
- ArangoServer.log # Return log files
102
- ArangoServer.reload # Reloads the routing information from the collection routing.
103
- ArangoServer.statistics # Returns the statistics information
104
- ArangoServer.statistics description: true # Fetch descriptive info of statistics
105
- ArangoServer.role # Get to know whether this server is a Coordinator or DB-Server
106
- ArangoServer.serverId # Fetch this servers uniq identifier
107
- ```
108
-
109
- ### Manage Async
110
-
111
- With ArangoServer you can manage Async results.
112
-
113
- ``` ruby
114
- ArangoServer.async = false # default
115
- ArangoServer.async = true # fire and forget
116
- ArangoServer.async = "store" # fire and store
117
- ```
118
-
119
- If Async is "store", then the commands of ArangoRB will return the id of the Async requests.
120
- ArangoServer provides different methods to manage these Async requests.
121
-
122
- ``` ruby
123
- ArangoServer.pendingAsync # Querying the status of a pending job
124
- ArangoServer.fetchAsync id: id # Fetches a job result and removes it from the queue
125
- ArangoServer.retrieveAsync id: id # Returns the status of a specific job
126
- ArangoServer.retrieveAsync type: type # Returns the ids of job results with a specific status
127
- # Type can be "done" or "pending"
128
- ArangoServer.retrieveDoneAsync # Equivalent to ArangoServer.retrieveAsync type: "done"
129
- ArangoServer.retrievePendingAsync # Equivalent to ArangoServer.retrieveAsync type: "pending"
130
- ArangoServer.cancelAsync id: id # Cancels an async job
131
- ArangoServer.destroyAsync id: id # Deletes an async job result
132
- ArangoServer.destroyAsync type: type # Deletes async jobs with a specific status
133
- # Type can be "all" or "expired"
134
- ArangoServer.destroyAllAsync # Equivalent to ArangoServer.destroyAsync type: "all"
135
- ArangoServer.destroyExpiredAsync # Equivalent to ArangoServer.destroyAsync type: "expired"
136
- ```
137
-
138
- ### Batch
139
-
140
- ArangoDB offers a batch request API that clients can use to send multiple operations in one batch to ArangoDB. To manage it you can use the following way.
141
-
142
- ``` ruby
143
- queries = [
144
- {
145
- "type": "POST",
146
- "address": "/_db/MyDatabase/_api/collection",
147
- "body": {"name": "newCOLLECTION"},
148
- "id": "1"
149
- },
150
- {
151
- "type": "GET",
152
- "address": "/_api/database",
153
- "id": "2"
154
- }
155
- ]
156
- ArangoServer.batch queries: queries
157
- ```
158
-
159
- To manage these batch, ArangoServer offers the following functions:
160
-
161
- ``` ruby
162
- ArangoServer.createDumpBatch ttl: 10 # Create a new dump batch with 10 second time-to-live (return id of the dumpBatch)
163
- ArangoServer.prolongDumpBatch id: idDumpBatch, ttl: 20 # Prolong the life of a batch for 20 seconds
164
- ArangoServer.destroyDumpBatch id: idDumpBatch # Delete a selected batch
165
- ```
166
-
167
- ### Miscellaneous
168
-
169
- ``` ruby
170
- ArangoServer.version # Returns the server version number
171
- ArangoServer.flushWAL # Flushes the write-ahead log
172
- ArangoServer.propertyWAL # Retrieves the configuration of the write-ahead log
173
- ArangoServer.changePropertyWAL # Configures the write-ahead log
174
- ArangoServer.transactions # Returns information about the currently running transactions
175
- ArangoServer.time # Get the current time of the system
176
- ArangoServer.echo # Return current request
177
- ArangoServer.databaseVersion # Return the required version of the database
178
- ArangoServer.sleep duration: 10 # Sleep for a specified amount of seconds
179
- ArangoServer.shutdown # Initiate shutdown sequence
180
- ArangoServer.restart # Restart ArangoDB (requires administration access)
181
- ```
182
-
183
- UNTESTED
184
-
185
- ``` ruby
186
- ArangoServer.test body: body # Runs tests on server
187
- ArangoServer.execute body: body # Execute a script on the server.
188
- ```
189
-
190
- ### Sharding (UNTESTED)
191
-
192
- ArangoDB permits the sharding of the database. Although these methods has not been tested with ArangoRB.
193
-
194
- ``` ruby
195
- ArangoServer.cluster # Default cluster
196
- ArangoServer.getCluster body: body, cluster: cluster # Retrieve cluster
197
- ArangoServer.executeCluster body: body, cluster: cluster # Execute cluster
198
- ArangoServer.executeClusterPut body: body, cluster: cluster # Execute cluster
199
- ArangoServer.executeClusterHead body: body, cluster: cluster # Execute cluster
200
- ArangoServer.destroyCluster cluster: cluster # Delete cluster
201
- ArangoServer.updateCluster body: body, cluster: cluster # Update cluster
202
- ArangoServer.checkPort port: port # Allows to check whether a given port is usable
203
- ArangoServer.server # Returns the id of a server in a cluster.
204
- ArangoServer.clusterStatistics dbserver: dbserver # Allows to query the statistics of a DBserver in the cluster
205
- ```
206
-
207
- <a name="ArangoDatabase"></a>
208
- ## ArangoDatabase
209
-
210
- ArangoDatabase is used to manage your Database. You can create an instance in the following way:
211
-
212
- ``` ruby
213
- myDatabase = ArangoDatabase.new database: "MyDatabase"
214
- ```
215
-
216
- Alternatively, you can use the default values provided by ArangoServer:
217
-
218
- ``` ruby
219
- ArangoServer.database = "MyDatabase"
220
- myDatabase = ArangoDatabase.new
221
- ```
222
-
223
- ### Create and Destroy a Database
224
-
225
- ``` ruby
226
- myDatabase.create # Create a new Database
227
- myDatabase.destroy # Delete the selected Database
228
- ```
229
-
230
- ### Retrieve information
231
-
232
- ``` ruby
233
- ArangoDatabase.info # Obtain general info about the databases
234
- ArangoDatabase.databases # Obtain an Array with the available databases
235
- myDatabase.collections # Obtain an Array with the available collections in the selected Database
236
- myDatabase.graphs # Obtain an Array with the available graphs in the selected Database
237
- myDatabase.functions # Obtain an Array with the available functions in the selected Database
238
- ```
239
-
240
- It is possible to access its Collections and Graphs by their ids.
241
-
242
- ``` ruby
243
- myDatabase["MyCollection"].retrieve # where "MyCollection" is the id of the collection
244
- myDatabase.collection("MyCollection").retrieve
245
- myDatabase.graph("MyGraph").retrieve
246
- ```
247
-
248
-
249
- ### Query
250
-
251
- ArangoDatabase instances can manage the queries used in their Database.
252
-
253
- ``` ruby
254
- myDatabase.propertiesQuery; # See property of the Query
255
- myDatabase.currentQuery; # Check the current Query
256
- myDatabase.slowQuery; # Find slow queries
257
- myDatabase.stopSlowQuery; # Stop slow queries
258
- myDatabase.kill query: myQuery # Kill a Query
259
- myDatabase.changePropertiesQuery maxSlowQueries: 65 # Change properties of a Query
260
- ```
261
-
262
- ### Cache
263
-
264
- To manage the cache ArangoDatabase provides the following three functions.
265
-
266
- ``` ruby
267
- myDatabase.clearCache # Clear Cache
268
- myDatabase.propertyCache # Check properties Cache
269
- myDatabase.changePropertyCache maxResults: 30 # Change properties Cache
270
- ```
271
-
272
- ### AQL Functions
273
-
274
- ``` ruby
275
- myDatabase.createFunction code: "function(){return 1+1;}", name: "myFunction" # Create a new Function
276
- myDatabase.deleteFunction name: "myFunction" # Delete a function
277
- myDatabase.functions # Retrieve a list of the available functions
278
- ```
279
-
280
- ### User
281
-
282
- You can manage the right of a user to access the database.
283
-
284
- ``` ruby
285
- myDatabase.grant user: myUser # Grant access to database
286
- myDatabase.revoke user: myUser # Revoke access to database
287
- ```
288
-
289
- ### Replication (UNTESTED)
290
-
291
- ``` ruby
292
- myDatabase.inventory # Returns an overview of collections and their indexes
293
- myDatabase.clusterInventory # Return cluster inventory of collections and indexes
294
- myDatabase.logger # Return replication logger state
295
- myDatabase.loggerFollow # Returns log entries
296
- myDatabase.firstTick # Returns the first available tick value
297
- myDatabase.rangeTick # Return the tick ranges available in the WAL logfiles
298
- myDatabase.sync # Synchronize data from a remote endpoint
299
- myDatabase.configurationReplication # Return configuration of replication applier
300
- myDatabase.modifyConfigurationReplication # Adjust configuration of replication applier
301
- myDatabase.startReplication # Start replication applier
302
- myDatabase.stateReplication # State of the replication applier
303
- myDatabase.stopReplication # Stop replication applier
304
- myDatabase.enslave # Turn the server into a slave of another
305
- ```
306
-
307
- <a name="ArangoCollection"></a>
308
- ## ArangoCollection
309
-
310
- ArangoDatabase is used to manage your Collections. You can create an ArangoCollection instance in one of the following way:
311
-
312
- ``` ruby
313
- myCollection = ArangoCollection.new database: "MyDatabase", collection: "MyCollection"
314
- myCollection = ArangoCollection.new collection: "MyCollection" # Using the default database
315
- myCollection = ArangoCollection.new # Using the default database and collection
316
- ```
317
-
318
- A Collection can be of two types: "Document" and "Edge". If you want to specify it, uses:
319
-
320
- ``` ruby
321
- myCollectionA = ArangoCollection.new collection: "MyCollectionA", type: "Document"
322
- myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"
323
- ```
324
-
325
- ### Create a Collection
326
-
327
- `myCollection.create`
328
-
329
- If not specified the default type of the Collection is "Document".
330
- To create an Edge Collection you can use one of the next three options:
331
-
332
- ``` ruby
333
- myCollection.create_edge_collection
334
- myCollection.create type: "Edge"
335
- myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"; myCollectionB.create
336
- ```
337
-
338
- ### Destroy or Truncate a Collections
339
-
340
- Destroy will delete the selected Collection from the Database.
341
-
342
- `myCollection.destroy`
343
-
344
- Truncate will delete all the Documents inside the selected Collection.
345
-
346
- `myCollection.truncate`
347
-
348
- ### Retrieve information
349
-
350
- It is possible to access its Documents and its database.
351
-
352
- ``` ruby
353
- myCollection["MyDocument"]
354
- myDatabase.document("MyDocument")
355
- myDatabase.database
356
- ```
357
-
358
- For other information
359
-
360
- ``` ruby
361
- myCollection.retrieve # Retrieve the selected Collection
362
- myCollection.indexes # Return a list of all used Indexes in the Collection
363
- myCollection.data # Returns the whole content of one collection
364
- myCollection.properties # Properties of the Collection
365
- myCollection.count # Number of Documents in the Collection
366
- myCollection.stats # Statistics of the Collection
367
- myCollection.revision # Return collection revision id
368
- myCollection.checksum # Return checksum for the Collection
369
- ```
370
-
371
- To retrieve all the documents of a Collection you can use:
372
-
373
- ``` ruby
374
- myCollection.documents
375
- myCollection.allDocuments
376
- ```
377
-
378
- These two functions are similar except for the fact that you can assign different variables.
379
-
380
- `myCollection.documents type: "path"`
381
-
382
- Type can be "path", "id" or "key" in relation what we wish to have. If not specified we will receive an array of ArangoDocument instances.
383
-
384
- `myCollection.allDocuments skip: 3, limit: 100, batchSize: 10`
385
-
386
- It means that we skip the first three Documents, we can retrieve the next 100 Documents but we return only the first ten.
387
-
388
- To retrieve specific Document you can use:
389
-
390
- ``` ruby
391
- myCollection.documentsMatch match: {"value" => 4} # All Documents of the Collection with value equal to 4
392
- myCollection.documentMatch match: {"value" => 4} # The first Document of the Collection with value equal to 4
393
- myCollection.documentByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array
394
- myCollection.random # A random Document of the Collection
395
- ```
396
-
397
- ### Modify the Collection
398
-
399
- ``` ruby
400
- myCollection.load # Load the Collection
401
- myCollection.unload # Unload the Collection
402
- myCollection.change waitForSync: true # Change a property of the Collection
403
- myCollection.rename "myCollectionC" # Rename the Collection
404
- myCollection.rotate # Rotate journal of a collection
405
- ```
406
-
407
- ### Import and Export Documents
408
-
409
- For the standard way to import one or more Documents (or Edges) we refer to the [dedicated ArangoDocument section](#create_doc).
410
- However it is possible to import a huge quantity of documents in a Collection with only one requests with the command import.
411
-
412
- <strong>Import one Document with Array</strong>
413
- I import one document with the following structure {"value": "uno", "num": 1, "name": "ONE"}.
414
- ``` ruby
415
- attributes = ["value", "num", "name"]
416
- values = ["uno",1,"ONE"]
417
- myCollection.import attributes: attributes, values: values
418
- ```
419
-
420
- <strong>Import more Documents with Array</strong>
421
- I import three Documents with the following structure {"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "TWO"}, {"value": "tre", "num": 3, "name": "THREE"}.
422
- ``` ruby
423
- attributes = ["value", "num", "name"]
424
- values = [["uno",1,"ONE"],["due",2,"TWO"],["tre",3,"THREE"]]
425
- myCollection.import attributes: attributes, values: values
426
- ```
427
-
428
- <strong>Import more Documents with JSON</strong>
429
- I import two Documents with the following structure {"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "TWO"}.
430
- ``` ruby
431
- body = [{"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "DUE"}]
432
- myCollection.importJSON body: body
433
- ```
434
-
435
- As it is possible to import files, it is possible to export all the Document of a Collection with the following command.
436
- ``` ruby
437
- myCollection.export
438
- ```
439
-
440
- Alternatively it is possible to retrieve all the Documents in a Collection gradually.
441
-
442
- ``` ruby
443
- myCollection.export batchSize: 3 # First three Documents of the Collection
444
- myCollection.exportNext # Next three Documents
445
- myCollection.exportNext # Next three Documents
446
- ```
447
-
448
- ### Other operations
449
-
450
- ``` ruby
451
- myCollection.removeByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array will be removed
452
- myCollection.removeMatch match: {"value" => 4} # All Documents of the Collection with value equal to 4 will be removed
453
- myCollection.replaceMatch match: {"value" => 4}, newValue: {"value" => 6} # All Documents of the Collection with value equal to 4 will be replaced with the new Value
454
- myCollection.updateMatch match: {"value" => 4}, newValue: {"value" => 6} # All Documents of the Collection with value equal to 4 will be updated with the new Value
455
- ```
456
-
457
- <a name="ArangoDocument"></a>
458
- ## ArangoDocument
459
-
460
- An Arango Document is an element of a Collection. Edges are documents with "\_from" and "\_to" in their body.
461
- You can create an ArangoCollection instance in one of the following way:
462
-
463
- ``` ruby
464
- myDocument = ArangoDocument.new database: "MyDatabase", collection: "MyCollection", key: "myKey"
465
- myDocument = ArangoDocument.new collection: "MyCollection", key: "myKey" # Using default Database
466
- myDocument = ArangoDocument.new key: "myKey" # Using default Collection and Database
467
- myDocument = ArangoDocument.new # Using default Collection and Database and I don't want to define a key for my Instance
468
- ```
469
-
470
- In the case you want to define a Edge, it is convenient to introduce the parameters "from" and "to" in the instance.
471
-
472
- ``` ruby
473
- myEdge = ArangoDocument.new from: myDocA, to: myDocB
474
- ```
475
-
476
- where myDocA and myDocB are the IDs of two Documents or are two ArangoDocument instances.
477
- During the instance, it is possible to define a Body for the Document.
478
-
479
- ``` ruby
480
- myDocument = ArangoDocument.new body: {"value" => 17}
481
- ```
482
-
483
- <a name="create_doc"></a>
484
- ### Create one or more Documents
485
-
486
- ArangoRB provides several way to create a single Document.
487
-
488
- ``` ruby
489
- myDocument.create
490
- myCollection.create_document document: myDocument # myDocument is an ArangoDocument instance or a Hash
491
- ArangoDocument.create body: {"value" => 17}, collection: myDocument
492
- ```
493
-
494
- Or more Documents.
495
-
496
- ``` ruby
497
- myCollection.create_document document: [myDocumentA, myDocumentB, {"value" => 17}] # Array of ArangoDocument instances and Hashes
498
- ArangoDocument.create body: [myDocumentA, {"value" => 18}, {"value" => 3}], collection: myDocument # Array of ArangoDocument instances and Hash
499
- ```
500
-
501
- ### Create one or more Edges
502
-
503
- ArangoRB has different way to create one or multiple edges. Here some example:
504
-
505
- ``` ruby
506
- myEdge = ArangoDocument.new from: myDocA, to: myDocB; myEdge.create
507
- myEdge.create_edge from: myDocA, to: myDocB # myDocA and myDocB are ArangoDocument ids or ArangoDocument instances
508
- myEdgeCollection.create_edge document: myEdge, from: myDocA, to: myDocB
509
- ArangoDocument.create_edge body: {"value" => 17}, from: myDocA, to: myDocB, collection: myEdgeCollection
510
- ```
511
-
512
- Further we have the possibility to create different combination of Edges in only one line of code
513
-
514
- One-to-one with one Edge class
515
-
516
- * [myDocA] --(myEdge)--> [myDocB]
517
-
518
- ``` ruby
519
- myEdgeCollection.create_edge document: myEdge, from: myDocA, to: myDocB
520
- ```
521
-
522
- One-to-more with one Edge class (and More-to-one with one Edge class)
523
-
524
- * [myDocA] --(myEdge)--> [myDocB]
525
- * [myDocA] --(myEdge)--> [myDocC]
526
-
527
- ``` ruby
528
- myEdgeCollection.create_edge document: myEdge, from: myDocA, to: [myDocB, myDocC]
529
- ```
530
-
531
- More-to-More with one Edge class
532
-
533
- * [myDocA] --(myEdge)--> [myDocC]
534
- * [myDocB] --(myEdge)--> [myDocC]
535
- * [myDocA] --(myEdge)--> [myDocD]
536
- * [myDocB] --(myEdge)--> [myDocD]
537
-
538
- ``` ruby
539
- myEdgeCollection.create_edge document: myEdge, from: [myDocA, myDocB], to: [myDocC, myDocD]
540
- ```
541
-
542
- More-to-More with more Edge classes
543
-
544
- * [myDocA] --(myEdge)--> [myDocC]
545
- * [myDocB] --(myEdge)--> [myDocC]
546
- * [myDocA] --(myEdge)--> [myDocD]
547
- * [myDocB] --(myEdge)--> [myDocD]
548
- * [myDocA] --(myEdge2)--> [myDocC]
549
- * [myDocB] --(myEdge2)--> [myDocC]
550
- * [myDocA] --(myEdge2)--> [myDocD]
551
- * [myDocB] --(myEdge2)--> [myDocD]
552
-
553
- ``` ruby
554
- myEdgeCollection.create_edge document: [myEdge, myEdge2], from: [myDocA, myDocB], to: [myDocC, myDocD]
555
- ```
556
-
557
- ### Destroy a Document
558
-
559
- ``` ruby
560
- myDocument.destroy
561
- ```
562
-
563
- ### Retrieve information
564
-
565
- ``` ruby
566
- myDocument.retrieve # Retrieve Document
567
- myDocument.collection # Retrieve Collection of the Document
568
- myDocument.database # Retrieve Database of the Document
569
- myDocument.retrieve_edges collection: myEdgeCollection # Retrieve all myEdgeCollection edges connected with the Document
570
- myDocument.any(myEdgeCollection) # Retrieve all myEdgeCollection edges connected with the Document
571
- myDocument.in(myEdgeCollection) # Retrieve all myEdgeCollection edges coming in the Document
572
- myDocument.out(myEdgeCollection) # Retrieve all myEdgeCollection edges going out the Document
573
- myEdge.from # Retrieve the document at the begin of the edge
574
- myEdge.to # Retrieve the document at the end of the edge
575
- ```
576
-
577
- #### Example: how to navigate the edges
578
-
579
- Think for example that we have the following schema:
580
- * A --[class: a, name: aa]--> B
581
- * A --[class: a, name: bb]--> C
582
- * A --[class: b, name: cc]--> D
583
- * B --[class: a, name: dd]--> E
584
-
585
- Then we have:
586
-
587
- * A.retrieve is A
588
- * A.retrieve_edges(collection: a) is [aa, bb]
589
- * B.any(a) is [aa, dd]
590
- * B.in(a) is [aa]
591
- * B.out(a) is [dd]
592
- * aa.from is A
593
- * aa.to is B
594
-
595
- We can even do some combinations: for example A.out(a)[0].to.out(a)[0].to is E since:
596
- * A.out(a) is [aa]
597
- * A.out(a)[0] is aa
598
- * A.out(a)[0].to is B
599
- * A.out(a)[0].to.out(a) is [dd]
600
- * A.out(a)[0].to.out(a)[0] is dd
601
- * A.out(a)[0].to.out(a)[0].to is E
602
-
603
- ### Modify
604
-
605
- ``` ruby
606
- myDocument.update body: {"value" => 3} # We update or add a value
607
- myDocument.replace body: {"value" => 3} # We replace a value
608
- ```
609
-
610
- <a name="ArangoGraph"></a>
611
- ## ArangoGraph
612
-
613
- ArangoGraph are used to manage Graphs. You can create an ArangoGraph instance in one of the following way.
614
-
615
- ``` ruby
616
- myGraph = ArangoGraph.new database: "MyDatabase", graph: "MyGraph"
617
- myGraph = ArangoGraph.new graph: "MyGraph" # By using the default Database
618
- myGraph = ArangoGraph.new # By using the defauly Database and Graph
619
- ```
620
-
621
- ### Create, Retrieve and Destroy a Graph
622
-
623
- ``` ruby
624
- myGraph.create # create a new Graph
625
- myGraph.retrieve # retrieve the Graph
626
- myGraph.database # retrieve database of the Graph
627
- myGraph.destroy # destroy the Graph
628
- ```
629
-
630
- ### Manage Vertex Collections
631
-
632
- ``` ruby
633
- myGraph.vertexCollections # Retrieve all the vertexCollections of the Graph
634
- myGraph.addVertexCollection collection: "myCollection" # Add a Vertex Collection to our Graph
635
- myGraph.removeVertexCollection collection: "myCollection" # Remove a Vertex Collection to our Graph
636
- ```
637
-
638
- ### Manage Edge Collections
639
-
640
- ``` ruby
641
- myGraph.edgeCollections # Retrieve all the edgeCollections of the Graph
642
- myGraph.addEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Add an Edge Collection to our Graph
643
- myGraph.replaceEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Replace an Edge Collection to our Graph
644
- myGraph.removeEdgeCollections collection: "myEdgeCollection" # Remove an Edge Collection to our Graph
645
- ```
646
-
647
- <a name="ArangoVertex"></a><a name="ArangoEdge"></a>
648
- ## ArangoVertex and ArangoEdge
649
-
650
- Both these two classes inherit the class ArangoDocument.
651
- These two classes have been created since ArangoDatabase offers, in connection of the chosen graph, different HTTP requests to manage Vertexes and Edges. We recommend the reader to read carefully the section on [ArangoDocument instances](#ArangoDocument) before to start to use ArangoVertex and ArangoEdge instances.
652
-
653
- ### ArangoVertex methods
654
-
655
- ArangoVertex inherit all the methods of ArangoDocument class. The following one works similar to the one of ArangoDocument Class but use different HTTP requests. For this reason the performance could be different.
656
- To use ArangoVertex, the Collection of the Vertex needs to be added either to the VertexCollections or to the EdgeCollections of the chosen Graph.
657
-
658
- ``` ruby
659
- myVertex = ArangoVertex.new key: "newVertex", body: {"value" => 3}, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
660
- myVertex.create # create a new Document in the Graph
661
- myVertex.retrieve # retrieve a Document
662
- myVertex.graph # Retrieve Graph of the Document
663
- myVertex.replace body: {"value" => 6} # replace the Document
664
- myVertex.update body: {"value" => 6} # update the Document
665
- myVertex.destroy # delete the Document
666
- ```
667
-
668
- ### ArangoEdge methods
669
-
670
- ArangoEdge inherit all the methods of ArangoDocument class. The following one works similar to the one of ArangoDocument Class but use a different HTTP request. For this reason the performance could be different.
671
- To use ArangoEdge, the Collection of the Edge needs to be added to the EdgeCollections of the chosen Graph.
672
-
673
- ``` ruby
674
- myEdge = ArangoEdge.new key: "newVertex", body: {"value" => 3}, from: myArangoDocument, to: myArangoDocument, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
675
- myEdge.create # create a new Document of type Edge in the Graph
676
- myEdge.retrieve # retrieve a Document
677
- myEdge.graph # Retrieve Graph of the Document
678
- myEdge.replace body: {"value" => 6} # replace the Document
679
- myEdge.update body: {"value" => 6} # update the Document
680
- myEdge.destroy # delete the Document
681
- ```
682
-
683
- <a name="ArangoTraversal"></a>
684
- ## ArangoTraversal
685
-
686
- ArangoTraversal is used to administrate the traversals.
687
- ArangoTraversal needs to know the vertex from where the traversal starts, the direction the traversal is going and either the Graph or the EdgeCollection we want to analize.
688
-
689
- ``` ruby
690
- myTraversal = ArangoTraversal.new # create new ArangoTraversal
691
- myTraversal.vertex = myVertex # define starting Vertex
692
- myTraversal.graph = myGraph # define used Graph
693
- myTraversal.edgeCollection = myEdgeCollection # define used Edge
694
- myTraversal.in # Direction is in
695
- myTraversal.out # Direction is out
696
- myTraversal.any # Direction is in and out
697
- myTraversal.min = 1 # Define how minimum deep we want to go with the traversal
698
- myTraversal.max = 3 # Define how maximum deep we want to go with the traversal
699
- ```
700
-
701
- After the traversal is setup, you can execute it:
702
-
703
- ``` ruby
704
- myTraversal.execute
705
- ```
706
-
707
- <a name="arangoaql"></a>
708
- ## ArangoAQL - ArangoDatabase Query Language
709
-
710
- ArangoAQL is used to manage the ArangoDB query language. To instantiate a query
711
-
712
- ``` ruby
713
- myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
714
- ```
715
-
716
- To execute it use:
717
- ``` ruby
718
- myQuery.execute
719
- ```
720
-
721
- If the query is too big, you can divide the fetching in pieces, for example:
722
- ``` ruby
723
- myQuery.size = 10
724
- myQuery.execute # First 10 documents
725
- myQuery.next # Next 10 documents
726
- myQuery.next # Next 10 documents
727
- ```
728
-
729
- ### Check property query
730
-
731
- ``` ruby
732
- myQuery.explain # Show data query
733
- myQuery.parse # Parse query
734
- myQuery.properties; # Check properties
735
- myQuery.current; # Retrieve current Query
736
- myQuery.slow; # Retrieve slow Queries
737
- myQuery.changeProperties maxSlowQueries: 65 # Change Properties
738
- ```
739
-
740
- ### Delete query
741
-
742
- ``` ruby
743
- myQuery.stopSlow; # Stop Slow query
744
- myQuery.kill; # Kill Query
745
- ```
746
-
747
- <a name="ArangoUser"></a>
748
- ## ArangoUser
749
-
750
- ArangoUser manages the users.
751
- To initialize an user:
752
-
753
- ``` ruby
754
- myUser = ArangoUser.new user: "MyUser", password: "password"
755
- ```
756
-
757
- ### User management
758
-
759
- ``` ruby
760
- myUser.retrieve # Retrieve User
761
- myUser["MyDatabase"] # Retrieve database if the user can access it
762
- myUser.create # Create a new User
763
- myUser.replace active: false # Replace User
764
- myUser.update active: false # Update User
765
- myUser.destroy # Delete User
766
- ```
767
-
768
- ### Database management
769
-
770
- ``` ruby
771
- myUser.databases # Check permission Databases
772
- myUser.grant database: "MyDatabase" # Grant access to a database
773
- myUser.revoke database: "MyDatabase" # Revoke access to a database
774
- ```
775
-
776
- <a name="ArangoIndex"></a>
777
- ## ArangoIndex
778
-
779
- ArangoIndex manages the indexes.
780
- To initialize an index:
781
-
782
- ``` ruby
783
- myIndex = ArangoIndex.new fields: "num", unique: false, id: "myIndex"
784
- ```
785
-
786
- ### Index management
787
-
788
- ``` ruby
789
- myIndex.retrieve # Retrieve Index
790
- myIndex.create # Create a new Index
791
- ArangoIndex.indexes collection: "MyCollection" # List indexes
792
- myIndex.destroy # Delete Index
793
- ```
794
-
795
- Alternatively, you can create an Index of a Collection directly from its Collection.
796
-
797
- ``` ruby
798
- myCollection.createIndex unique: false, fields: "num", type: "hash"
799
- ```
800
-
801
- <a name="ArangoTransaction"></a>
802
- ## ArangoTransaction
803
-
804
- Transactions are managed by ArangoTransaction. This class has only initialization and execution.
805
-
806
- ``` ruby
807
- myArangoTransaction = ArangoTransaction.new action: "function(){ var db = require('@arangodb').db; db.MyCollection.save({}); return db.MyCollection.count(); }", write: myCollection # Or read
808
- myArangoTransaction.execute # Return the result of the execution
809
- ```
810
-
811
- <a name="ArangoTask"></a>
812
- ## ArangoTask
813
-
814
- Tasks are managed by ArangoTask.
815
-
816
- ``` ruby
817
- myArangoTask = ArangoTask.new id: "mytaskid", name: "MyTaskID", command: "(function(params) { require('@arangodb').print(params); })(params)", params: {"foo" => "bar", "bar" => "foo"}, period: 2 # Initialize a Task Instance that will be alive for 2 seconds
818
- myArangoTask.create # Create a new Task
819
- ArangoTask.tasks # Retrieve a list of active tasks
820
- myArangoTask.retrieve # Retrieve a Task
821
- myArangoTask.destroy # Delete a Task
822
- ```
823
-
824
- <a name="ArangoCache"></a>
825
- ## ArangoCache
826
-
827
- ArangoCache helps you to manage your request to your Database by creating a cache.
828
-
829
- ``` ruby
830
- myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
831
- myQuery.execute # Heavy computation
832
- ArangoCache.cache data: myQuery # Cache these heavy query
833
- ArangoCache.uncache data: myQuery # Retrieve cached ArangoAQL with same query request
834
- ArangoCache.clear data: myQuery # Free the cache from these three documents
835
- ArangoCache.clear type: "AQL" # Delete cache from AQL requests
836
- ArangoCache.clear # Clear completely all the cache
837
- ```
838
-
839
- Alternatively we can save, retrieve and delete multiple values
840
-
841
- ``` ruby
842
- myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
843
- myQuery2 = ArangoAQL.new query: "FOR u IN Hour FILTER u._key == "2016-10-04T23" RETURN u"
844
- myQuery.execute # Heavy computation
845
- myQuery2.execute
846
- ArangoCache.cache data: [myQuery, myQuery2] # Cache these heavy query
847
- ArangoCache.uncache data: [myQuery, myQuery2] # Retrieve cached ArangoAQL
848
- ArangoCache.clear data: [myQuery, myQuery2] # Free the cache from these request
849
- ```
850
-
851
- If we need we can save with personalized ID.
852
-
853
- ``` ruby
854
- ArangoCache.cache id: ["myFirstQuery", "mySecondQuery"] data: [myQuery, myQuery2] # Cache these heavy query
855
- ArangoCache.uncache type: "AQL", id: ["myFirstQuery", "mySecondQuery"] # Retrieve cached ArangoAQL
856
- ArangoCache.clear type: "AQL", id: ["myFirstQuery", "mySecondQuery"] # Free the cache from these request
857
- ```
858
-
859
- The type and the quantity that you can save in the cache are the following: Database: 1, Collection: 20, Document: 200, Graph: 1, Vertex: 50, Edge: 100, Index: 20, AQL: 100, User: 50, Task: 20, Traversal: 20, Transaction: 20, Other: 100. For "Other" we mean all the values that are not included in the other categories.
860
-
861
- To modify these limitations you can use the following command:
862
- ``` ruby
863
- ArangoCache.max type: "Document", val: 100 # Change limits Document
864
- ```
865
- NB: If you insert a max value higher than the quantity of elements in the Cache, then the first elements in excess will be removed from the Cache.
866
-
867
- If the limit of the Cache for one type is reached, then the first element cached of that type will be deleted from the Cache.
1
+ ArangoRB [![Gem Version](https://badge.fury.io/rb/arangorb.svg)](https://badge.fury.io/rb/arangorb)
2
+ ===============================
3
+
4
+ [ArangoDatabase](https://www.arangodb.com/) is a native multi-model database with flexible data models for document, graphs, and key-values.
5
+ ArangoRB is a Gem to use ArangoDatabase with Ruby. ArangoRB is based on the [HTTP API of ArangoDB](https://docs.arangodb.com/3.0/HTTP/index.html).
6
+
7
+ ArangoRB has been tested with ArangoDatabase 3.0 on Ruby 2.3.1. It requires the gem "HTTParty"
8
+
9
+ To install ArangoRB: `gem install arangorb`
10
+
11
+ To use it in your application: `require "arangorb"`
12
+
13
+ This Gem was created from [Seluxit ApS](http://seluxit.com/).
14
+
15
+ ## Classes used
16
+
17
+ ArangoRB has the following classes.
18
+
19
+ * [ArangoServer](#ArangoServer): to manage the global variables for the management of the database
20
+ * [ArangoDatabase](#ArangoDatabase): to manage Databases
21
+ * [ArangoCollection](#ArangoCollection): to manage Collections
22
+ * [ArangoDocument](#ArangoDocument): to manage Documents
23
+ * [ArangoVertex](#ArangoVertex): to manage Vertexes
24
+ * [ArangoEdge](#ArangoEdge): to manage Edges
25
+ * [ArangoGraph](#ArangoGraph): to manage Graphs
26
+ * [ArangoTraversal](#ArangoTraversal): to manage Traversal operations
27
+ * [ArangoAQL](#arangoaql): to manage AQL instances
28
+ * [ArangoUser](#ArangoUser): to manage Users
29
+ * [ArangoIndex](#ArangoIndex): to manage Indexes
30
+ * [ArangoTask](#ArangoTask): to manage Tasks
31
+ * [ArangoTransaction](#ArangoTransaction): to manage Transactions
32
+ * [ArangoCache](#ArangoCache): to manage a cache on your Computer
33
+ * [ArangoReplication](#ArangoReplication): to manage Replications
34
+
35
+ NB: All the instances of these classes (with the exception of ArangoCache) can be transformed in Hash with the command to_h.
36
+
37
+ <a name="ArangoServer"></a>
38
+ ## ArangoServer
39
+
40
+ ArangoServer is used to manage the default Database, Collection, User and Graph.
41
+ It is used to give your login credentials and it is the mandatory step to start your database.
42
+ Further it helps to manage the Server connected with ArangoDB.
43
+
44
+ To setup your credentials use:
45
+
46
+ ``` ruby
47
+ ArangoServer.default_server user: "MyUsername", password: "MyPassword", server: "localhost", port: "8529"
48
+ ```
49
+
50
+ If not declared, the default values are user: "root", password: "", server: "localhost", port: "8529".
51
+
52
+ ### Default variables
53
+
54
+ Databases, Graphs and Collections used in your program can be defined each time. But often it is convenient to have some default one.
55
+ If this is the case, the user can use ArangoServer to define some default values.
56
+
57
+ ``` ruby
58
+ ArangoServer.database = "MyDatabase" # Setup default Database
59
+ ArangoServer.graph = "MyGraph" # Setup default Graph
60
+ ArangoServer.collection = "MyCollection" # Setup default Collection
61
+ ArangoServer.user = "MyUser" # Setup default User
62
+ ```
63
+
64
+ By default the default database is "\_system".
65
+
66
+ ### Verbose
67
+
68
+ For Debugging reasons the user can receive the original JSON file from the database by setting verbose on true (false by default).
69
+
70
+ ``` ruby
71
+ ArangoServer.verbose = true
72
+ ```
73
+
74
+ Remember that verbose is only for testing reason: to work efficiently verbose should be false.
75
+
76
+ ### Information
77
+
78
+ Basic informations can be retrieved with these command.
79
+
80
+ ``` ruby
81
+ ArangoServer.database # Check name default Database
82
+ ArangoServer.graph # Check name default Graph
83
+ ArangoServer.collection # Check name default Collection
84
+ ArangoServer.user # Check name default User
85
+ ArangoServer.address # Check address used to connect with the server
86
+ ArangoServer.username # Check name used to connect with the server
87
+ ArangoServer.verbose # Check if verbose is true or false
88
+ ArangoServer.async # Check the status of async
89
+ ArangoServer.request # Check the default request sent to the server
90
+ ```
91
+
92
+ To retrieve lists
93
+
94
+ ``` ruby
95
+ ArangoServer.endpoints # Lists of endpoints used
96
+ ArangoServer.users # Lists of available users
97
+ ArangoServer.databases # Lists of available databases
98
+ ArangoServer.tasks # Lists of available tasks
99
+ ```
100
+
101
+ To monitoring the server you can use the following commands
102
+
103
+ ``` ruby
104
+ ArangoServer.log # Return log files
105
+ ArangoServer.reload # Reloads the routing information from the collection routing.
106
+ ArangoServer.statistics # Returns the statistics information
107
+ ArangoServer.statistics description: true # Fetch descriptive info of statistics
108
+ ArangoServer.role # Get to know whether this server is a Coordinator or DB-Server
109
+ ArangoServer.serverId # Fetch this servers uniq identifier
110
+ ```
111
+
112
+ ### Manage Async
113
+
114
+ With ArangoServer you can manage Async results.
115
+
116
+ ``` ruby
117
+ ArangoServer.async = false # default
118
+ ArangoServer.async = true # fire and forget
119
+ ArangoServer.async = "store" # fire and store
120
+ ```
121
+
122
+ If Async is "store", then the commands of ArangoRB will return the id of the Async requests.
123
+ ArangoServer provides different methods to manage these Async requests.
124
+
125
+ ``` ruby
126
+ ArangoServer.pendingAsync # Querying the status of a pending job
127
+ ArangoServer.fetchAsync id: id # Fetches a job result and removes it from the queue
128
+ ArangoServer.retrieveAsync id: id # Returns the status of a specific job
129
+ ArangoServer.retrieveAsync type: type # Returns the ids of job results with a specific status
130
+ # Type can be "done" or "pending"
131
+ ArangoServer.retrieveDoneAsync # Equivalent to ArangoServer.retrieveAsync type: "done"
132
+ ArangoServer.retrievePendingAsync # Equivalent to ArangoServer.retrieveAsync type: "pending"
133
+ ArangoServer.cancelAsync id: id # Cancels an async job
134
+ ArangoServer.destroyAsync id: id # Deletes an async job result
135
+ ArangoServer.destroyAsync type: type # Deletes async jobs with a specific status
136
+ # Type can be "all" or "expired"
137
+ ArangoServer.destroyAllAsync # Equivalent to ArangoServer.destroyAsync type: "all"
138
+ ArangoServer.destroyExpiredAsync # Equivalent to ArangoServer.destroyAsync type: "expired"
139
+ ```
140
+
141
+ ### Batch
142
+
143
+ ArangoDB offers a batch request API that clients can use to send multiple operations in one batch to ArangoDB. To manage it you can use the following way.
144
+
145
+ ``` ruby
146
+ queries = [
147
+ {
148
+ "type": "POST",
149
+ "address": "/_db/MyDatabase/_api/collection",
150
+ "body": {"name": "newCOLLECTION"},
151
+ "id": "1"
152
+ },
153
+ {
154
+ "type": "GET",
155
+ "address": "/_api/database",
156
+ "id": "2"
157
+ }
158
+ ]
159
+ ArangoServer.batch queries: queries
160
+ ```
161
+
162
+ To manage these batch, ArangoServer offers the following functions:
163
+
164
+ ``` ruby
165
+ ArangoServer.createDumpBatch ttl: 10 # Create a new dump batch with 10 second time-to-live (return id of the dumpBatch)
166
+ ArangoServer.prolongDumpBatch id: idDumpBatch, ttl: 20 # Prolong the life of a batch for 20 seconds
167
+ ArangoServer.destroyDumpBatch id: idDumpBatch # Delete a selected batch
168
+ ```
169
+
170
+ ### Miscellaneous
171
+
172
+ ``` ruby
173
+ ArangoServer.version # Returns the server version number
174
+ ArangoServer.flushWAL # Flushes the write-ahead log
175
+ ArangoServer.propertyWAL # Retrieves the configuration of the write-ahead log
176
+ ArangoServer.changePropertyWAL # Configures the write-ahead log
177
+ ArangoServer.transactions # Returns information about the currently running transactions
178
+ ArangoServer.time # Get the current time of the system
179
+ ArangoServer.echo # Return current request
180
+ ArangoServer.databaseVersion # Return the required version of the database
181
+ ArangoServer.sleep duration: 10 # Sleep for a specified amount of seconds
182
+ ArangoServer.shutdown # Initiate shutdown sequence
183
+ ArangoServer.restart # Restart ArangoDB (requires administration access)
184
+ ```
185
+
186
+ UNTESTED
187
+
188
+ ``` ruby
189
+ ArangoServer.test body: body # Runs tests on server
190
+ ArangoServer.execute body: body # Execute a script on the server.
191
+ ```
192
+
193
+ ### Sharding (UNTESTED)
194
+
195
+ ArangoDB permits the sharding of the database. Although these methods has not been tested with ArangoRB.
196
+
197
+ ``` ruby
198
+ ArangoServer.cluster # Default cluster
199
+ ArangoServer.getCluster body: body, cluster: cluster # Retrieve cluster
200
+ ArangoServer.executeCluster body: body, cluster: cluster # Execute cluster
201
+ ArangoServer.executeClusterPut body: body, cluster: cluster # Execute cluster
202
+ ArangoServer.executeClusterHead body: body, cluster: cluster # Execute cluster
203
+ ArangoServer.destroyCluster cluster: cluster # Delete cluster
204
+ ArangoServer.updateCluster body: body, cluster: cluster # Update cluster
205
+ ArangoServer.checkPort port: port # Allows to check whether a given port is usable
206
+ ArangoServer.server # Returns the id of a server in a cluster.
207
+ ArangoServer.clusterStatistics dbserver: dbserver # Allows to query the statistics of a DBserver in the cluster
208
+ ```
209
+
210
+ <a name="ArangoDatabase"></a>
211
+ ## ArangoDatabase
212
+
213
+ ArangoDatabase is used to manage your Database. You can create an instance in the following way:
214
+
215
+ ``` ruby
216
+ myDatabase = ArangoDatabase.new database: "MyDatabase"
217
+ ```
218
+
219
+ Alternatively, you can use the default values provided by ArangoServer:
220
+
221
+ ``` ruby
222
+ ArangoServer.database = "MyDatabase"
223
+ myDatabase = ArangoDatabase.new
224
+ ```
225
+
226
+ ### Create and Destroy a Database
227
+
228
+ ``` ruby
229
+ myDatabase.create # Create a new Database
230
+ myDatabase.destroy # Delete the selected Database
231
+ ```
232
+
233
+ ### Retrieve information
234
+
235
+ ``` ruby
236
+ ArangoDatabase.info # Obtain general info about the databases
237
+ ArangoDatabase.databases # Obtain an Array with the available databases
238
+ myDatabase.collections # Obtain an Array with the available collections in the selected Database
239
+ myDatabase.graphs # Obtain an Array with the available graphs in the selected Database
240
+ myDatabase.functions # Obtain an Array with the available functions in the selected Database
241
+ ```
242
+
243
+ It is possible to access its Collections and Graphs by their ids.
244
+
245
+ ``` ruby
246
+ myDatabase["MyCollection"].retrieve # where "MyCollection" is the id of the collection
247
+ myDatabase.collection("MyCollection").retrieve
248
+ myDatabase.graph("MyGraph").retrieve
249
+ ```
250
+
251
+
252
+ ### Query
253
+
254
+ ArangoDatabase instances can manage the queries used in their Database.
255
+
256
+ ``` ruby
257
+ myDatabase.propertiesQuery; # See property of the Query
258
+ myDatabase.currentQuery; # Check the current Query
259
+ myDatabase.slowQuery; # Find slow queries
260
+ myDatabase.stopSlowQuery; # Stop slow queries
261
+ myDatabase.kill query: myQuery # Kill a Query
262
+ myDatabase.changePropertiesQuery maxSlowQueries: 65 # Change properties of a Query
263
+ ```
264
+
265
+ ### Cache
266
+
267
+ To manage the cache ArangoDatabase provides the following three functions.
268
+
269
+ ``` ruby
270
+ myDatabase.clearCache # Clear Cache
271
+ myDatabase.propertyCache # Check properties Cache
272
+ myDatabase.changePropertyCache maxResults: 30 # Change properties Cache
273
+ ```
274
+
275
+ ### AQL Functions
276
+
277
+ ``` ruby
278
+ myDatabase.createFunction code: "function(){return 1+1;}", name: "myFunction" # Create a new Function
279
+ myDatabase.deleteFunction name: "myFunction" # Delete a function
280
+ myDatabase.functions # Retrieve a list of the available functions
281
+ ```
282
+
283
+ ### User
284
+
285
+ You can manage the right of a user to access the database.
286
+
287
+ ``` ruby
288
+ myDatabase.grant user: myUser # Grant access to database
289
+ myDatabase.revoke user: myUser # Revoke access to database
290
+ ```
291
+
292
+ <a name="ArangoCollection"></a>
293
+ ## ArangoCollection
294
+
295
+ ArangoDatabase is used to manage your Collections. You can create an ArangoCollection instance in one of the following way:
296
+
297
+ ``` ruby
298
+ myCollection = ArangoCollection.new database: "MyDatabase", collection: "MyCollection"
299
+ myCollection = ArangoCollection.new collection: "MyCollection" # Using the default database
300
+ myCollection = ArangoCollection.new # Using the default database and collection
301
+ ```
302
+
303
+ A Collection can be of two types: "Document" and "Edge". If you want to specify it, uses:
304
+
305
+ ``` ruby
306
+ myCollectionA = ArangoCollection.new collection: "MyCollectionA", type: "Document"
307
+ myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"
308
+ ```
309
+
310
+ ### Create a Collection
311
+
312
+ `myCollection.create`
313
+
314
+ If not specified the default type of the Collection is "Document".
315
+ To create an Edge Collection you can use one of the next three options:
316
+
317
+ ``` ruby
318
+ myCollection.create_edge_collection
319
+ myCollection.create type: "Edge"
320
+ myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"; myCollectionB.create
321
+ ```
322
+
323
+ ### Destroy or Truncate a Collections
324
+
325
+ Destroy will delete the selected Collection from the Database.
326
+
327
+ `myCollection.destroy`
328
+
329
+ Truncate will delete all the Documents inside the selected Collection.
330
+
331
+ `myCollection.truncate`
332
+
333
+ ### Retrieve information
334
+
335
+ It is possible to access its Documents and its database.
336
+
337
+ ``` ruby
338
+ myCollection["MyDocument"]
339
+ myDatabase.document("MyDocument")
340
+ myDatabase.database
341
+ ```
342
+
343
+ For other information
344
+
345
+ ``` ruby
346
+ myCollection.retrieve # Retrieve the selected Collection
347
+ myCollection.indexes # Return a list of all used Indexes in the Collection
348
+ myCollection.data # Returns the whole content of one collection
349
+ myCollection.properties # Properties of the Collection
350
+ myCollection.count # Number of Documents in the Collection
351
+ myCollection.stats # Statistics of the Collection
352
+ myCollection.revision # Return collection revision id
353
+ myCollection.checksum # Return checksum for the Collection
354
+ ```
355
+
356
+ To retrieve all the documents of a Collection you can use:
357
+
358
+ ``` ruby
359
+ myCollection.documents
360
+ myCollection.allDocuments
361
+ ```
362
+
363
+ These two functions are similar except for the fact that you can assign different variables.
364
+
365
+ `myCollection.documents type: "path"`
366
+
367
+ Type can be "path", "id" or "key" in relation what we wish to have. If not specified we will receive an array of ArangoDocument instances.
368
+
369
+ `myCollection.allDocuments skip: 3, limit: 100, batchSize: 10`
370
+
371
+ It means that we skip the first three Documents, we can retrieve the next 100 Documents but we return only the first ten.
372
+
373
+ To retrieve specific Document you can use:
374
+
375
+ ``` ruby
376
+ myCollection.documentsMatch match: {"value" => 4} # All Documents of the Collection with value equal to 4
377
+ myCollection.documentMatch match: {"value" => 4} # The first Document of the Collection with value equal to 4
378
+ myCollection.documentByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array
379
+ myCollection.random # A random Document of the Collection
380
+ ```
381
+
382
+ ### Modify the Collection
383
+
384
+ ``` ruby
385
+ myCollection.load # Load the Collection
386
+ myCollection.unload # Unload the Collection
387
+ myCollection.change waitForSync: true # Change a property of the Collection
388
+ myCollection.rename "myCollectionC" # Rename the Collection
389
+ myCollection.rotate # Rotate journal of a collection
390
+ ```
391
+
392
+ ### Import and Export Documents
393
+
394
+ For the standard way to import one or more Documents (or Edges) we refer to the [dedicated ArangoDocument section](#create_doc).
395
+ However it is possible to import a huge quantity of documents in a Collection with only one requests with the command import.
396
+
397
+ <strong>Import one Document with Array</strong>
398
+ I import one document with the following structure {"value": "uno", "num": 1, "name": "ONE"}.
399
+ ``` ruby
400
+ attributes = ["value", "num", "name"]
401
+ values = ["uno",1,"ONE"]
402
+ myCollection.import attributes: attributes, values: values
403
+ ```
404
+
405
+ <strong>Import more Documents with Array</strong>
406
+ I import three Documents with the following structure {"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "TWO"}, {"value": "tre", "num": 3, "name": "THREE"}.
407
+ ``` ruby
408
+ attributes = ["value", "num", "name"]
409
+ values = [["uno",1,"ONE"],["due",2,"TWO"],["tre",3,"THREE"]]
410
+ myCollection.import attributes: attributes, values: values
411
+ ```
412
+
413
+ <strong>Import more Documents with JSON</strong>
414
+ I import two Documents with the following structure {"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "TWO"}.
415
+ ``` ruby
416
+ body = [{"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "DUE"}]
417
+ myCollection.importJSON body: body
418
+ ```
419
+
420
+ As it is possible to import files, it is possible to export all the Document of a Collection with the following command.
421
+ ``` ruby
422
+ myCollection.export
423
+ ```
424
+
425
+ Alternatively it is possible to retrieve all the Documents in a Collection gradually.
426
+
427
+ ``` ruby
428
+ myCollection.export batchSize: 3 # First three Documents of the Collection
429
+ myCollection.exportNext # Next three Documents
430
+ myCollection.exportNext # Next three Documents
431
+ ```
432
+
433
+ ### Other operations
434
+
435
+ ``` ruby
436
+ myCollection.removeByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array will be removed
437
+ myCollection.removeMatch match: {"value" => 4} # All Documents of the Collection with value equal to 4 will be removed
438
+ myCollection.replaceMatch match: {"value" => 4}, newValue: {"value" => 6} # All Documents of the Collection with value equal to 4 will be replaced with the new Value
439
+ myCollection.updateMatch match: {"value" => 4}, newValue: {"value" => 6} # All Documents of the Collection with value equal to 4 will be updated with the new Value
440
+ ```
441
+
442
+ <a name="ArangoDocument"></a>
443
+ ## ArangoDocument
444
+
445
+ An Arango Document is an element of a Collection. Edges are documents with "\_from" and "\_to" in their body.
446
+ You can create an ArangoCollection instance in one of the following way:
447
+
448
+ ``` ruby
449
+ myDocument = ArangoDocument.new database: "MyDatabase", collection: "MyCollection", key: "myKey"
450
+ myDocument = ArangoDocument.new collection: "MyCollection", key: "myKey" # Using default Database
451
+ myDocument = ArangoDocument.new key: "myKey" # Using default Collection and Database
452
+ myDocument = ArangoDocument.new # Using default Collection and Database and I don't want to define a key for my Instance
453
+ ```
454
+
455
+ In the case you want to define a Edge, it is convenient to introduce the parameters "from" and "to" in the instance.
456
+
457
+ ``` ruby
458
+ myEdge = ArangoDocument.new from: myDocA, to: myDocB
459
+ ```
460
+
461
+ where myDocA and myDocB are the IDs of two Documents or are two ArangoDocument instances.
462
+ During the instance, it is possible to define a Body for the Document.
463
+
464
+ ``` ruby
465
+ myDocument = ArangoDocument.new body: {"value" => 17}
466
+ ```
467
+
468
+ <a name="create_doc"></a>
469
+ ### Create one or more Documents
470
+
471
+ ArangoRB provides several way to create a single Document.
472
+
473
+ ``` ruby
474
+ myDocument.create
475
+ myCollection.create_document document: myDocument # myDocument is an ArangoDocument instance or a Hash
476
+ ArangoDocument.create body: {"value" => 17}, collection: myDocument
477
+ ```
478
+
479
+ Or more Documents.
480
+
481
+ ``` ruby
482
+ myCollection.create_document document: [myDocumentA, myDocumentB, {"value" => 17}] # Array of ArangoDocument instances and Hashes
483
+ ArangoDocument.create body: [myDocumentA, {"value" => 18}, {"value" => 3}], collection: myDocument # Array of ArangoDocument instances and Hash
484
+ ```
485
+
486
+ ### Create one or more Edges
487
+
488
+ ArangoRB has different way to create one or multiple edges. Here some example:
489
+
490
+ ``` ruby
491
+ myEdge = ArangoDocument.new from: myDocA, to: myDocB; myEdge.create
492
+ myEdge.create_edge from: myDocA, to: myDocB # myDocA and myDocB are ArangoDocument ids or ArangoDocument instances
493
+ myEdgeCollection.create_edge document: myEdge, from: myDocA, to: myDocB
494
+ ArangoDocument.create_edge body: {"value" => 17}, from: myDocA, to: myDocB, collection: myEdgeCollection
495
+ ```
496
+
497
+ Further we have the possibility to create different combination of Edges in only one line of code
498
+
499
+ One-to-one with one Edge class
500
+
501
+ * [myDocA] --(myEdge)--> [myDocB]
502
+
503
+ ``` ruby
504
+ myEdgeCollection.create_edge document: myEdge, from: myDocA, to: myDocB
505
+ ```
506
+
507
+ One-to-more with one Edge class (and More-to-one with one Edge class)
508
+
509
+ * [myDocA] --(myEdge)--> [myDocB]
510
+ * [myDocA] --(myEdge)--> [myDocC]
511
+
512
+ ``` ruby
513
+ myEdgeCollection.create_edge document: myEdge, from: myDocA, to: [myDocB, myDocC]
514
+ ```
515
+
516
+ More-to-More with one Edge class
517
+
518
+ * [myDocA] --(myEdge)--> [myDocC]
519
+ * [myDocB] --(myEdge)--> [myDocC]
520
+ * [myDocA] --(myEdge)--> [myDocD]
521
+ * [myDocB] --(myEdge)--> [myDocD]
522
+
523
+ ``` ruby
524
+ myEdgeCollection.create_edge document: myEdge, from: [myDocA, myDocB], to: [myDocC, myDocD]
525
+ ```
526
+
527
+ More-to-More with more Edge classes
528
+
529
+ * [myDocA] --(myEdge)--> [myDocC]
530
+ * [myDocB] --(myEdge)--> [myDocC]
531
+ * [myDocA] --(myEdge)--> [myDocD]
532
+ * [myDocB] --(myEdge)--> [myDocD]
533
+ * [myDocA] --(myEdge2)--> [myDocC]
534
+ * [myDocB] --(myEdge2)--> [myDocC]
535
+ * [myDocA] --(myEdge2)--> [myDocD]
536
+ * [myDocB] --(myEdge2)--> [myDocD]
537
+
538
+ ``` ruby
539
+ myEdgeCollection.create_edge document: [myEdge, myEdge2], from: [myDocA, myDocB], to: [myDocC, myDocD]
540
+ ```
541
+
542
+ ### Destroy a Document
543
+
544
+ ``` ruby
545
+ myDocument.destroy
546
+ ```
547
+
548
+ ### Retrieve information
549
+
550
+ ``` ruby
551
+ myDocument.retrieve # Retrieve Document
552
+ myDocument.collection # Retrieve Collection of the Document
553
+ myDocument.database # Retrieve Database of the Document
554
+ myDocument.retrieve_edges collection: myEdgeCollection # Retrieve all myEdgeCollection edges connected with the Document
555
+ myDocument.any(myEdgeCollection) # Retrieve all myEdgeCollection edges connected with the Document
556
+ myDocument.in(myEdgeCollection) # Retrieve all myEdgeCollection edges coming in the Document
557
+ myDocument.out(myEdgeCollection) # Retrieve all myEdgeCollection edges going out the Document
558
+ myEdge.from # Retrieve the document at the begin of the edge
559
+ myEdge.to # Retrieve the document at the end of the edge
560
+ ```
561
+
562
+ #### Example: how to navigate the edges
563
+
564
+ Think for example that we have the following schema:
565
+ * A --[class: a, name: aa]--> B
566
+ * A --[class: a, name: bb]--> C
567
+ * A --[class: b, name: cc]--> D
568
+ * B --[class: a, name: dd]--> E
569
+
570
+ Then we have:
571
+
572
+ * A.retrieve is A
573
+ * A.retrieve_edges(collection: a) is [aa, bb]
574
+ * B.any(a) is [aa, dd]
575
+ * B.in(a) is [aa]
576
+ * B.out(a) is [dd]
577
+ * aa.from is A
578
+ * aa.to is B
579
+
580
+ We can even do some combinations: for example A.out(a)[0].to.out(a)[0].to is E since:
581
+ * A.out(a) is [aa]
582
+ * A.out(a)[0] is aa
583
+ * A.out(a)[0].to is B
584
+ * A.out(a)[0].to.out(a) is [dd]
585
+ * A.out(a)[0].to.out(a)[0] is dd
586
+ * A.out(a)[0].to.out(a)[0].to is E
587
+
588
+ ### Modify
589
+
590
+ ``` ruby
591
+ myDocument.update body: {"value" => 3} # We update or add a value
592
+ myDocument.replace body: {"value" => 3} # We replace a value
593
+ ```
594
+
595
+ <a name="ArangoGraph"></a>
596
+ ## ArangoGraph
597
+
598
+ ArangoGraph are used to manage Graphs. You can create an ArangoGraph instance in one of the following way.
599
+
600
+ ``` ruby
601
+ myGraph = ArangoGraph.new database: "MyDatabase", graph: "MyGraph"
602
+ myGraph = ArangoGraph.new graph: "MyGraph" # By using the default Database
603
+ myGraph = ArangoGraph.new # By using the defauly Database and Graph
604
+ ```
605
+
606
+ ### Create, Retrieve and Destroy a Graph
607
+
608
+ ``` ruby
609
+ myGraph.create # create a new Graph
610
+ myGraph.retrieve # retrieve the Graph
611
+ myGraph.database # retrieve database of the Graph
612
+ myGraph.destroy # destroy the Graph
613
+ ```
614
+
615
+ ### Manage Vertex Collections
616
+
617
+ ``` ruby
618
+ myGraph.vertexCollections # Retrieve all the vertexCollections of the Graph
619
+ myGraph.addVertexCollection collection: "myCollection" # Add a Vertex Collection to our Graph
620
+ myGraph.removeVertexCollection collection: "myCollection" # Remove a Vertex Collection to our Graph
621
+ ```
622
+
623
+ ### Manage Edge Collections
624
+
625
+ ``` ruby
626
+ myGraph.edgeCollections # Retrieve all the edgeCollections of the Graph
627
+ myGraph.addEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Add an Edge Collection to our Graph
628
+ myGraph.replaceEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Replace an Edge Collection to our Graph
629
+ myGraph.removeEdgeCollections collection: "myEdgeCollection" # Remove an Edge Collection to our Graph
630
+ ```
631
+
632
+ <a name="ArangoVertex"></a><a name="ArangoEdge"></a>
633
+ ## ArangoVertex and ArangoEdge
634
+
635
+ Both these two classes inherit the class ArangoDocument.
636
+ These two classes have been created since ArangoDatabase offers, in connection of the chosen graph, different HTTP requests to manage Vertexes and Edges. We recommend the reader to read carefully the section on [ArangoDocument instances](#ArangoDocument) before to start to use ArangoVertex and ArangoEdge instances.
637
+
638
+ ### ArangoVertex methods
639
+
640
+ ArangoVertex inherit all the methods of ArangoDocument class. The following one works similar to the one of ArangoDocument Class but use different HTTP requests. For this reason the performance could be different.
641
+ To use ArangoVertex, the Collection of the Vertex needs to be added either to the VertexCollections or to the EdgeCollections of the chosen Graph.
642
+
643
+ ``` ruby
644
+ myVertex = ArangoVertex.new key: "newVertex", body: {"value" => 3}, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
645
+ myVertex.create # create a new Document in the Graph
646
+ myVertex.retrieve # retrieve a Document
647
+ myVertex.graph # Retrieve Graph of the Document
648
+ myVertex.replace body: {"value" => 6} # replace the Document
649
+ myVertex.update body: {"value" => 6} # update the Document
650
+ myVertex.destroy # delete the Document
651
+ ```
652
+
653
+ ### ArangoEdge methods
654
+
655
+ ArangoEdge inherit all the methods of ArangoDocument class. The following one works similar to the one of ArangoDocument Class but use a different HTTP request. For this reason the performance could be different.
656
+ To use ArangoEdge, the Collection of the Edge needs to be added to the EdgeCollections of the chosen Graph.
657
+
658
+ ``` ruby
659
+ myEdge = ArangoEdge.new key: "newVertex", body: {"value" => 3}, from: myArangoDocument, to: myArangoDocument, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
660
+ myEdge.create # create a new Document of type Edge in the Graph
661
+ myEdge.retrieve # retrieve a Document
662
+ myEdge.graph # Retrieve Graph of the Document
663
+ myEdge.replace body: {"value" => 6} # replace the Document
664
+ myEdge.update body: {"value" => 6} # update the Document
665
+ myEdge.destroy # delete the Document
666
+ ```
667
+
668
+ <a name="ArangoTraversal"></a>
669
+ ## ArangoTraversal
670
+
671
+ ArangoTraversal is used to administrate the traversals.
672
+ ArangoTraversal needs to know the vertex from where the traversal starts, the direction the traversal is going and either the Graph or the EdgeCollection we want to analize.
673
+
674
+ ``` ruby
675
+ myTraversal = ArangoTraversal.new # create new ArangoTraversal
676
+ myTraversal.vertex = myVertex # define starting Vertex
677
+ myTraversal.graph = myGraph # define used Graph
678
+ myTraversal.edgeCollection = myEdgeCollection # define used Edge
679
+ myTraversal.in # Direction is in
680
+ myTraversal.out # Direction is out
681
+ myTraversal.any # Direction is in and out
682
+ myTraversal.min = 1 # Define how minimum deep we want to go with the traversal
683
+ myTraversal.max = 3 # Define how maximum deep we want to go with the traversal
684
+ ```
685
+
686
+ After the traversal is setup, you can execute it:
687
+
688
+ ``` ruby
689
+ myTraversal.execute
690
+ ```
691
+
692
+ <a name="arangoaql"></a>
693
+ ## ArangoAQL - ArangoDatabase Query Language
694
+
695
+ ArangoAQL is used to manage the ArangoDB query language. To instantiate a query
696
+
697
+ ``` ruby
698
+ myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
699
+ ```
700
+
701
+ To execute it use:
702
+ ``` ruby
703
+ myQuery.execute
704
+ ```
705
+
706
+ If the query is too big, you can divide the fetching in pieces, for example:
707
+ ``` ruby
708
+ myQuery.size = 10
709
+ myQuery.execute # First 10 documents
710
+ myQuery.next # Next 10 documents
711
+ myQuery.next # Next 10 documents
712
+ ```
713
+
714
+ ### Check property query
715
+
716
+ ``` ruby
717
+ myQuery.explain # Show data query
718
+ myQuery.parse # Parse query
719
+ myQuery.properties; # Check properties
720
+ myQuery.current; # Retrieve current Query
721
+ myQuery.slow; # Retrieve slow Queries
722
+ myQuery.changeProperties maxSlowQueries: 65 # Change Properties
723
+ ```
724
+
725
+ ### Delete query
726
+
727
+ ``` ruby
728
+ myQuery.stopSlow; # Stop Slow query
729
+ myQuery.kill; # Kill Query
730
+ ```
731
+
732
+ <a name="ArangoUser"></a>
733
+ ## ArangoUser
734
+
735
+ ArangoUser manages the users.
736
+ To initialize an user:
737
+
738
+ ``` ruby
739
+ myUser = ArangoUser.new user: "MyUser", password: "password"
740
+ ```
741
+
742
+ ### User management
743
+
744
+ ``` ruby
745
+ myUser.retrieve # Retrieve User
746
+ myUser["MyDatabase"] # Retrieve database if the user can access it
747
+ myUser.create # Create a new User
748
+ myUser.replace active: false # Replace User
749
+ myUser.update active: false # Update User
750
+ myUser.destroy # Delete User
751
+ ```
752
+
753
+ ### Database management
754
+
755
+ ``` ruby
756
+ myUser.databases # Check permission Databases
757
+ myUser.grant database: "MyDatabase" # Grant access to a database
758
+ myUser.revoke database: "MyDatabase" # Revoke access to a database
759
+ ```
760
+
761
+ <a name="ArangoIndex"></a>
762
+ ## ArangoIndex
763
+
764
+ ArangoIndex manages the indexes.
765
+ To initialize an index:
766
+
767
+ ``` ruby
768
+ myIndex = ArangoIndex.new fields: "num", unique: false, id: "myIndex"
769
+ ```
770
+
771
+ ### Index management
772
+
773
+ ``` ruby
774
+ myIndex.retrieve # Retrieve Index
775
+ myIndex.create # Create a new Index
776
+ ArangoIndex.indexes collection: "MyCollection" # List indexes
777
+ myIndex.destroy # Delete Index
778
+ ```
779
+
780
+ Alternatively, you can create an Index of a Collection directly from its Collection.
781
+
782
+ ``` ruby
783
+ myCollection.createIndex unique: false, fields: "num", type: "hash"
784
+ ```
785
+
786
+ <a name="ArangoTransaction"></a>
787
+ ## ArangoTransaction
788
+
789
+ Transactions are managed by ArangoTransaction. This class has only initialization and execution.
790
+
791
+ ``` ruby
792
+ myArangoTransaction = ArangoTransaction.new action: "function(){ var db = require('@arangodb').db; db.MyCollection.save({}); return db.MyCollection.count(); }", write: myCollection # Or read
793
+ myArangoTransaction.execute # Return the result of the execution
794
+ ```
795
+
796
+ <a name="ArangoTask"></a>
797
+ ## ArangoTask
798
+
799
+ Tasks are managed by ArangoTask.
800
+
801
+ ``` ruby
802
+ myArangoTask = ArangoTask.new id: "mytaskid", name: "MyTaskID", command: "(function(params) { require('@arangodb').print(params); })(params)", params: {"foo" => "bar", "bar" => "foo"}, period: 2 # Initialize a Task Instance that will be alive for 2 seconds
803
+ myArangoTask.create # Create a new Task
804
+ ArangoTask.tasks # Retrieve a list of active tasks
805
+ myArangoTask.retrieve # Retrieve a Task
806
+ myArangoTask.destroy # Delete a Task
807
+ ```
808
+
809
+ <a name="ArangoCache"></a>
810
+ ## ArangoCache
811
+
812
+ ArangoCache helps you to manage your request to your Database by creating a cache.
813
+
814
+ ``` ruby
815
+ myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
816
+ myQuery.execute # Heavy computation
817
+ ArangoCache.cache data: myQuery # Cache these heavy query
818
+ ArangoCache.uncache data: myQuery # Retrieve cached ArangoAQL with same query request
819
+ ArangoCache.clear data: myQuery # Free the cache from these three documents
820
+ ArangoCache.clear type: "AQL" # Delete cache from AQL requests
821
+ ArangoCache.clear # Clear completely all the cache
822
+ ```
823
+
824
+ Alternatively we can save, retrieve and delete multiple values
825
+
826
+ ``` ruby
827
+ myQuery = ArangoAQL.new query: "FOR v,e,p IN 1..6 ANY 'Year/2016' GRAPH 'MyGraph' FILTER p.vertices[1].num == 6 && p.vertices[2].num == 22 && p.vertices[6]._key == '424028e5-e429-4885-b50b-007867208c71' RETURN [p.vertices[4].value, p.vertices[5].data]"
828
+ myQuery2 = ArangoAQL.new query: "FOR u IN Hour FILTER u._key == "2016-10-04T23" RETURN u"
829
+ myQuery.execute # Heavy computation
830
+ myQuery2.execute
831
+ ArangoCache.cache data: [myQuery, myQuery2] # Cache these heavy query
832
+ ArangoCache.uncache data: [myQuery, myQuery2] # Retrieve cached ArangoAQL
833
+ ArangoCache.clear data: [myQuery, myQuery2] # Free the cache from these request
834
+ ```
835
+
836
+ If we need we can save with personalized ID.
837
+
838
+ ``` ruby
839
+ ArangoCache.cache id: ["myFirstQuery", "mySecondQuery"] data: [myQuery, myQuery2] # Cache these heavy query
840
+ ArangoCache.uncache type: "AQL", id: ["myFirstQuery", "mySecondQuery"] # Retrieve cached ArangoAQL
841
+ ArangoCache.clear type: "AQL", id: ["myFirstQuery", "mySecondQuery"] # Free the cache from these request
842
+ ```
843
+
844
+ The type and the quantity that you can save in the cache are the following: Database: 1, Collection: 20, Document: 200, Graph: 1, Vertex: 50, Edge: 100, Index: 20, AQL: 100, User: 50, Task: 20, Traversal: 20, Transaction: 20, Other: 100. For "Other" we mean all the values that are not included in the other categories.
845
+
846
+ To modify these limitations you can use the following command:
847
+ ``` ruby
848
+ ArangoCache.max type: "Document", val: 100 # Change limits Document
849
+ ```
850
+ NB: If you insert a max value higher than the quantity of elements in the Cache, then the first elements in excess will be removed from the Cache.
851
+
852
+ If the limit of the Cache for one type is reached, then the first element cached of that type will be deleted from the Cache.
853
+
854
+ <a name="ArangoReplication"></a>
855
+ ## Replication
856
+
857
+ Replication is useful to create back up copy of your database or to have a master-slave relationship between two databases.
858
+
859
+ Remember: the used database is the one where the data will be written (the slave) and the remote database will be the master one.
860
+
861
+ Use with caution since the data in the slave database will be deleted.
862
+
863
+ To setup our Slave Server and Master Database use a similar command.
864
+
865
+ ``` ruby
866
+ ArangoServer.default_server user: "root", password: "tretretre", server: "172.17.8.101", port: "8529" # Our Slave Server
867
+ myReplication = ArangoReplication.new endpoint: "tcp://10.10.1.97:8529", username: "root", password: "", database: "year" # Our Master Database
868
+ ```
869
+
870
+ Than to do a simple syncronization uses;
871
+
872
+ ``` ruby
873
+ myReplication.sync
874
+ ```
875
+
876
+ To retrieve some information ArangoRB provides the following methods:
877
+
878
+ ``` ruby
879
+ myDatabase = ArangoDatabase.new database: "year"
880
+ myCollection = myDatabase["MyCollection"]
881
+ myDatabase.inventory # Fetch Collection data
882
+ myCollection.dump # Fetch all the data in one class from one tick to another
883
+ myReplication.logger # Returns the current state of the server's replication logger
884
+ myReplication.loggerFollow # Returns data from the server's replication log.
885
+ myReplication.firstTick # Return the first available tick value from the server
886
+ myReplication.rangeTick # Returns the currently available ranges of tick values for all currently available WAL logfiles.
887
+ myReplication.serverId # Returns the servers id.
888
+ ```
889
+
890
+ ### Relation Master-Slave
891
+
892
+ To enslave a Server in relation to another Database use the following command:
893
+
894
+ ``` ruby
895
+ myReplication.enslave
896
+ ```
897
+
898
+ To manage the Configuration of a Master-Slave Replication you can use the following commands:
899
+
900
+ ``` ruby
901
+ myReplication.configurationReplication # check the Configuration of the Replication
902
+ myReplication.stateReplication # check the status of the Replication
903
+ myReplication.stopReplication # stop the Replication
904
+ myReplication.modifyReplication # modify the Configuration of the Replication (you can modify only a stopped Replication)
905
+ myReplication.startReplication # restart the replication
906
+ ```