arangorb 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +2 -2
- data/README.md +418 -123
- data/lib/ArangoRB_AQL.rb +90 -103
- data/lib/ArangoRB_Col.rb +476 -159
- data/lib/ArangoRB_DB.rb +305 -79
- data/lib/ArangoRB_Doc.rb +112 -114
- data/lib/ArangoRB_Edg.rb +81 -62
- data/lib/ArangoRB_Gra.rb +125 -76
- data/lib/ArangoRB_Index.rb +144 -0
- data/lib/ArangoRB_Ser.rb +439 -18
- data/lib/ArangoRB_Task.rb +136 -0
- data/lib/ArangoRB_Tra.rb +47 -42
- data/lib/ArangoRB_Tran.rb +48 -0
- data/lib/ArangoRB_User.rb +152 -0
- data/lib/ArangoRB_Ver.rb +74 -57
- data/lib/arangorb.rb +4 -0
- data/spec/arangoRB_helper.rb +2 -9
- data/spec/arangoRestart_helper.rb +14 -0
- data/spec/lib/{arangoAQL_helper.rb → 0.1.0/arangoAQL_helper.rb} +2 -21
- data/spec/lib/{arangoC_helper.rb → 0.1.0/arangoC_helper.rb} +40 -19
- data/spec/lib/{arangoDB_helper.rb → 0.1.0/arangoDB_helper.rb} +13 -13
- data/spec/lib/{arangoDoc_helper.rb → 0.1.0/arangoDoc_helper.rb} +10 -23
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -0
- data/spec/lib/{arangoG_helper.rb → 0.1.0/arangoG_helper.rb} +7 -21
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -0
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -0
- data/spec/lib/{arangoV_helper.rb → 0.1.0/arangoV_helper.rb} +6 -22
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -0
- data/spec/lib/1.0.0/arangoDB_helper.rb +81 -0
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -0
- data/spec/lib/1.0.0/arangoS_helper.rb +196 -0
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -0
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -0
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -0
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -0
- data/spec/spec_helper.rb +34 -0
- metadata +28 -15
- data/spec/lib/arangoE_helper.rb +0 -70
- data/spec/lib/arangoS_helper.rb +0 -28
- data/spec/lib/arangoT_helper.rb +0 -67
data/README.md
CHANGED
@@ -1,111 +1,258 @@
|
|
1
|
-
ArangoRB
|
1
|
+
ArangoRB [![Gem Version](https://badge.fury.io/rb/arangorb.svg)](https://badge.fury.io/rb/arangorb)
|
2
2
|
===============================
|
3
3
|
|
4
|
-
[
|
5
|
-
ArangoRB
|
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
6
|
|
7
|
-
ArangoRB has been tested with
|
7
|
+
ArangoRB has been tested with ArangoDatabase 3.0 on Ruby 2.3.1. It requires the gem "HTTParty"
|
8
8
|
|
9
|
-
|
10
|
-
`require_relative "./ArangoRB/ArangoRB"` in your ruby code.
|
9
|
+
To install ArangoRB: `gem install arangorb`
|
11
10
|
|
12
|
-
|
11
|
+
To use it in your application: `require "arangorb"`
|
12
|
+
|
13
|
+
This Gem was created from [Seluxit ApS](http://seluxit.com/).
|
13
14
|
|
14
15
|
## Classes used
|
15
16
|
|
16
17
|
ArangoRB has the following classes.
|
17
18
|
|
18
|
-
* [
|
19
|
-
* [
|
20
|
-
* [
|
21
|
-
* [
|
22
|
-
* [
|
23
|
-
* [
|
24
|
-
* [
|
25
|
-
* [
|
26
|
-
* [ArangoAQL](#arangoaql): to manage
|
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
|
27
32
|
|
28
|
-
<a name="
|
29
|
-
##
|
33
|
+
<a name="ArangoServer"></a>
|
34
|
+
## ArangoServer
|
30
35
|
|
31
|
-
|
36
|
+
ArangoServer is used to manage the default Database, Collection, User and Graph.
|
37
|
+
It is used to give your login credentials and it is the mandatory step to start your database.
|
38
|
+
Further it helps to manage the Server connected with ArangoDB.
|
32
39
|
|
33
|
-
To setup your
|
40
|
+
To setup your credentials use:
|
34
41
|
|
35
42
|
``` ruby
|
36
|
-
|
43
|
+
ArangoServer.default_server user: "MyUsername", password: "MyPassword", server: "localhost", port: "8529"
|
37
44
|
```
|
38
45
|
|
39
|
-
|
46
|
+
If not declared, the default values are user: "root", password: "", server: "localhost", port: "8529".
|
40
47
|
|
41
|
-
###
|
48
|
+
### Default variables
|
42
49
|
|
43
|
-
|
44
|
-
If this is the case, the user can use
|
50
|
+
Databases, Graphs and Collections used in your program can be defined each time. But often it is convenient to have some default one.
|
51
|
+
If this is the case, the user can use ArangoServer to define some default values.
|
45
52
|
|
46
53
|
``` ruby
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
ArangoServer.database = "MyDatabase" # Setup default Database
|
55
|
+
ArangoServer.graph = "MyGraph" # Setup default Graph
|
56
|
+
ArangoServer.collection = "MyCollection" # Setup default Collection
|
57
|
+
ArangoServer.user = "MyUser" # Setup default User
|
50
58
|
```
|
51
59
|
|
52
|
-
By default the
|
60
|
+
By default the default database is "\_system".
|
53
61
|
|
54
62
|
### Verbose
|
55
63
|
|
56
|
-
For Debugging reasons the user
|
64
|
+
For Debugging reasons the user can receive the original JSON file from the database by setting verbose on true (false by default).
|
57
65
|
|
58
66
|
``` ruby
|
59
|
-
|
67
|
+
ArangoServer.verbose = true
|
60
68
|
```
|
61
69
|
|
62
70
|
Remember that verbose is only for testing reason: to work efficiently verbose should be false.
|
63
71
|
|
64
|
-
|
65
|
-
|
72
|
+
### Information
|
73
|
+
|
74
|
+
Basic informations can be retrieved with these command.
|
75
|
+
|
76
|
+
``` ruby
|
77
|
+
ArangoServer.database # Check name default Database
|
78
|
+
ArangoServer.graph # Check name default Graph
|
79
|
+
ArangoServer.collection # Check name default Collection
|
80
|
+
ArangoServer.user # Check name default User
|
81
|
+
ArangoServer.address # Check address used to connect with the server
|
82
|
+
ArangoServer.username # Check name used to connect with the server
|
83
|
+
ArangoServer.verbose # Check if verbose is true or false
|
84
|
+
ArangoServer.async # Check the status of async
|
85
|
+
ArangoServer.request # Check the default request sent to the server
|
86
|
+
```
|
87
|
+
|
88
|
+
To retrieve lists
|
89
|
+
|
90
|
+
``` ruby
|
91
|
+
ArangoServer.endpoints # Lists of endpoints used
|
92
|
+
ArangoServer.users # Lists of available users
|
93
|
+
ArangoServer.databases # Lists of available databases
|
94
|
+
ArangoServer.tasks # Lists of available tasks
|
95
|
+
```
|
96
|
+
|
97
|
+
To monitoring the server you can use the following commands
|
98
|
+
|
99
|
+
``` ruby
|
100
|
+
ArangoServer.log # Return log files
|
101
|
+
ArangoServer.reload # Reloads the routing information from the collection routing.
|
102
|
+
ArangoServer.statistics # Returns the statistics information
|
103
|
+
ArangoServer.statistics description: true # Fetch descriptive info of statistics
|
104
|
+
ArangoServer.role # Get to know whether this server is a Coordinator or DB-Server
|
105
|
+
ArangoServer.serverId # Fetch this servers uniq identifier
|
106
|
+
```
|
107
|
+
|
108
|
+
### Manage Async
|
109
|
+
|
110
|
+
With ArangoServer you can manage Async results.
|
111
|
+
|
112
|
+
``` ruby
|
113
|
+
ArangoServer.async = false # default
|
114
|
+
ArangoServer.async = true # fire and forget
|
115
|
+
ArangoServer.async = "store" # fire and store
|
116
|
+
```
|
117
|
+
|
118
|
+
If Async is "store", then the commands of ArangoRB will return the id of the Async requests.
|
119
|
+
ArangoServer provides different methods to manage these Async requests.
|
120
|
+
|
121
|
+
``` ruby
|
122
|
+
ArangoServer.pendingAsync # Querying the status of a pending job
|
123
|
+
ArangoServer.fetchAsync id: id # Fetches a job result and removes it from the queue
|
124
|
+
ArangoServer.retrieveAsync id: id # Returns the status of a specific job
|
125
|
+
ArangoServer.retrieveAsync type: type # Returns the ids of job results with a specific status
|
126
|
+
# Type can be "done" or "pending"
|
127
|
+
ArangoServer.retrieveDoneAsync # Equivalent to ArangoServer.retrieveAsync type: "done"
|
128
|
+
ArangoServer.retrievePendingAsync # Equivalent to ArangoServer.retrieveAsync type: "pending"
|
129
|
+
ArangoServer.cancelAsync id: id # Cancels an async job
|
130
|
+
ArangoServer.destroyAsync id: id # Deletes an async job result
|
131
|
+
ArangoServer.destroyAsync type: type # Deletes async jobs with a specific status
|
132
|
+
# Type can be "all" or "expired"
|
133
|
+
ArangoServer.destroyAllAsync # Equivalent to ArangoServer.destroyAsync type: "all"
|
134
|
+
ArangoServer.destroyExpiredAsync # Equivalent to ArangoServer.destroyAsync type: "expired"
|
135
|
+
```
|
136
|
+
|
137
|
+
### Batch
|
138
|
+
|
139
|
+
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.
|
140
|
+
|
141
|
+
``` ruby
|
142
|
+
queries = [
|
143
|
+
{
|
144
|
+
"type": "POST",
|
145
|
+
"address": "/_db/MyDatabase/_api/collection",
|
146
|
+
"body": {"name": "newCOLLECTION"},
|
147
|
+
"id": "1"
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"type": "GET",
|
151
|
+
"address": "/_api/database",
|
152
|
+
"id": "2"
|
153
|
+
}
|
154
|
+
]
|
155
|
+
ArangoServer.batch queries: queries
|
156
|
+
```
|
157
|
+
|
158
|
+
To manage these batch, ArangoServer offers the following functions:
|
66
159
|
|
67
|
-
|
160
|
+
``` ruby
|
161
|
+
ArangoServer.createDumpBatch ttl: 10 # Create a new dump batch with 10 second time-to-live (return id of the dumpBatch)
|
162
|
+
ArangoServer.prolongDumpBatch id: idDumpBatch, ttl: 20 # Prolong the life of a batch for 20 seconds
|
163
|
+
ArangoServer.destroyDumpBatch id: idDumpBatch # Delete a selected batch
|
164
|
+
```
|
165
|
+
|
166
|
+
### Miscellaneous
|
167
|
+
|
168
|
+
``` ruby
|
169
|
+
ArangoServer.version # Returns the server version number
|
170
|
+
ArangoServer.flushWAL # Flushes the write-ahead log
|
171
|
+
ArangoServer.propertyWAL # Retrieves the configuration of the write-ahead log
|
172
|
+
ArangoServer.changePropertyWAL # Configures the write-ahead log
|
173
|
+
ArangoServer.transactions # Returns information about the currently running transactions
|
174
|
+
ArangoServer.time # Get the current time of the system
|
175
|
+
ArangoServer.echo # Return current request
|
176
|
+
ArangoServer.databaseVersion # Return the required version of the database
|
177
|
+
ArangoServer.sleep duration: 10 # Sleep for a specified amount of seconds
|
178
|
+
ArangoServer.shutdown # Initiate shutdown sequence
|
179
|
+
ArangoServer.restart # Restart ArangoDB (requires administration access)
|
180
|
+
```
|
181
|
+
|
182
|
+
UNTESTED
|
183
|
+
|
184
|
+
``` ruby
|
185
|
+
ArangoServer.test body: body # Runs tests on server
|
186
|
+
ArangoServer.execute body: body # Execute a script on the server.
|
187
|
+
```
|
188
|
+
|
189
|
+
### Sharding (UNTESTED)
|
190
|
+
|
191
|
+
ArangoDB permits the sharding of the database. Although these methods has not been tested with ArangoRB.
|
192
|
+
|
193
|
+
``` ruby
|
194
|
+
ArangoServer.cluster # Default cluster
|
195
|
+
ArangoServer.getCluster body: body, cluster: cluster # Retrieve cluster
|
196
|
+
ArangoServer.executeCluster body: body, cluster: cluster # Execute cluster
|
197
|
+
ArangoServer.executeClusterPut body: body, cluster: cluster # Execute cluster
|
198
|
+
ArangoServer.executeClusterHead body: body, cluster: cluster # Execute cluster
|
199
|
+
ArangoServer.destroyCluster cluster: cluster # Delete cluster
|
200
|
+
ArangoServer.updateCluster body: body, cluster: cluster # Update cluster
|
201
|
+
ArangoServer.checkPort port: port # Allows to check whether a given port is usable
|
202
|
+
ArangoServer.server # Returns the id of a server in a cluster.
|
203
|
+
ArangoServer.clusterStatistics dbserver: dbserver # Allows to query the statistics of a DBserver in the cluster
|
204
|
+
```
|
205
|
+
|
206
|
+
<a name="ArangoDatabase"></a>
|
207
|
+
## ArangoDatabase
|
208
|
+
|
209
|
+
ArangoDatabase is used to manage your Database. You can create an instance in the following way:
|
68
210
|
|
69
211
|
``` ruby
|
70
|
-
myDatabase =
|
212
|
+
myDatabase = ArangoDatabase.new database: "MyDatabase"
|
71
213
|
```
|
72
214
|
|
73
|
-
Alternatively, you can use
|
215
|
+
Alternatively, you can use the default values provided by ArangoServer:
|
74
216
|
|
75
217
|
``` ruby
|
76
|
-
|
77
|
-
myDatabase =
|
218
|
+
ArangoServer.database = "MyDatabase"
|
219
|
+
myDatabase = ArangoDatabase.new
|
78
220
|
```
|
79
221
|
|
80
222
|
### Create and Destroy a Database
|
81
223
|
|
82
224
|
``` ruby
|
83
|
-
myDatabase.create
|
84
|
-
|
225
|
+
myDatabase.create # Create a new Database
|
226
|
+
myDatabase.destroy # Delete the selected Database
|
85
227
|
```
|
86
228
|
|
87
229
|
### Retrieve information
|
88
230
|
|
89
231
|
``` ruby
|
90
|
-
|
91
|
-
|
232
|
+
ArangoDatabase.info # Obtain general info about the databases
|
233
|
+
ArangoDatabase.databases # Obtain an Array with the available databases
|
92
234
|
myDatabase.collections # Obtain an Array with the available collections in the selected Database
|
93
235
|
myDatabase.graphs # Obtain an Array with the available graphs in the selected Database
|
236
|
+
myDatabase.functions # Obtain an Array with the available functions in the selected Database
|
94
237
|
```
|
95
238
|
|
96
239
|
### Query
|
97
240
|
|
241
|
+
ArangoDatabase instances can manage the queries used in their Database.
|
242
|
+
|
98
243
|
``` ruby
|
99
244
|
myDatabase.propertiesQuery; # See property of the Query
|
100
245
|
myDatabase.currentQuery; # Check the current Query
|
101
246
|
myDatabase.slowQuery; # Find slow queries
|
102
247
|
myDatabase.stopSlowQuery; # Stop slow queries
|
103
|
-
myDatabase.kill
|
248
|
+
myDatabase.kill query: myQuery # Kill a Query
|
104
249
|
myDatabase.changePropertiesQuery maxSlowQueries: 65 # Change properties of a Query
|
105
250
|
```
|
106
251
|
|
107
252
|
### Cache
|
108
253
|
|
254
|
+
To manage the cache ArangoDatabase provides the following three functions.
|
255
|
+
|
109
256
|
``` ruby
|
110
257
|
myDatabase.clearCache # Clear Cache
|
111
258
|
myDatabase.propertyCache # Check properties Cache
|
@@ -119,22 +266,50 @@ myDatabase.createFunction code: "function(){return 1+1;}", name: "myFunction" #
|
|
119
266
|
myDatabase.deleteFunction name: "myFunction" # Delete a function
|
120
267
|
myDatabase.functions # Retrieve a list of the available functions
|
121
268
|
```
|
122
|
-
<a name="arangoc"></a>
|
123
|
-
## ArangoC - ArangoDB Collection
|
124
269
|
|
125
|
-
|
270
|
+
### User
|
271
|
+
|
272
|
+
You can manage the right of a user to access the database.
|
273
|
+
|
274
|
+
``` ruby
|
275
|
+
@myDatabase.grant user: myUser # Grant access to database
|
276
|
+
@myDatabase.revoke user: myUser # Revoke access to database
|
277
|
+
```
|
278
|
+
|
279
|
+
### Replication (UNTESTED)
|
280
|
+
|
281
|
+
``` ruby
|
282
|
+
@myDatabase.inventory # Returns an overview of collections and their indexes
|
283
|
+
@myDatabase.clusterInventory # Return cluster inventory of collections and indexes
|
284
|
+
@myDatabase.logger # Return replication logger state
|
285
|
+
@myDatabase.loggerFollow # Returns log entries
|
286
|
+
@myDatabase.firstTick # Returns the first available tick value
|
287
|
+
@myDatabase.rangeTick # Return the tick ranges available in the WAL logfiles
|
288
|
+
@myDatabase.sync # Synchronize data from a remote endpoint
|
289
|
+
@myDatabase.configurationReplication # Return configuration of replication applier
|
290
|
+
@myDatabase.modifyConfigurationReplication # Adjust configuration of replication applier
|
291
|
+
@myDatabase.startReplication # Start replication applier
|
292
|
+
@myDatabase.stateReplication # State of the replication applier
|
293
|
+
@myDatabase.stopReplication # Stop replication applier
|
294
|
+
@myDatabase.enslave # Turn the server into a slave of another
|
295
|
+
```
|
296
|
+
|
297
|
+
<a name="ArangoCollection"></a>
|
298
|
+
## ArangoCollection
|
299
|
+
|
300
|
+
ArangoDatabase is used to manage your Collections. You can create an ArangoCollection instance in one of the following way:
|
126
301
|
|
127
302
|
``` ruby
|
128
|
-
myCollection =
|
129
|
-
myCollection =
|
130
|
-
myCollection =
|
303
|
+
myCollection = ArangoCollection.new database: "MyDatabase", collection: "MyCollection"
|
304
|
+
myCollection = ArangoCollection.new collection: "MyCollection" # Using the default database
|
305
|
+
myCollection = ArangoCollection.new # Using the default database and collection
|
131
306
|
```
|
132
307
|
|
133
308
|
A Collection can be of two types: "Document" and "Edge". If you want to specify it, uses:
|
134
309
|
|
135
310
|
``` ruby
|
136
|
-
myCollectionA =
|
137
|
-
myCollectionB =
|
311
|
+
myCollectionA = ArangoCollection.new collection: "MyCollectionA", type: "Document"
|
312
|
+
myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"
|
138
313
|
```
|
139
314
|
|
140
315
|
### Create a Collection
|
@@ -146,13 +321,13 @@ To create an Edge Collection you can use one of the next three options:
|
|
146
321
|
|
147
322
|
``` ruby
|
148
323
|
myCollection.create_edge_collection
|
149
|
-
myCollection.create type:
|
150
|
-
myCollectionB =
|
324
|
+
myCollection.create type: "Edge"
|
325
|
+
myCollectionB = ArangoCollection.new collection: "MyCollectionB", type: "Edge"; myCollectionB.create
|
151
326
|
```
|
152
327
|
|
153
328
|
### Destroy or Truncate a Collections
|
154
329
|
|
155
|
-
Destroy will delete from the Database
|
330
|
+
Destroy will delete the selected Collection from the Database.
|
156
331
|
|
157
332
|
`myCollection.destroy`
|
158
333
|
|
@@ -164,10 +339,13 @@ Truncate will delete all the Documents inside the selected Collection.
|
|
164
339
|
|
165
340
|
``` ruby
|
166
341
|
myCollection.retrieve # Retrieve the selected Collection
|
342
|
+
myCollection.indexes # Return a list of all used Indexes in the Collection
|
343
|
+
myCollection.data # Returns the whole content of one collection
|
167
344
|
myCollection.properties # Properties of the Collection
|
168
345
|
myCollection.count # Number of Documents in the Collection
|
169
346
|
myCollection.stats # Statistics of the Collection
|
170
|
-
myCollection.
|
347
|
+
myCollection.revision # Return collection revision id
|
348
|
+
myCollection.checksum # Return checksum for the Collection
|
171
349
|
```
|
172
350
|
|
173
351
|
To retrieve the documents of a Collection you can use:
|
@@ -181,7 +359,7 @@ These two functions are similar except for the fact that you can assign differen
|
|
181
359
|
|
182
360
|
`myCollection.documents type: "path"`
|
183
361
|
|
184
|
-
Type can be "path", "id" or "key" in relation what we wish to have. If not specified we will receive an array of
|
362
|
+
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.
|
185
363
|
|
186
364
|
`myCollection.allDocuments skip: 3, limit: 100, batchSize: 10`
|
187
365
|
|
@@ -203,6 +381,48 @@ myCollection.load # Load the Collection
|
|
203
381
|
myCollection.unload # Unload the Collection
|
204
382
|
myCollection.change waitForSync: true # Change a property of the Collection
|
205
383
|
myCollection.rename "myCollectionC" # Rename the Collection
|
384
|
+
myCollection.rotate # Rotate journal of a collection
|
385
|
+
```
|
386
|
+
|
387
|
+
### Import and Export Documents
|
388
|
+
|
389
|
+
For the standard way to import one or more Documents (or Edges) we refer to the [dedicated ArangoDocument section](#create_doc).
|
390
|
+
However it is possible to import a huge quantity of documents in a Collection with only one requests with the command import.
|
391
|
+
|
392
|
+
<strong>Import one Document with Array</strong>
|
393
|
+
I import one document with the following structure {"value": "uno", "num": 1, "name": "ONE"}.
|
394
|
+
``` ruby
|
395
|
+
attributes = ["value", "num", "name"]
|
396
|
+
values = ["uno",1,"ONE"]
|
397
|
+
myCollection.import attributes: attributes, values: values
|
398
|
+
```
|
399
|
+
|
400
|
+
<strong>Import more Documents with Array</strong>
|
401
|
+
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"}.
|
402
|
+
``` ruby
|
403
|
+
attributes = ["value", "num", "name"]
|
404
|
+
values = [["uno",1,"ONE"],["due",2,"TWO"],["tre",3,"THREE"]]
|
405
|
+
myCollection.import attributes: attributes, values: values
|
406
|
+
```
|
407
|
+
|
408
|
+
<strong>Import more Documents with JSON</strong>
|
409
|
+
I import two Documents with the following structure {"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "TWO"}.
|
410
|
+
``` ruby
|
411
|
+
body = [{"value": "uno", "num": 1, "name": "ONE"}, {"value": "due", "num": 2, "name": "DUE"}]
|
412
|
+
myCollection.importJSON body: body
|
413
|
+
```
|
414
|
+
|
415
|
+
As it is possible to import files, it is possible to export all the Document of a Collection with the following command.
|
416
|
+
``` ruby
|
417
|
+
myCollection.export
|
418
|
+
```
|
419
|
+
|
420
|
+
Alternatively it is possible to retrieve all the Documents in a Collection gradually.
|
421
|
+
|
422
|
+
``` ruby
|
423
|
+
myCollection.export batchSize: 3 # First three Documents of the Collection
|
424
|
+
myCollection.exportNext # Next three Documents
|
425
|
+
myCollection.exportNext # Next three Documents
|
206
426
|
```
|
207
427
|
|
208
428
|
### Other operations
|
@@ -214,60 +434,59 @@ myCollection.replaceMatch match: {"value" => 4}, newValue: {"value" => 6} # All
|
|
214
434
|
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
|
215
435
|
```
|
216
436
|
|
217
|
-
<a name="
|
218
|
-
##
|
437
|
+
<a name="ArangoDocument"></a>
|
438
|
+
## ArangoDocument
|
219
439
|
|
220
440
|
An Arango Document is an element of a Collection. Edges are documents with "\_from" and "\_to" in their body.
|
221
|
-
You can create an
|
441
|
+
You can create an ArangoCollection instance in one of the following way:
|
222
442
|
|
223
443
|
``` ruby
|
224
|
-
myDocument =
|
225
|
-
myDocument =
|
226
|
-
myDocument =
|
227
|
-
myDocument =
|
228
|
-
myDocument = ArangoDoc.new # If the database and the collection have been already defined with ArangoS and I don't want to define a key for my Instance
|
444
|
+
myDocument = ArangoDocument.new database: "MyDatabase", collection: "MyCollection", key: "myKey"
|
445
|
+
myDocument = ArangoDocument.new collection: "MyCollection", key: "myKey" # Using default Database
|
446
|
+
myDocument = ArangoDocument.new key: "myKey" # Using default Collection and Database
|
447
|
+
myDocument = ArangoDocument.new # Using default Collection and Database and I don't want to define a key for my Instance
|
229
448
|
```
|
230
449
|
|
231
|
-
In the case you want to define a Edge, it is convenient to introduce
|
450
|
+
In the case you want to define a Edge, it is convenient to introduce the parameters "from" and "to" in the instance.
|
232
451
|
|
233
452
|
``` ruby
|
234
|
-
myEdge =
|
453
|
+
myEdge = ArangoDocument.new from: myDocA, to: myDocB
|
235
454
|
```
|
236
455
|
|
237
|
-
where myDocA and myDocB are the IDs of two Documents or are two
|
238
|
-
|
239
|
-
When you do the instance of an ArangoDoc is a good idea to define a Body for the Document you want:
|
456
|
+
where myDocA and myDocB are the IDs of two Documents or are two ArangoDocument instances.
|
457
|
+
During the instance, it is possible to define a Body for the Document.
|
240
458
|
|
241
459
|
``` ruby
|
242
|
-
myDocument =
|
460
|
+
myDocument = ArangoDocument.new body: {"value" => 17}
|
243
461
|
```
|
244
462
|
|
463
|
+
<a name="create_doc"></a>
|
245
464
|
### Create one or more Documents
|
246
465
|
|
247
|
-
|
466
|
+
ArangoRB provides several way to create a single Document.
|
248
467
|
|
249
468
|
``` ruby
|
250
469
|
myDocument.create
|
251
|
-
myCollection.create_document document: myDocument # myDocument is an
|
252
|
-
|
470
|
+
myCollection.create_document document: myDocument # myDocument is an ArangoDocument instance or a Hash
|
471
|
+
ArangoDocument.create body: {"value" => 17}, collection: myDocument
|
253
472
|
```
|
254
473
|
|
255
|
-
|
474
|
+
Or more Documents.
|
256
475
|
|
257
476
|
``` ruby
|
258
|
-
myCollection.create_document document: [myDocumentA, myDocumentB, {"value" => 17}] # Array of
|
259
|
-
|
477
|
+
myCollection.create_document document: [myDocumentA, myDocumentB, {"value" => 17}] # Array of ArangoDocument instances and Hashes
|
478
|
+
ArangoDocument.create body: [myDocumentA, {"value" => 18}, {"value" => 3}], collection: myDocument # Array of ArangoDocument instances and Hash
|
260
479
|
```
|
261
480
|
|
262
481
|
### Create one or more Edges
|
263
482
|
|
264
|
-
|
483
|
+
ArangoRB has different way to create one or multiple edges. Here some example:
|
265
484
|
|
266
485
|
``` ruby
|
267
|
-
myEdge =
|
268
|
-
myEdge.create_edge from: myDocA, to: myDocB # myDocA and myDocB are
|
486
|
+
myEdge = ArangoDocument.new from: myDocA, to: myDocB; myEdge.create
|
487
|
+
myEdge.create_edge from: myDocA, to: myDocB # myDocA and myDocB are ArangoDocument ids or ArangoDocument instances
|
269
488
|
myEdgeCollection.create_edge document: myEdge, from: myDocA, to: myDocB
|
270
|
-
|
489
|
+
ArangoDocument.create_edge body: {"value" => 17}, from: myDocA, to: myDocB, collection: myEdgeCollection
|
271
490
|
```
|
272
491
|
|
273
492
|
Further we have the possibility to create different combination of Edges in only one line of code
|
@@ -325,7 +544,7 @@ myDocument.destroy
|
|
325
544
|
|
326
545
|
``` ruby
|
327
546
|
myDocument.retrieve # Retrieve Document
|
328
|
-
myDocument.retrieve_edges
|
547
|
+
myDocument.retrieve_edges collection: myEdgeCollection # Retrieve all myEdgeCollection edges connected with the Document
|
329
548
|
myDocument.any(myEdgeCollection) # Retrieve all myEdgeCollection edges connected with the Document
|
330
549
|
myDocument.in(myEdgeCollection) # Retrieve all myEdgeCollection edges coming in the Document
|
331
550
|
myDocument.out(myEdgeCollection) # Retrieve all myEdgeCollection edges going out the Document
|
@@ -366,15 +585,15 @@ myDocument.update body: {"value" => 3} # We update or add a value
|
|
366
585
|
myDocument.replace body: {"value" => 3} # We replace a value
|
367
586
|
```
|
368
587
|
|
369
|
-
<a name="
|
370
|
-
##
|
588
|
+
<a name="ArangoGraph"></a>
|
589
|
+
## ArangoGraph
|
371
590
|
|
372
|
-
|
591
|
+
ArangoGraph are used to manage Graphs. You can create an ArangoGraph instance in one of the following way.
|
373
592
|
|
374
593
|
``` ruby
|
375
|
-
myGraph =
|
376
|
-
myGraph =
|
377
|
-
myGraph =
|
594
|
+
myGraph = ArangoGraph.new database: "MyDatabase", graph: "MyGraph"
|
595
|
+
myGraph = ArangoGraph.new graph: "MyGraph" # By using the default Database
|
596
|
+
myGraph = ArangoGraph.new # By using the defauly Database and Graph
|
378
597
|
```
|
379
598
|
|
380
599
|
### Create, Retrieve and Destroy a Graph
|
@@ -389,32 +608,32 @@ myGraph.destroy # destroy the Graph
|
|
389
608
|
|
390
609
|
``` ruby
|
391
610
|
myGraph.vertexCollections # Retrieve all the vertexCollections of the Graph
|
392
|
-
myGraph.addVertexCollection
|
393
|
-
myGraph.removeVertexCollection
|
611
|
+
myGraph.addVertexCollection collection: "myCollection" # Add a Vertex Collection to our Graph
|
612
|
+
myGraph.removeVertexCollection collection: "myCollection" # Remove a Vertex Collection to our Graph
|
394
613
|
```
|
395
614
|
|
396
615
|
### Manage Edge Collections
|
397
616
|
|
398
617
|
``` ruby
|
399
618
|
myGraph.edgeCollections # Retrieve all the edgeCollections of the Graph
|
400
|
-
myGraph.addEdgeCollections
|
401
|
-
myGraph.replaceEdgeCollections
|
402
|
-
myGraph.removeEdgeCollections
|
619
|
+
myGraph.addEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Add an Edge Collection to our Graph
|
620
|
+
myGraph.replaceEdgeCollections collection: "myEdgeCollection", from: "myCollectionA", to: "myCollectionB" # Replace an Edge Collection to our Graph
|
621
|
+
myGraph.removeEdgeCollections collection: "myEdgeCollection" # Remove an Edge Collection to our Graph
|
403
622
|
```
|
404
623
|
|
405
|
-
<a name="
|
406
|
-
##
|
624
|
+
<a name="ArangoVertex"></a><a name="ArangoEdge"></a>
|
625
|
+
## ArangoVertex and ArangoEdge
|
407
626
|
|
408
|
-
Both these two classes inherit the class
|
409
|
-
These two classes have been created since
|
627
|
+
Both these two classes inherit the class ArangoDocument.
|
628
|
+
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.
|
410
629
|
|
411
|
-
###
|
630
|
+
### ArangoVertex methods
|
412
631
|
|
413
|
-
|
414
|
-
To use
|
632
|
+
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.
|
633
|
+
To use ArangoVertex, the Collection of the Vertex needs to be added either to the VertexCollections or to the EdgeCollections of the chosen Graph.
|
415
634
|
|
416
635
|
``` ruby
|
417
|
-
myVertex =
|
636
|
+
myVertex = ArangoVertex.new key: "newVertex", body: {"value" => 3}, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
|
418
637
|
myVertex.create # create a new Document in the Graph
|
419
638
|
myVertex.retrieve # retrieve a Document
|
420
639
|
myVertex.replace body: {"value" => 6} # replace the Document
|
@@ -422,13 +641,13 @@ myVertex.update body: {"value" => 6} # update the Document
|
|
422
641
|
myVertex.destroy # delete the Document
|
423
642
|
```
|
424
643
|
|
425
|
-
###
|
644
|
+
### ArangoEdge methods
|
426
645
|
|
427
|
-
|
428
|
-
To use
|
646
|
+
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.
|
647
|
+
To use ArangoEdge, the Collection of the Edge needs to be added to the EdgeCollections of the chosen Graph.
|
429
648
|
|
430
649
|
``` ruby
|
431
|
-
myEdge =
|
650
|
+
myEdge = ArangoEdge.new key: "newVertex", body: {"value" => 3}, from: myArangoDocument, to: myArangoDocument, collection: "myCollection", graph: "myGraph", database: "myDatabase" # create a new instance
|
432
651
|
myEdge.create # create a new Document of type Edge in the Graph
|
433
652
|
myEdge.retrieve # retrieve a Document
|
434
653
|
myEdge.replace body: {"value" => 6} # replace the Document
|
@@ -436,37 +655,37 @@ myEdge.update body: {"value" => 6} # update the Document
|
|
436
655
|
myEdge.destroy # delete the Document
|
437
656
|
```
|
438
657
|
|
439
|
-
<a name="
|
440
|
-
##
|
658
|
+
<a name="ArangoTraversal"></a>
|
659
|
+
## ArangoTraversal
|
441
660
|
|
442
|
-
|
443
|
-
|
661
|
+
ArangoTraversal is used to administrate the traversals.
|
662
|
+
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.
|
444
663
|
|
445
664
|
``` ruby
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
665
|
+
myTraversal = ArangoTraversal.new # create new ArangoTraversal
|
666
|
+
myTraversal.vertex = myVertex # define starting Vertex
|
667
|
+
myTraversal.graph = myGraph # define used Graph
|
668
|
+
myTraversal.edgeCollection = myEdgeCollection # define used Edge
|
669
|
+
myTraversal.in # Direction is in
|
670
|
+
myTraversal.out # Direction is out
|
671
|
+
myTraversal.any # Direction is in and out
|
672
|
+
myTraversal.min = 1 # Define how minimum deep we want to go with the traversal
|
673
|
+
myTraversal.max = 3 # Define how maximum deep we want to go with the traversal
|
455
674
|
```
|
456
675
|
|
457
|
-
After the
|
676
|
+
After the traversal is setup, you can execute it:
|
458
677
|
|
459
678
|
``` ruby
|
460
|
-
|
679
|
+
myTraversal.execute
|
461
680
|
```
|
462
681
|
|
463
682
|
<a name="arangoaql"></a>
|
464
|
-
## ArangoAQL -
|
683
|
+
## ArangoAQL - ArangoDatabase Query Language
|
465
684
|
|
466
|
-
ArangoAQL is used to manage the ArangoDB query
|
685
|
+
ArangoAQL is used to manage the ArangoDB query language. To instantiate a query
|
467
686
|
|
468
687
|
``` ruby
|
469
|
-
myQuery = ArangoAQL.new
|
688
|
+
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]"
|
470
689
|
```
|
471
690
|
|
472
691
|
To execute it use:
|
@@ -474,7 +693,7 @@ To execute it use:
|
|
474
693
|
myQuery.execute
|
475
694
|
```
|
476
695
|
|
477
|
-
If the query is too big, you can divide the fetching in
|
696
|
+
If the query is too big, you can divide the fetching in pieces, for example:
|
478
697
|
``` ruby
|
479
698
|
myQuery.size = 10
|
480
699
|
myQuery.execute # First 10 documents
|
@@ -499,3 +718,79 @@ myQuery.changeProperties maxSlowQueries: 65 # Change Properties
|
|
499
718
|
myQuery.stopSlow; # Stop Slow query
|
500
719
|
myQuery.kill; # Kill Query
|
501
720
|
```
|
721
|
+
|
722
|
+
<a name="ArangoUser"></a>
|
723
|
+
## ArangoUser
|
724
|
+
|
725
|
+
ArangoUser manages the users.
|
726
|
+
To initialize an user:
|
727
|
+
|
728
|
+
``` ruby
|
729
|
+
myUser = ArangoUser.new user: "MyUser", password: "password"
|
730
|
+
```
|
731
|
+
|
732
|
+
### User management
|
733
|
+
|
734
|
+
``` ruby
|
735
|
+
myUser.retrieve # Retrieve User
|
736
|
+
myUser.create # Create a new User
|
737
|
+
myUser.replace active: false # Replace User
|
738
|
+
myUser.update active: false # Update User
|
739
|
+
myUser.destroy # Delete User
|
740
|
+
```
|
741
|
+
|
742
|
+
### Database management
|
743
|
+
|
744
|
+
``` ruby
|
745
|
+
myUser.databases # Check permission Databases
|
746
|
+
myUser.grant database: "MyDatabase" # Grant access to a database
|
747
|
+
myUser.revoke database: "MyDatabase" # Revoke access to a database
|
748
|
+
```
|
749
|
+
|
750
|
+
<a name="ArangoIndex"></a>
|
751
|
+
## ArangoIndex
|
752
|
+
|
753
|
+
ArangoIndex manages the indexes.
|
754
|
+
To initialize an index:
|
755
|
+
|
756
|
+
``` ruby
|
757
|
+
myIndex = ArangoIndex.new fields: "num", unique: false, id: "myIndex"
|
758
|
+
```
|
759
|
+
|
760
|
+
### Index management
|
761
|
+
|
762
|
+
``` ruby
|
763
|
+
myIndex.retrieve # Retrieve Index
|
764
|
+
myIndex.create # Create a new Index
|
765
|
+
ArangoIndex.indexes collection: "MyCollection" # List indexes
|
766
|
+
myIndex.destroy # Delete Index
|
767
|
+
```
|
768
|
+
|
769
|
+
Alternatively, you can create an Index of a Collection directly from its Collection.
|
770
|
+
|
771
|
+
``` ruby
|
772
|
+
myCollection.createIndex unique: false, fields: "num", type: "hash"
|
773
|
+
```
|
774
|
+
|
775
|
+
<a name="ArangoTransaction"></a>
|
776
|
+
## ArangoTransaction
|
777
|
+
|
778
|
+
Transactions are managed by ArangoTransaction. This class has only initialization and execution.
|
779
|
+
|
780
|
+
``` ruby
|
781
|
+
myArangoTransaction = ArangoTransaction.new action: "function(){ var db = require('@arangodb').db; db.MyCollection.save({}); return db.MyCollection.count(); }", write: myCollection # Or read
|
782
|
+
myArangoTransaction.execute # Return the result of the execution
|
783
|
+
```
|
784
|
+
|
785
|
+
<a name="ArangoTask"></a>
|
786
|
+
## ArangoTask
|
787
|
+
|
788
|
+
Tasks are managed by ArangoTask.
|
789
|
+
|
790
|
+
``` ruby
|
791
|
+
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
|
792
|
+
myArangoTask.create # Create a new Task
|
793
|
+
ArangoTask.tasks # Retrieve a list of active tasks
|
794
|
+
myArangoTask.retrieve # Retrieve a Task
|
795
|
+
myArangoTask.destroy # Delete a Task
|
796
|
+
```
|