arango-driver 3.5.0.alpha0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +1073 -0
  4. data/arango_opal.js +15 -0
  5. data/lib/arango-driver.rb +61 -0
  6. data/lib/arango.rb +96 -0
  7. data/lib/arango/aql.rb +188 -0
  8. data/lib/arango/collection.rb +575 -0
  9. data/lib/arango/collection/documents.rb +122 -0
  10. data/lib/arango/collection/edges.rb +149 -0
  11. data/lib/arango/collection/importing.rb +57 -0
  12. data/lib/arango/collection/indexes.rb +53 -0
  13. data/lib/arango/collection/replication.rb +24 -0
  14. data/lib/arango/collection/user.rb +28 -0
  15. data/lib/arango/cursor.rb +67 -0
  16. data/lib/arango/database.rb +188 -0
  17. data/lib/arango/database/analyzer.rb +21 -0
  18. data/lib/arango/database/aql_functions.rb +54 -0
  19. data/lib/arango/database/aql_queries.rb +114 -0
  20. data/lib/arango/database/aql_query_cache.rb +27 -0
  21. data/lib/arango/database/collections.rb +100 -0
  22. data/lib/arango/database/foxx_services.rb +103 -0
  23. data/lib/arango/database/graph_access.rb +27 -0
  24. data/lib/arango/database/http_route.rb +9 -0
  25. data/lib/arango/database/replication.rb +96 -0
  26. data/lib/arango/database/stream_transactions.rb +25 -0
  27. data/lib/arango/database/tasks.rb +67 -0
  28. data/lib/arango/database/transactions.rb +15 -0
  29. data/lib/arango/database/user.rb +26 -0
  30. data/lib/arango/database/view_access.rb +37 -0
  31. data/lib/arango/document.rb +443 -0
  32. data/lib/arango/edge.rb +164 -0
  33. data/lib/arango/error.rb +97 -0
  34. data/lib/arango/error_db.rb +27 -0
  35. data/lib/arango/foxx.rb +255 -0
  36. data/lib/arango/graph.rb +202 -0
  37. data/lib/arango/graph/basics.rb +39 -0
  38. data/lib/arango/graph/edge_access.rb +56 -0
  39. data/lib/arango/graph/vertex_access.rb +33 -0
  40. data/lib/arango/helper/collection_assignment.rb +13 -0
  41. data/lib/arango/helper/database_assignment.rb +14 -0
  42. data/lib/arango/helper/request_method.rb +45 -0
  43. data/lib/arango/helper/return.rb +21 -0
  44. data/lib/arango/helper/satisfaction.rb +28 -0
  45. data/lib/arango/helper/server_assignment.rb +13 -0
  46. data/lib/arango/helper/traversal.rb +12 -0
  47. data/lib/arango/index.rb +103 -0
  48. data/lib/arango/replication.rb +231 -0
  49. data/lib/arango/request.rb +92 -0
  50. data/lib/arango/request_batch.rb +174 -0
  51. data/lib/arango/result.rb +130 -0
  52. data/lib/arango/search_view.rb +23 -0
  53. data/lib/arango/server.rb +68 -0
  54. data/lib/arango/server/administration.rb +296 -0
  55. data/lib/arango/server/agency.rb +23 -0
  56. data/lib/arango/server/async.rb +51 -0
  57. data/lib/arango/server/batch.rb +35 -0
  58. data/lib/arango/server/config.rb +76 -0
  59. data/lib/arango/server/databases.rb +71 -0
  60. data/lib/arango/server/monitoring.rb +17 -0
  61. data/lib/arango/server/opal_support.rb +95 -0
  62. data/lib/arango/server/tasks.rb +69 -0
  63. data/lib/arango/server/user.rb +22 -0
  64. data/lib/arango/task.rb +223 -0
  65. data/lib/arango/transaction.rb +113 -0
  66. data/lib/arango/traversal.rb +212 -0
  67. data/lib/arango/user.rb +174 -0
  68. data/lib/arango/version.rb +3 -0
  69. data/lib/arango/vertex.rb +112 -0
  70. data/lib/arango/view.rb +124 -0
  71. data/lib/arango/view/basics.rb +25 -0
  72. metadata +296 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71f45497861998bdeb1e5a62f1611d361aa7464f8d25ce4b5ba78cbb9f09135e
4
+ data.tar.gz: 934fec400892dde00847b3ae128d57e999e2aed37f7848840fc265391a84d900
5
+ SHA512:
6
+ metadata.gz: f35bbabeb4fb047fd9c321aab7dec7b1a9b17a576d5e453171b79c88283bccb32c3613f89159c2139e8d76ab92e46f5f502f2982e61180716e386646a566c5c8
7
+ data.tar.gz: b567233189af91068e386b25460b5775cb2ae698f06eb6caa0d7ecfc0b36111c0263a2993c80cd211dde1b02ad5975b4687cf7c6643ea01050138c705889757c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 StefanoMartin, 2019 Jan Biedermann
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.
@@ -0,0 +1,1073 @@
1
+ arango-driver
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
+ arango-driver is a Gem to use ArangoDB with Ruby. arango-driver is based on the [HTTP API of ArangoDB](https://docs.arangodb.com/3.5/HTTP/index.html)
6
+ and its [Error Codes](https://www.arangodb.com/docs/3.5/appendix-error-codes.html).
7
+
8
+ The version of arango-driver follows the ArangoDB version, version 3.5.x of the driver is meant to be used with ArangoDB 3.5.y, where x and y may differ.
9
+
10
+ This doesnt work yet, gem not published yet:
11
+ To install arango-driver: `gem install arango-driver`
12
+ To use it in your application: `require "arango-driver"`
13
+ Please install from the repo instead.
14
+
15
+ ## Community and Support
16
+ At the [Isomorfeus Framework Project](http://isomorfeus.com). There is a #arango_driver channel at the isomorfeus Slack space.
17
+
18
+ # This is currently WIP, the information below is mostly obsolete. See spec/*_spec.rb files for currently supported things and usage.
19
+
20
+ ## Classes used
21
+
22
+ arango-driver has the two type of classes.
23
+
24
+ Classes relative to ArangoDB elements:
25
+ * [Arango::Server](#ArangoServer): to manage a Server
26
+ * [Arango::Database](#ArangoDatabase): to manage a Database
27
+ * [Arango::Collection](#ArangoCollection): to manage a Collection
28
+ * [Arango::Document](#ArangoDocument): to manage a Document
29
+ * [Arango::Vertex](#ArangoVertex): to manage a Vertex
30
+ * [Arango::Edge](#ArangoEdge): to manage an Edge
31
+ * [Arango::Graph](#ArangoGraph): to manage a Graph
32
+ * [Arango::Traversal](#ArangoTraversal): to manage a Traversal operation
33
+ * [Arango::AQL](#arangoaql): to manage an AQL instances
34
+ * [Arango::User](#ArangoUser): to manage an User
35
+ * [Arango::Index](#ArangoIndex): to manage an Index
36
+ * [Arango::Task](#ArangoTask): to manage a Task
37
+ * [Arango::Transaction](#ArangoTransaction): to manage a Transaction
38
+ * [Arango::Replication](#ArangoReplication): to manage a Replication
39
+ * [Arango::Batch](#ArangoBatch): to manage a Batch of multiple requests
40
+ * [Arango::Foxx](#ArangoFoxx): to manage a Foxx instance
41
+ * [Arango::View](#ArangoView): to manage a View instance
42
+
43
+ Classes relative to the Gem arango-driver
44
+ * [Arango::Cache](#ArangoCache): to manage internal Cache
45
+ * [Arango::Error](#ArangoError): to handle arango-driver errors
46
+
47
+ All the instances of these classes can be transformed in Hash with the method to_h.
48
+
49
+ Many methods can have multiple attributes not mentioned in this documentation. Keep in mind that if an attribute is defined in the ArangoDB documentation, then it is easy that it is an attribute for the relative method too.
50
+ Please refer to the ArangoDB documentation, the rubydoc documentation or open an issue for this missing attributes.
51
+
52
+ <a name="ArangoServer"></a>
53
+ ## Arango::Server
54
+
55
+ Arango::Server is used to manage a single server by managing the connection with ArangoDB.
56
+ You can provide your login credentials and it is a mandatory step to start your database.
57
+
58
+ To setup a server use the following way:
59
+
60
+ ``` ruby
61
+ server = Arango::Server.new username: "MyUsername", password: "MyPassword",
62
+ server: "localhost", port: "8529", tls: false
63
+ server.username = "MyOtherUsername" # Default "root"
64
+ server.password = "other_password"
65
+ server.server = "127.0.0.1" # Default "localhost"
66
+ server.port = "8765" # Default "8529"
67
+ server.tls = true # Default false, to do https requests instead of http
68
+ ```
69
+
70
+ Password is a mandatory field.
71
+
72
+ ### Returning results
73
+
74
+ arango-driver try always to store the information obtained from ArangoDB in an instance.
75
+ If you need to receive the output, you can return it with:
76
+
77
+ ``` ruby
78
+ server.return_output = true # Default false
79
+ ```
80
+
81
+ ### Verbose and warnings
82
+
83
+ For Debugging reasons the user can print out the request and response to ArangoDB by setting verbose to true.
84
+
85
+ ``` ruby
86
+ server.verbose = true # Default false
87
+ ```
88
+
89
+ Remember that verbose is only for testing reason: to work efficiently verbose should be false.
90
+
91
+ Some deprecated methods will return a warning. To silence these warnings use:
92
+
93
+ ``` ruby
94
+ server.warning = false # Default true
95
+ ```
96
+
97
+ ### Connection Pool
98
+
99
+ arango-driver supports connection pool, to activate it you can setup pool to true during the initialization or the proceedings. To do so use:
100
+
101
+ ``` ruby
102
+ server = Arango::Server.new username: "MyUsername", password: "MyPassword",
103
+ server: "localhost", port: "8529", pool: true, size: 5, timeout: 5, tls: false
104
+ server.pool = true # Defult false
105
+ server.size = 7 # Default 5
106
+ server.timeout = 10 # Default 5
107
+ server.restartPool # Restart pool with new size and timeout
108
+ ```
109
+
110
+ NB: ConnectionPool is not heavily tested.
111
+
112
+ ### Cache
113
+
114
+ Often arango-driver returns multiple time the same object (for example for lists or for retrieving). It can happens thus that a document instance updated somewhere in your code, it is not update somewhere even if you are refering the same ArangoDB document.
115
+ To avoid this, arango-driver provides its own cache.
116
+
117
+ You can activate the arango-driver cache by using:
118
+
119
+ ``` ruby
120
+ server.active_cache = true # Default false
121
+ ```
122
+
123
+ If active_cache is true, then a previous document or collection instance will be stored in the arango-driver cache. In case a new instance of the same document is created, then a new instance will NOT be created but, instead, the old one will be returned.
124
+
125
+ With an example:
126
+
127
+ ``` ruby
128
+ server.active_cache = false
129
+ a = Arango::Document.new name: "test", collection: my_collection
130
+ b = Arango::Document.new name: "test", collection: my_collection
131
+ # In this case a and b are two different instances
132
+ ```
133
+
134
+ ``` ruby
135
+ server.active_cache = true
136
+ a = Arango::Document.new name: "test", collection: my_collection
137
+ b = Arango::Document.new name: "test", collection: my_collection
138
+ # In this case a and b are the same instance
139
+ ```
140
+
141
+ Note that if you set server.active_cache to false, then the stored Cache will be emptied.
142
+ For more information about the cache, look at the section about [Arango::Cache](#ArangoCache).
143
+
144
+ ### Information
145
+
146
+ Basic information can be retrieved with these command.
147
+
148
+ ``` ruby
149
+ server.to_h # Return an hash of the instances
150
+ server.endpoint # Check address used to connect with the server
151
+ server.username # Check name used to connect with the server
152
+ server.verbose # Check if verbose is true or false
153
+ server.async # Check the status of async
154
+ ```
155
+
156
+ To retrieve lists
157
+
158
+ ``` ruby
159
+ server.databases # Lists of available databases
160
+ server.endpoints # Lists of endpoints used
161
+ server.users # Lists of available users
162
+ server.tasks # Lists of available tasks
163
+ ```
164
+
165
+ To monitoring the server you can use the following commands
166
+
167
+ ``` ruby
168
+ server.log # Return log files
169
+ server.loglevel
170
+ server.updateLoglevel body: body
171
+ server.available? # Reloads the routing information from the collection routing.
172
+ server.reload # Reloads the routing information from the collection routing.
173
+ server.statistics # Returns the statistics information
174
+ server.statisticsDescription # Fetch descriptive info of statistics
175
+ server.status # Status of the server
176
+ server.role # Get to know whether this server is a Coordinator or DB-Server
177
+ server.serverData # Get server data
178
+ server.mode # Get server mode
179
+ server.updateMode(mode: "default") # Change mode of the server
180
+ ```
181
+
182
+ ### Manage Async
183
+
184
+ With Arango::Server you can manage Async results. It can be useful to use async for heavy requests (like the one in example/year.rb).
185
+
186
+ ``` ruby
187
+ server.async = false # default
188
+ server.async = true # fire and forget
189
+ server.async = :store # fire and store
190
+ ```
191
+
192
+ If Async is "store", then the commands of arango-driver will return the id of the Async requests.
193
+ Arango::Server provides different methods to manage these Async requests.
194
+
195
+ ``` ruby
196
+ server.fetchAsync id: id # Fetches a job result and removes it from the queue
197
+ server.cancelAsync id: id # Cancels an async job
198
+ server.destroyAsync id: id # Deletes an async job result
199
+ server.retrieveAsync id: id # Returns the status of a specific job
200
+ server.retrieveAsyncByType type: type # Returns the ids of job results with a specific
201
+ # status. Type can be "done" or "pending"
202
+ server.retrieveDoneAsync # Equivalent to server.retrieveAsync type: "done"
203
+ server.retrievePendingAsync # Equivalent to server.retrieveAsync type: "pending"
204
+ server.destroyAsync type: type # Deletes async jobs with a specific status
205
+ # Type can be "all" or "expired"
206
+ server.destroyAllAsync # Equivalent to server.destroyAsync type: "all"
207
+ server.destroyExpiredAsync # Equivalent to server.destroyAsync type: "expired"
208
+ ```
209
+
210
+ ### Miscellaneous
211
+
212
+ ``` ruby
213
+ server.version # Returns the server version number
214
+ server.engine # Returns the server engine
215
+ server.flushWAL # Flushes the write-ahead log
216
+ server.propertyWAL # Retrieves the configuration of the write-ahead log
217
+ server.changePropertyWAL # Configures the write-ahead log
218
+ server.transactions # Returns information about the currently running transactions
219
+ server.time # Get the current time of the system
220
+ server.echo # Return current request
221
+ server.databaseVersion # Return the required version of the database
222
+ server.shutdown # Initiate shutdown sequence
223
+ ```
224
+
225
+ UNTESTED
226
+
227
+ ``` ruby
228
+ server.test body: body # Runs tests on server
229
+ server.execute body: body # Execute a script on the server.
230
+ ```
231
+
232
+ ### Cluster (UNTESTED)
233
+
234
+ ArangoDB permits the sharding of the database. Although these methods has not been tested with arango-driver.
235
+
236
+ ``` ruby
237
+ server.clusterHealth port: port # Allows to check whether a given port is usable
238
+ server.serverId # Returns the id of a server in a cluster.
239
+ server.clusterStatistics dbserver: dbserver # Allows to query the statistics of a
240
+ # DBserver in the cluster
241
+ ```
242
+
243
+ <a name="ArangoDatabase"></a>
244
+ ## Arango::Database
245
+
246
+ Arango::Database is used to manage a Database. You can create an instance in one of the following ways:
247
+
248
+ ``` ruby
249
+ myDatabase = server.database name: "MyDatabase"
250
+ myDatabase = server["MyDatabase"]
251
+ myDatabase = Arango::Database.new database: "MyDatabase", server: server
252
+ ```
253
+
254
+ ### Main methods
255
+
256
+ ``` ruby
257
+ myDatabase.create # Create a new Database
258
+ myDatabase.retrieve # Retrieve database
259
+ myDatabase.destroy # Delete the selected Database
260
+ ```
261
+
262
+ ### Retrieve information
263
+
264
+ ``` ruby
265
+ server.databases # Obtain an Array with the available databases in the server
266
+ myDatabase.to_h # Hash of the instance
267
+ myDatabase.info # Obtain general info about the databases
268
+ myDatabase.sever # Return the server connected with the database
269
+ myDatabase.collections # Obtain an Array with the available collections in the selected Database
270
+ myDatabase.graphs # Obtain an Array with the available graphs in the selected Database
271
+ myDatabase.aqlFunctions # Obtain an Array with the available functions in the selected Database
272
+ myDatabase.foxxes # Return all the foxx available in the database
273
+ myDatabase.views # Return all the views available in the database
274
+ myDatabase.tasks # Return all the tasks available in the database
275
+ ```
276
+
277
+ <a name="arangoaql"></a>
278
+ ## Arango::AQL
279
+
280
+ An AQL instance can be created by using one of the following way:
281
+
282
+ ``` ruby
283
+ 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]"
284
+ myQuery = myDatabase.aql query: query
285
+ myQuery = ArangoAQL.new database: myDatabase, query: query
286
+ ```
287
+
288
+ To execute it use:
289
+
290
+ ``` ruby
291
+ myQuery.execute
292
+ ```
293
+
294
+ If the query is too big, you can divide the fetching in pieces, for example:
295
+
296
+ ``` ruby
297
+ myQuery.size = 10
298
+ myQuery.execute # First 10 documents
299
+ myQuery.next # Next 10 documents
300
+ myQuery.next # Next 10 documents
301
+ ```
302
+
303
+ Other useful methods are the following
304
+
305
+ ``` ruby
306
+ myQuery.destroy # Destroy cursor to retrieve documents
307
+ myQuery.kill # Kill query request (if requires too much time)
308
+ myQuery.explain # Show data query
309
+ myQuery.parse # Parse query
310
+ ```
311
+
312
+ ### Query Properties
313
+
314
+ It is possible to handle generic properties of query by Arango::Database.
315
+
316
+ ``` ruby
317
+ myQuery.to_h # Return an hash version of the instance
318
+ myQuery.properties # Check Query properties
319
+ myQuery.current # Retrieve current running Query
320
+ myQuery.changeProperties maxSlowQueries: 65 # Change Properties
321
+ myQuery.slow # Retrieve slow Queries
322
+ myQuery.stopSlowQueries # Stop slow Queries
323
+ ```
324
+
325
+ The cache of the query can handle in the following way:
326
+
327
+ ``` ruby
328
+ myDatabase.retrieveQueryCache # Retrieve Query Cache
329
+ myDatabase.clearQueryCache # Clear Query Cache
330
+ myDatabase.propertyQueryCache # Check properties Cache
331
+ myDatabase.changePropertyQueryCache maxResults: 30 # Change properties Cache
332
+ ```
333
+
334
+ ### AQL Functions
335
+
336
+ AQL queries can be potentiate by providing javascript function as supports.
337
+
338
+ ``` ruby
339
+ myDatabase.createAqlFunction code: "function(){return 1+1;}", name: "myFunction" # Create a new AQL Function
340
+ myDatabase.deleteFunction name: "myFunction" # Delete an AQL function
341
+ myDatabase.aqlFunctions # Retrieve a list of the available aql functions
342
+ ```
343
+
344
+ <a name="ArangoCollection"></a>
345
+ ## Arango::Collection
346
+
347
+ Arango::Collection is used to manage your Collections. You can create an Arango::Collection instance in one of the following way:
348
+
349
+ ``` ruby
350
+ myCollection = myDatabase.collection name: "MyCollection"
351
+ myCollection = myDatabase["MyCollection"]
352
+ myCollection = Arango::Collection.new database: myDatabase, collection: "MyCollection"
353
+ ```
354
+
355
+ A Collection can be of two types: "Document" and "Edge". If you want to specify it, uses:
356
+
357
+ ``` ruby
358
+ myCollectionA = ArangoCollection.new collection: "MyCollectionA", type: :document # Default
359
+ myEdgeCollection = ArangoCollection.new collection: "MyCollectionB", type: :edge
360
+ ```
361
+
362
+ ### Main methods
363
+
364
+ ``` ruby
365
+ myCollection.create # Create collection
366
+ myCollection.destroy # Delete collection from database
367
+ myCollection.truncate # Delete all the Documents inside the selected Collection
368
+ myCollection.retrieve # Retrieve the selected Collection
369
+ ```
370
+
371
+ ### Info methods
372
+
373
+ ``` ruby
374
+ myCollection.database # Return database of the collection
375
+ myCollection.server # Returm server of the collection
376
+ myCollection.indexes # Return a list of all used Indexes in the Collection
377
+ myCollection.rotate # Rotate the collection
378
+ myCollection.data # Returns the whole content of one collection
379
+ myCollection.properties # Properties of the Collection
380
+ myCollection.count # Number of Documents in the Collection
381
+ myCollection.stats # Statistics of the Collection
382
+ myCollection.revision # Return collection revision id
383
+ myCollection.checksum # Return checksum for the Collection
384
+ ```
385
+
386
+ ### Modify the Collection
387
+
388
+ ``` ruby
389
+ myCollection.load # Load the collection (preparing for retrieving documents)
390
+ myCollection.unload # Unload the collection (if you stop to work with it)
391
+ myCollection.loadIndexesIntoMemory # Load indexes in memory
392
+ myCollection.change(waitForSync: true) # Change some properties
393
+ myCollection.rename(newName: "myCollection2") # Change name (NB: This is not Arango::Cache compatible)
394
+ myCollection.rotate # Rotate journal of a collection
395
+ ```
396
+
397
+ ### Handle documents
398
+
399
+ To retrieve all the documents of a Collection you can use:
400
+
401
+ ``` ruby
402
+ myCollection.documents
403
+ myCollection.allDocuments
404
+ ```
405
+
406
+ These two functions are similar except for the fact that you can assign different variables.
407
+
408
+ ``` ruby
409
+ myCollection.documents type: "path"
410
+ myCollection.next # Retrieve other documents if the first request is not finished
411
+ ```
412
+
413
+ Type can be "path", "id" or "key" in relation what we wish to have. If not specified arango-driver will return an array of Arango::Document instances.
414
+
415
+ ``` ruby
416
+ myCollection.allDocuments skip: 3, limit: 100, batchSize: 10
417
+ ```
418
+
419
+ It means that we skip the first three Documents, we can retrieve the next 100 Documents but we return only the first ten.
420
+
421
+ To retrieve specific Document you can use:
422
+
423
+ ``` ruby
424
+ myCollection.documentsMatch match: {value: 4} # All Documents of the Collection with value equal to 4
425
+ myCollection.documentMatch match: {value: 4} # The first Document of the Collection with value equal to 4
426
+ myCollection.documentByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array
427
+ myCollection.documentByName names: ["4546", "4646"] # Documents of the Collection with the name in the Array
428
+ myCollection.random # A random Document of the Collection
429
+ ```
430
+
431
+ #### Modifying multiple documents
432
+
433
+ From a collection is it possible to create, remove and modify multiple documents.
434
+
435
+ ``` ruby
436
+ myCollection.createDocuments document: [myDocumentA, myDocumentB, {value: 17}] # Array of Arango::Document instances and Hashes
437
+ myCollection.removeByKeys keys: ["4546", "4646"] # Documents of the Collection with the keys in the Array will be removed
438
+ myCollection.removeMatch match: {value: 4} # All Documents of the Collection with value equal to 4 will be removed
439
+ 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
440
+ 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
441
+ ```
442
+
443
+ #### Create multiple Edges at once
444
+
445
+ We have the possibility to create different combination of Edges in only one line of code.
446
+
447
+ One-to-one with one Edge class
448
+
449
+ * [myDocA] --(myEdge)--> [myDocB]
450
+
451
+ ``` ruby
452
+ myEdgeCollection.createEdges document: myEdge, from: myDocA, to: myDocB
453
+ ```
454
+
455
+ One-to-more with one Edge class (and More-to-one with one Edge class)
456
+
457
+ * [myDocA] --(myEdge)--> [myDocB]
458
+ * [myDocA] --(myEdge)--> [myDocC]
459
+
460
+ ``` ruby
461
+ myEdgeCollection.createEdges document: myEdge, from: myDocA, to: [myDocB, myDocC]
462
+ ```
463
+
464
+ More-to-More with one Edge class
465
+
466
+ * [myDocA] --(myEdge)--> [myDocC]
467
+ * [myDocB] --(myEdge)--> [myDocC]
468
+ * [myDocA] --(myEdge)--> [myDocD]
469
+ * [myDocB] --(myEdge)--> [myDocD]
470
+
471
+ ``` ruby
472
+ myEdgeCollection.createEdges document: myEdge, from: [myDocA, myDocB], to: [myDocC, myDocD]
473
+ ```
474
+
475
+ More-to-More with more Edge classes
476
+
477
+ * [myDocA] --(myEdge)--> [myDocC]
478
+ * [myDocB] --(myEdge)--> [myDocC]
479
+ * [myDocA] --(myEdge)--> [myDocD]
480
+ * [myDocB] --(myEdge)--> [myDocD]
481
+ * [myDocA] --(myEdge2)--> [myDocC]
482
+ * [myDocB] --(myEdge2)--> [myDocC]
483
+ * [myDocA] --(myEdge2)--> [myDocD]
484
+ * [myDocB] --(myEdge2)--> [myDocD]
485
+
486
+ ``` ruby
487
+ myEdgeCollection.createEdges document: [myEdge, myEdge2], from: [myDocA, myDocB], to: [myDocC, myDocD]
488
+ ```
489
+
490
+
491
+ ### Import and Export Documents
492
+
493
+ Another way to create multiple documents in a Collection with only one request is by using the method import.
494
+
495
+ #### Import one Document with Array
496
+
497
+ We can import one document with the following structure {value: "uno", num: 1, name: "ONE"}.
498
+
499
+ ``` ruby
500
+ attributes = ["value", "num", "name"]
501
+ values = ["uno",1,"ONE"]
502
+ myCollection.import attributes: attributes, values: values
503
+ ```
504
+
505
+ #### Import more Documents with Array
506
+
507
+ We can 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"}.
508
+
509
+ ``` ruby
510
+ attributes = ["value", "num", "name"]
511
+ values = [["uno",1,"ONE"],["due",2,"TWO"],["tre",3,"THREE"]]
512
+ myCollection.import attributes: attributes, values: values
513
+ ```
514
+
515
+ #### Import more Documents with JSON
516
+
517
+ I import two Documents with the following structure {value: "uno", num: 1, name: "ONE"}, {value: "due", num: 2, name: "TWO"}.
518
+
519
+ ``` ruby
520
+ body = [{value: "uno", num: 1, name: "ONE"}, {value: "due", num: 2, name: "DUE"}]
521
+ myCollection.importJSON body: body
522
+ ```
523
+
524
+ #### Export files
525
+
526
+ As it is possible to import files, it is possible to export all the Document of a Collection with the following command.
527
+
528
+ ``` ruby
529
+ myCollection.export
530
+ ```
531
+
532
+ Alternatively it is possible to retrieve all the Documents in a Collection gradually.
533
+
534
+ ``` ruby
535
+ myCollection.export batchSize: 3 # First three Documents of the Collection
536
+ myCollection.exportNext # Next three Documents
537
+ myCollection.exportNext # Next three Documents
538
+ ```
539
+
540
+ <a name="ArangoDocument"></a>
541
+ ## Arango::Document
542
+
543
+ An Arango::Document is an element of a Arango::Collection. Edges are Arango documents with "\_from" and "\_to" in their body.
544
+ You can create an ArangoCollection instance in one of the following way:
545
+
546
+ ``` ruby
547
+ myDocument = myCollection.document name: "MyDocument"
548
+ myDocument = myCollection["MyDocument"]
549
+ myDocument = Arango::Document.new collection: myCollection, name: "MyDocument"
550
+ ```
551
+
552
+ In the case you want to define a Edge, it is convenient to introduce the parameters "from" and "to" in the instance.
553
+
554
+ ``` ruby
555
+ myEdge = Arango::Document.new name: "MyEdge", from: myDocA, to: myDocB
556
+ ```
557
+
558
+ where myDocA and myDocB are the IDs of two Documents or are two Arango::Document instances.
559
+
560
+ During the creation of an Arango::Document instance, it is possible to define the body for the Document.
561
+
562
+ ``` ruby
563
+ myDocument = Arango::Document.new body: {value: 17}, name: "MyDocument"
564
+ ```
565
+
566
+ ### Main methods
567
+
568
+ arango-driver provides several way to create a single Document.
569
+
570
+ ``` ruby
571
+ myDocument.create # Create a new document
572
+ myDocument.retrieve # Retrieve Document
573
+ myDocument.update body: {value: 3} # We update or add a value
574
+ myDocument.replace body: {value: 3} # We replace a value
575
+ myDocument.destroy # Destroy document
576
+ ```
577
+
578
+ ### Retrieve information
579
+
580
+ ``` ruby
581
+ myDocument.collection # Retrieve Collection of the Document
582
+ myDocument.database # Retrieve Database of the Document
583
+ myDocument.server # Retrieve Server of the Document
584
+ myDocument.edges collection: myEdgeCollection # Retrieve all myEdgeCollection edges connected with the Document
585
+ myDocument.any(myEdgeCollection) # Retrieve all myEdgeCollection edges connected with the Document
586
+ myDocument.in(myEdgeCollection) # Retrieve all myEdgeCollection edges coming in the Document
587
+ myDocument.out(myEdgeCollection) # Retrieve all myEdgeCollection edges going out the Document
588
+ myEdge.from # Retrieve the document at the begin of the edge
589
+ myEdge.to # Retrieve the document at the end of the edge
590
+ ```
591
+
592
+ #### Example: how to navigate the edges
593
+
594
+ It is possible to navigate between edges and vertexes of a graph database.
595
+
596
+ Think for example that we have the following schema:
597
+ * A --[class: a, name: aa]--> B
598
+ * A --[class: a, name: bb]--> C
599
+ * A --[class: b, name: cc]--> D
600
+ * B --[class: a, name: dd]--> E
601
+
602
+ Then we have:
603
+
604
+ * A.retrieve is A
605
+ * A.edges(collection: a) is [aa, bb]
606
+ * B.in(a) is [aa]
607
+ * B.out(a) is [dd]
608
+ * B.any(a) is [aa, dd] (aa in entry, dd in exit)
609
+ * aa.from is A
610
+ * aa.to is B
611
+
612
+ We can even do some combinations: for example A.out(a)[0].to.out(a)[0].to is E since:
613
+ * A.out(a) is [aa]
614
+ * A.out(a)[0] is aa
615
+ * A.out(a)[0].to is B
616
+ * A.out(a)[0].to.out(a) is [dd]
617
+ * A.out(a)[0].to.out(a)[0] is dd
618
+ * A.out(a)[0].to.out(a)[0].to is E
619
+
620
+ <a name="ArangoGraph"></a>
621
+ ## Arango::Graph
622
+
623
+ ArangoGraph are used to manage Graphs. You can create an Arango::Graph instance in one of the following way.
624
+
625
+ ``` ruby
626
+ myGraph = myDatabase.graph name: "MyGraph"
627
+ myGraph = Arango::Graph.new name: "MyGraph", database: myDatabase
628
+ ```
629
+
630
+ ### Main methods
631
+
632
+ ``` ruby
633
+ myGraph.create # create a new Graph
634
+ myGraph.retrieve # retrieve the Graph
635
+ myGraph.database # retrieve database of the Graph
636
+ myGraph.destroy # destroy the Graph
637
+ ```
638
+
639
+ ### Manage Vertex Collections
640
+
641
+ ``` ruby
642
+ myGraph.getVertexCollections # Retrieve all the vertexCollections of the Graph
643
+ myGraph.addVertexCollection collection: "myCollection" # Add a Vertex Collection to our Graph
644
+ myGraph.removeVertexCollection collection: "myCollection" # Remove a Vertex Collection to our Graph
645
+ ```
646
+
647
+ ### Manage Edge Collections
648
+
649
+ ``` ruby
650
+ myGraph.edgeCollections # Retrieve all the edgeCollections of the Graph
651
+ myGraph.addEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Add an Edge Collection to our Graph
652
+ myGraph.replaceEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Replace an Edge Collection to our Graph
653
+ myGraph.removeEdgeCollections collection: "myEdgeCollection" # Remove an Edge Collection to our Graph
654
+ ```
655
+
656
+ <a name="ArangoVertex"></a>
657
+ <a name="ArangoEdge"></a>
658
+ ## Arango::Vertex and Arango::Edge
659
+
660
+ Both these two classes inherit the class Arango::Document.
661
+ These two classes have been created since Arango::Database 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 [Arango::Document instances](#ArangoDocument) before to start to use Arango::Vertex and Arango::Edge instances.
662
+
663
+ ### Arango::Vertex methods
664
+
665
+ Arango::Vertex inherit all the methods of Arango::Document class. The following one works similar to the one of Arango::Document Class but use different HTTP requests. For this reason the performance could be different.
666
+ To use Arango::Vertex, the Collection of the Vertex needs to be added either to the VertexCollections or to the EdgeCollections of the chosen Graph. And the Collection needs to have assigned the graph.
667
+
668
+ ``` ruby
669
+ myCollection.graph = myGraph # Be sure that the collection is assigned to a Graph
670
+ myVertex = myCollection.vertex name: "newVertex", body: {value: 3} # If graph is not assigned, an Arango::Document will be created
671
+ myVertex = Arango::Vertex.new name: "newVertex", body: {value: 3},
672
+ collection: myCollection # create a new instance
673
+ ```
674
+
675
+ ``` ruby
676
+ myVertex.create # create a new Document in the Graph
677
+ myVertex.retrieve # retrieve a Document
678
+ myVertex.graph # retrieve Graph of the Document
679
+ myVertex.replace body: {value: 6} # replace the Document
680
+ myVertex.update body: {value: 6} # update the Document
681
+ myVertex.destroy # delete the Document
682
+ ```
683
+
684
+ ### Arango::Edge methods
685
+
686
+ Arango::Edge inherit all the methods of Arango::Document class. The following one works similar to the one of Arango::Document Class but use a different HTTP request. For this reason the performance could be different.
687
+ To use Arango::Edge, the Collection of the Edge needs to be added to the EdgeCollections of the chosen Graph.
688
+
689
+ ``` ruby
690
+ myEdgeCollection.graph = myGraph
691
+ myEdge = myCollection.edge name: "newEdge", body: {value: 3}, from: myArangoDocument1, to: myArangoDocument2 # If graph is not assigned, an Arango::Document will be created
692
+ ```
693
+
694
+ ``` ruby
695
+ myEdge.create # create a new Document of type Edge in the Graph
696
+ myEdge.retrieve # retrieve a Document
697
+ myEdge.graph # Retrieve Graph of the Document
698
+ myEdge.replace body: {value: 6} # replace the Document
699
+ myEdge.update body: {value: 6} # update the Document
700
+ myEdge.destroy # delete the Document
701
+ ```
702
+
703
+ <a name="ArangoTraversal"></a>
704
+ ## Arango::Traversal
705
+
706
+ Arango::Traversal is used to administrate the traversals.
707
+ Arango::Traversal 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 analyze.
708
+
709
+
710
+ ``` ruby
711
+ myTraversal = myVertex.traversal # Start traversal from myVertex
712
+ myTraversal = myDocument.traversal # Start traversal from myDocument
713
+ myTraversal = ArangoTraversal.new database: myDatabase, startVertex: myVertex # create instance
714
+ ```
715
+
716
+ ``` ruby
717
+ myTraversal.vertex = myVertex # define starting Vertex
718
+ myTraversal.edgeCollection = myEdgeCollection # define used Edge
719
+ myTraversal.in # Direction is in
720
+ myTraversal.out # Direction is out
721
+ myTraversal.any # Direction is in and out
722
+ myTraversal.min = 1 # Define how minimum deep we want to go with the traversal
723
+ myTraversal.max = 3 # Define how maximum deep we want to go with the traversal
724
+ ```
725
+
726
+ After the traversal is setup, you can execute it:
727
+
728
+ ``` ruby
729
+ myTraversal.execute
730
+ ```
731
+
732
+ <a name="ArangoUser"></a>
733
+ ## Arango::User
734
+
735
+ Arango::User manages the users.
736
+ To initialize an user:
737
+
738
+ ``` ruby
739
+ myUser = server.user name: "MyUser", password: "password"
740
+ myUser = Arango::User.new user: "MyUser", password: "password", server: server
741
+ ```
742
+
743
+ ### User management
744
+
745
+ ``` ruby
746
+ myUser.retrieve # Retrieve User
747
+ myUser["MyDatabase"] # Retrieve database if the user can access it
748
+ myUser.database("MyDatabase") # Retrieve database if the user can access it
749
+ myUser.create # Create a new User
750
+ myUser.replace active: false # Replace User
751
+ myUser.update active: false # Update User
752
+ myUser.destroy # Delete User
753
+ ```
754
+
755
+ ### Database management
756
+
757
+ ``` ruby
758
+ myUser.databases # List of databases can access
759
+ myUser.addDatabaseAccess grant: "rw", database: myDatabase
760
+ myUser.grant database: myDatabase # Grant access to a database
761
+ myUser.revoke database: myDatabase # Revoke access to a database
762
+ myUser.databaseAccess database: myDatabase # Check permission level of an User
763
+ myUser.addCollectionAccess grant: "rw", database: myDatabase, collection: myCollection
764
+ myUser.revokeCollectionAccess database: myDatabase, collection: myCollection
765
+ myUser.collectionAccess database: myDatabase, collection: myCollection
766
+ ```
767
+
768
+ You can manage the user permissions from the database or from the collection too.
769
+
770
+ ``` ruby
771
+ myDatabase.check_user(myUser)
772
+ myDatabase.addUserAccess(grant: "rw", user: myUser)
773
+ myDatabase.revokeUserAccess(user: myUser)
774
+ myDatabase.userAccess(user: myUser)
775
+ myCollection.check_user(myUser)
776
+ myCollection.addUserAccess(grant: "rw", user: myUser)
777
+ myCollection.revokeUserAccess(user: myUser)
778
+ myCollection.userAccess(user: myUser)
779
+ ```
780
+
781
+ <a name="ArangoIndex"></a>
782
+ ## Arango::Index
783
+
784
+ Arango::Index manages the indexes.
785
+ To initialize an index:
786
+
787
+ ``` ruby
788
+ myIndex = myCollection.index fields: "num", unique: false, id: "myIndex"
789
+ myIndex = Arango::Index.new fields: "num", unique: false, id: "myIndex", collection: myCollection
790
+ ```
791
+
792
+ ### Index management
793
+
794
+ ``` ruby
795
+ myIndex.retrieve # Retrieve Index
796
+ myIndex.create # Create a new Index
797
+ myIndex.destroy # Delete Index
798
+ ```
799
+
800
+ <a name="ArangoTransaction"></a>
801
+ ## Arango::Transaction
802
+
803
+ Transactions are managed by Arango::Transaction.
804
+
805
+ ``` ruby
806
+ action = "function(){ var db = require('@arangodb').db; db.MyCollection.save({}); return db.MyCollection.count(); }"
807
+ myTransaction = myDatabase.transaction action: action
808
+ myTransaction = Arango::Transaction.new action: action, database: myDatabase
809
+ ```
810
+
811
+ ``` ruby
812
+ myTransaction.addWrite(myCollection) # Add write collection
813
+ myTransaction.addRead(myCollection) # Add read collection
814
+ myArangoTransaction.execute # Return the result of the execution
815
+ ```
816
+
817
+ <a name="ArangoTask"></a>
818
+ ## Arango::Task
819
+
820
+ Tasks are managed by ArangoTask.
821
+
822
+ ``` ruby
823
+ command = "(function(params) { require('@arangodb').print(params); })(params)"
824
+ myTask = myDatabase.task id: "mytaskid", name: "MyTaskID", command: command, params: {foo: "bar", bar: "foo"}, period: 2
825
+ myTask = Arango::Task.new id: "mytaskid", name: "MyTaskID", command: command, params: {foo: "bar", bar: "foo"}, period: 2, database: myDatabase
826
+ ```
827
+
828
+ ``` ruby
829
+ myArangoTask.create # Create a new Task
830
+ myArangoTask.retrieve # Retrieve a Task
831
+ myArangoTask.destroy # Delete a Task
832
+ ```
833
+
834
+ <a name="ArangoReplication"></a>
835
+ ## Arango::Replication
836
+
837
+ Replication is useful to create back up copy of your database or to have a master-slave relationship between two databases.
838
+
839
+ Remember: the used database is the one where the data will be written (the slave) and the remote database will be the master one.
840
+
841
+ Use with caution since the data in the slave database will be deleted.
842
+
843
+ To setup our Slave Server and Master Database use a similar command.
844
+
845
+ ``` ruby
846
+ myReplication = slaveDatabase.replication(master: masterDatabase)
847
+ myReplication = masterDatabase.replication_as_master(slave: slaveDatabase)
848
+ myReplication = Arango::Replication.new master: masterDatabase, slave: slaveDatabase
849
+ ```
850
+
851
+ Than to do a simple syncronization uses;
852
+
853
+ ``` ruby
854
+ myReplication.sync # Sync master - slave database
855
+ ```
856
+
857
+ To retrieve other information arango-driver provides the following methods:
858
+
859
+ ``` ruby
860
+ myReplication.logger # Returns the current state of the server's replication logger
861
+ myReplication.loggerFollow # Returns data from the server's replication log.
862
+ myReplication.firstTick # Return the first available tick value from the server
863
+ myReplication.rangeTick # Returns the currently available ranges of tick values for all currently available WAL logfiles.
864
+ myReplication.serverId # Returns the servers id.
865
+ ```
866
+
867
+ ### Relation Master-Slave
868
+
869
+ To enslave a Server in relation to another Database use the following command:
870
+
871
+ ``` ruby
872
+ myReplication.enslave
873
+ ```
874
+
875
+ To manage the Configuration of a Master-Slave Replication you can use the following commands:
876
+
877
+ ``` ruby
878
+ myReplication.start # Start replication
879
+ myReplication.configuration # check the Configuration of the Replication
880
+ myReplication.state # check the status of the Replication
881
+ myReplication.stop # stop the Replication
882
+ myReplication.modify # modify the Configuration of the Replication (you can modify only a stopped Replication)
883
+ ```
884
+
885
+ ## Arango::Batch
886
+
887
+ To create a batch request, you can use arango-driver::Batch object. This permit to do multiple requests with one single call to the API.
888
+
889
+ To create a batch use one of the following way:
890
+
891
+ ``` ruby
892
+ batch = server.batch
893
+ batch = Arango::Batch.new(server: server)
894
+ ```
895
+
896
+ To add a queries to the batch request you can use the brutal way:
897
+
898
+ ``` ruby
899
+ batch.queries = [
900
+ {
901
+ type: "POST",
902
+ address: "/_db/MyDatabase/_api/collection",
903
+ body: {name: "newCOLLECTION"},
904
+ id: "1"
905
+ },
906
+ {
907
+ type: "GET",
908
+ address: "/_api/database",
909
+ id: "2"
910
+ }
911
+ ]
912
+ ```
913
+
914
+ Or the Ruby way (the id will be handled by the system, if not specified):
915
+
916
+ ``` ruby
917
+ batch = server.batch
918
+ batch.addQuery(method: "POST", address: "/_db/MyDatabase/_api/collection",
919
+ body: {name: "newCOLLECTION"})
920
+ batch.addQuery(method: "GET", address: "/_api/database")
921
+ ```
922
+
923
+ In both the cases the queries will be stored in an hash with key the id of the query and as value the query.
924
+ This query can be handled with the following methods:
925
+
926
+ ``` ruby
927
+ batch.to_h # Retrieve an hash version of the instance
928
+ batch.modifyQuery(id: "1", method: "GET", address: "/_db/MyDatabase/_api/collection/newCOLLECTION") # Modify the Query with id "1"
929
+ batch.removeQuery(id: "1") # Remove query
930
+ ```
931
+
932
+ To execute the query use:
933
+
934
+ ``` ruby
935
+ batch.execute
936
+ ```
937
+
938
+ To manage how the server handle the batch, Arango::Server offers the following functions:
939
+
940
+ ``` ruby
941
+ server.createDumpBatch ttl: 10 # Create a new dump batch with 10 second time-to-live (return id of the dumpBatch)
942
+ server.prolongDumpBatch id: idDumpBatch, ttl: 20 # Prolong the life of a batch for 20 seconds
943
+ server.destroyDumpBatch id: idDumpBatch # Delete a selected batch
944
+ ```
945
+
946
+ <a name="ArangoView"></a>
947
+ ## Arango::View
948
+
949
+ Views are managed by Arango::View.
950
+
951
+ ``` ruby
952
+ myView = myDatabase.view name: "MyView"
953
+ myView = Arango::View.new name: "MyView", database: myDatabase
954
+ ```
955
+
956
+ ``` ruby
957
+ myView.addLink(collection: myCollection) # Add a collection to the link
958
+ myView.retrieve # Retrieve view
959
+ myView.create # Create a view
960
+ myView.replaceProperties # Replace properties
961
+ myView.updateProperties # Update properties
962
+ myView.rename name: "MyView2" # Change name
963
+ myView.properties # Check properties
964
+ myView.destroy # Delete view
965
+ ```
966
+
967
+ <a name="ArangoFoxx"></a>
968
+ ## Arango::Foxx
969
+
970
+ Views are managed by Arango::Foxx. This instance of Foxx is untested.
971
+
972
+ ``` ruby
973
+ myFoxx = myDatabase.foxx mount: address
974
+ myFoxx = Arango::Foxx.new mount: address, database: myDatabase
975
+ ```
976
+
977
+ ``` ruby
978
+ myFoxx.retrieve # Retrieve foxx
979
+ myView.create # Create a foxx
980
+ myFoxx.update # Update foxx
981
+ myFoxx.replace # Replace foxx
982
+ myFoxx.destroy # Delete foxx
983
+ ```
984
+
985
+ Other methods
986
+
987
+ ``` ruby
988
+ myFoxx.retrieveConfiguration
989
+ myView.updateConfiguration body: body
990
+ myFoxx.replaceConfiguration body: body
991
+ myFoxx.retrieveDependencies
992
+ myFoxx.updateDependencies body: body
993
+ myFoxx.replaceDependencies body: body
994
+ myFoxx.scripts
995
+ myFoxx.run_script name: "test"
996
+ myFoxx.tests
997
+ myFoxx.enableDevelopment
998
+ myFoxx.disableDevelopment
999
+ myFoxx.readme
1000
+ myFoxx.swagger
1001
+ myFoxx.download path: path
1002
+ myFoxx.commit body: body
1003
+ ```
1004
+
1005
+ <a name="ArangoCache"></a>
1006
+ ## Arango::Cache
1007
+
1008
+ Arango::Cache is to manage arango-driver Cache (NOT ArangoDB cache) and it helps you to manage your documents around your code. In this way if you update an Arango::Document in your code, it will updated everywhere.
1009
+ An Arango::Cache instance is created together with the initialization of a server instance with active_cache true.
1010
+
1011
+ ``` ruby
1012
+ cache = server.cache # Arango::Cache instance
1013
+ cache.max # Max number of variable stored in the cache
1014
+ cache.updateMax(type: :document, val: 400) # Update how many documents store in the cache
1015
+ cache.clear # Clear cache
1016
+ cache.to_h # Hash of the cache
1017
+ ```
1018
+
1019
+ 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.
1020
+
1021
+ 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.
1022
+
1023
+
1024
+ <a name="ArangoError"></a>
1025
+ ## Arango::Error
1026
+
1027
+ Error from arango-driver are managed by Arango::Error.
1028
+ Each arango-driver error is provided of a code and a message. The list of code can be find in the file lib/Error.rb
1029
+
1030
+ ``` ruby
1031
+ begin
1032
+ Arango::Collection.new name: "Test", database: not_a_database
1033
+ rescue Arango::Error => e
1034
+ e.message # Message of the error
1035
+ e.code # arango-driver code, each arango-driver errors provides a list of errors
1036
+ e.data # More information about the error
1037
+ e.to_h # Hash version of the error
1038
+ end
1039
+ ```
1040
+
1041
+ Arango::Error has a children class called Arango::ErrorDB to handle Errors coming from wrong HTTP requests.
1042
+
1043
+ ``` ruby
1044
+ begin
1045
+ Arango::Collection.new(name: "DuplicateCollection", database: myDatabase).create
1046
+ rescue Arango::Error => e
1047
+ e.message # Message of the error
1048
+ e.code # HTTP error code
1049
+ e.data # More information about the error
1050
+ e.errorNum # ArangoDB errorNum code
1051
+ e.action # Type of request done to ArangoDB (POST, GET, ...)
1052
+ e.url # URL requested to ArangoDB
1053
+ e.request # Request made to ArangoDB
1054
+ e.to_h # Hash version of the error
1055
+ end
1056
+ ```
1057
+
1058
+ <a name="testing"></a>
1059
+ ## Testing
1060
+
1061
+ To test arango-driver you can use:
1062
+
1063
+ ``` ruby
1064
+ rspec spec/arangoRB_helper.rb
1065
+ ruby examples/year.rb
1066
+ ruby examples/year2.rb
1067
+ ```
1068
+
1069
+ Remember however the following:
1070
+ * Setup the correct server in lib/spec_helper.rb and in the examples
1071
+ * The test examples/year2.rb should run much after the test examples/year.rb, since the last test is dependent from the conclusion of the first test (that is running in async).
1072
+
1073
+ <a name="differences"></a>