arangorb 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db23869df50a9624a7f54598b85fdc08b776fb6c
4
- data.tar.gz: e4cd9e680e9f71b40357b7d4bc08f3f397f63982
3
+ metadata.gz: b9083016d3d65b87f4f4b039e1b1a8c294e92fb8
4
+ data.tar.gz: 4edf6c5fb4644ec569172b3e5291b445a4c9945c
5
5
  SHA512:
6
- metadata.gz: 4149062e4f5b9a3883769c54b2ba889b672477773ef60fd9364a72648519054aa79ae28ef8ba8a76597a374a07de434175f669084e5d6d68bc56aa091e60ae61
7
- data.tar.gz: a2ae7171adcb75443f86d4522940615d3220dd50f08e672b1e5699fe0a700651cf712073ca5a7ac0a7b71fb5a20cd90c4e3c264820edc4aa4a0b3beace5dd25f
6
+ metadata.gz: 3b19660e6341a311663c7106ec0d4665c24afcd9cf5400a8f34ece5467ef95a299bb745a8ee5a64fee181efd92a5d5b367b17525c6dfb44775476c90c7277dbe
7
+ data.tar.gz: 4e128d0d611404a35591867dce29402c5d24534f4361070fbd105fbac60b7f4a09a4ba3670dff3c380e0c841377420bb5493abb7f01b92105e81429edb398a01
data/ArangoRB.gemspec CHANGED
@@ -4,13 +4,13 @@ require "rake"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'arangorb'
7
- s.version = '1.1.0'
7
+ s.version = '1.2.0'
8
8
  s.authors = ['Stefano Martin']
9
9
  s.email = ['stefano@seluxit.com']
10
10
  s.homepage = 'https://github.com/StefanoMartin/ArangoRB'
11
11
  s.license = 'MIT'
12
12
  s.summary = 'A simple ruby client for ArangoDB'
13
- s.description = "ArangoDB is a powerful mixed database based on documents and graphs. ArangoRB is an experimental Ruby gems that uses ArangoDB's HTTP API."
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
14
  s.platform = Gem::Platform::RUBY
15
15
  s.require_paths = ['lib']
16
16
  s.files = FileList['lib/*', 'spec/**/*', 'ArangoRB.gemspec', 'Gemfile', 'LICENSE', 'README.md'].to_a
data/README.md CHANGED
@@ -29,6 +29,7 @@ ArangoRB has the following classes.
29
29
  * [ArangoIndex](#ArangoIndex): to manage Indexes
30
30
  * [ArangoTask](#ArangoTask): to manage Tasks
31
31
  * [ArangoTransaction](#ArangoTransaction): to manage Transactions
32
+ * [ArangoCache](#ArangoCache): to manage a cache on your Computer
32
33
 
33
34
  <a name="ArangoServer"></a>
34
35
  ## ArangoServer
@@ -239,9 +240,9 @@ myDatabase.functions # Obtain an Array with the available functions in the sele
239
240
  It is possible to access its Collections and Graphs by their ids.
240
241
 
241
242
  ``` ruby
242
- myDatabase["MyCollection"] # where "MyCollection" is the id of the collection
243
- myDatabase.collection("MyCollection")
244
- myDatabase.graph("MyGraph")
243
+ myDatabase["MyCollection"].retrieve # where "MyCollection" is the id of the collection
244
+ myDatabase.collection("MyCollection").retrieve
245
+ myDatabase.graph("MyGraph").retrieve
245
246
  ```
246
247
 
247
248
 
@@ -281,26 +282,26 @@ myDatabase.functions # Retrieve a list of the available functions
281
282
  You can manage the right of a user to access the database.
282
283
 
283
284
  ``` ruby
284
- @myDatabase.grant user: myUser # Grant access to database
285
- @myDatabase.revoke user: myUser # Revoke access to database
285
+ myDatabase.grant user: myUser # Grant access to database
286
+ myDatabase.revoke user: myUser # Revoke access to database
286
287
  ```
287
288
 
288
289
  ### Replication (UNTESTED)
289
290
 
290
291
  ``` ruby
291
- @myDatabase.inventory # Returns an overview of collections and their indexes
292
- @myDatabase.clusterInventory # Return cluster inventory of collections and indexes
293
- @myDatabase.logger # Return replication logger state
294
- @myDatabase.loggerFollow # Returns log entries
295
- @myDatabase.firstTick # Returns the first available tick value
296
- @myDatabase.rangeTick # Return the tick ranges available in the WAL logfiles
297
- @myDatabase.sync # Synchronize data from a remote endpoint
298
- @myDatabase.configurationReplication # Return configuration of replication applier
299
- @myDatabase.modifyConfigurationReplication # Adjust configuration of replication applier
300
- @myDatabase.startReplication # Start replication applier
301
- @myDatabase.stateReplication # State of the replication applier
302
- @myDatabase.stopReplication # Stop replication applier
303
- @myDatabase.enslave # Turn the server into a slave of another
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
304
305
  ```
305
306
 
306
307
  <a name="ArangoCollection"></a>
@@ -819,3 +820,48 @@ ArangoTask.tasks # Retrieve a list of active tasks
819
820
  myArangoTask.retrieve # Retrieve a Task
820
821
  myArangoTask.destroy # Delete a Task
821
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.
data/lib/ArangoRB_AQL.rb CHANGED
@@ -28,10 +28,11 @@ class ArangoAQL < ArangoServer
28
28
  @hasMore = false
29
29
  @id = ""
30
30
  @result = []
31
+ @idCache = "AQL_#{@query}"
31
32
  end
32
33
 
33
34
  attr_accessor :query, :batchSize, :ttl, :cache, :options, :bindVars
34
- attr_reader :count, :count, :hasMore, :id, :result
35
+ attr_reader :count, :count, :hasMore, :id, :result, :idCache
35
36
  alias size batchSize
36
37
  alias size= batchSize=
37
38
 
@@ -0,0 +1,174 @@
1
+ # ==== CACHE ====
2
+
3
+ class ArangoCache
4
+ @max = {
5
+ "Database" => 1,
6
+ "Collection" => 20,
7
+ "Document" => 200,
8
+ "Graph" => 1,
9
+ "Vertex" => 50,
10
+ "Edge" => 100,
11
+ "Index" => 20,
12
+ "AQL" => 100,
13
+ "User" => 50,
14
+ "Task" => 20,
15
+ "Traversal" => 20,
16
+ "Transaction" => 20,
17
+ "Other" => 100
18
+ }
19
+ @cache = {
20
+ "Database" => {},
21
+ "Collection" => {},
22
+ "Document" => {},
23
+ "Graph" => {},
24
+ "Vertex" => {},
25
+ "Edge" => {},
26
+ "Index" => {},
27
+ "AQL" => {},
28
+ "User" => {},
29
+ "Task" => {},
30
+ "Traversal" => {},
31
+ "Transaction" => {},
32
+ "Other" => {}
33
+ }
34
+
35
+ class << self
36
+ attr_accessor :max
37
+
38
+ def max(type:, val:)
39
+ return nil if @max[type].nil?
40
+ while @cache[type].length > val
41
+ @cache[type].shift
42
+ end
43
+ @max[type] = val
44
+ end
45
+
46
+ def retrieve
47
+ @cache
48
+ end
49
+
50
+ def cache(id: nil, data:)
51
+ val_to_cache = []
52
+ data = [data] unless data.is_a? Array
53
+
54
+ if id.nil?
55
+ data.each do |d|
56
+ type = d.class.to_s
57
+ type.slice! "Arango"
58
+ if @max[type].nil?
59
+ type = "Other"
60
+ idCache = "OTH_#{d.class.to_s}_#{Random.rand(10^12)}"
61
+ else
62
+ idCache = d.idCache
63
+ end
64
+ val_to_cache << [type, idCache, d]
65
+ end
66
+ else
67
+ id = [id] unless id.is_a? Array
68
+ if data.length == id.length
69
+ for i in 0...id.length
70
+ type = data[i].class.to_s
71
+ type.slice! "Arango"
72
+ type = "Other" if @max[type].nil?
73
+ val_to_cache << [type, id[i], data[i]]
74
+ end
75
+ else
76
+ return "Id should be a String or an Array with the same size of the Data Array"
77
+ end
78
+ end
79
+
80
+ val_to_cache.each do |val|
81
+ @cache[val[0]][val[1]] = val[2]
82
+ @cache[val[0]].shift if @cache[val[0]].length > @max[val[0]]
83
+ end
84
+
85
+ val_to_cache
86
+ end
87
+
88
+ def uncache(type: nil, id: nil, data: nil)
89
+ if id.nil? && data.nil? && !type.nil?
90
+ val_to_uncache = @cache[type].map{|k,v| v}
91
+ val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
92
+ return val_to_uncache
93
+ end
94
+
95
+ val_to_uncache = []
96
+ unless data.nil?
97
+ data = [data] unless data.is_a? Array
98
+ data.each do |d|
99
+ type = d.class.to_s
100
+ type.slice! "Arango"
101
+ next if @max[type].nil? || type == "Other"
102
+ idCache = d.idCache
103
+ val_to_uncache << [type, idCache]
104
+ end
105
+ end
106
+ unless type.nil? || id.nil?
107
+ id = [id] unless id.is_a? Array
108
+ if type.is_a? Array
109
+ if type.length == id.length
110
+ for i in 0...type.length
111
+ val_to_uncache << [type[i], id[i]]
112
+ end
113
+ else
114
+ return "Type should be a String or an Array with the same size of the Id Array"
115
+ end
116
+ elsif type.is_a? String
117
+ id.each do |idCache|
118
+ val_to_uncache << [type, idCache]
119
+ end
120
+ else
121
+ return "Type should be a String or an Array with the same size of the Id Array"
122
+ end
123
+ end
124
+ val_to_uncache = val_to_uncache.map{|val| @cache[val[0]][val[1]]}
125
+ val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
126
+ val_to_uncache
127
+ end
128
+
129
+ def clear(type: nil, id: nil, data: nil)
130
+ if type.nil? && id.nil? && data.nil?
131
+ @cache = { "Database" => {}, "Collection" => {}, "Document" => {}, "Graph" => {}, "Vertex" => {}, "Edge" => {}, "Index" => {}, "Query" => {},"User" => {}, "Traversal" => {}, "Transaction" => {} }
132
+ return true
133
+ end
134
+
135
+ if !type.nil? && id.nil? && data.nil?
136
+ @cache[type] = {}
137
+ return true
138
+ end
139
+
140
+ val_to_clear = []
141
+ unless data.nil?
142
+ data = [data] unless data.is_a? Array
143
+ data.each do |d|
144
+ type = d.class.to_s
145
+ type.slice! "Arango"
146
+ next if @max[type].nil? || type == "Other"
147
+ val_to_clear << [type, d.idCache]
148
+ end
149
+ end
150
+
151
+ unless type.nil? || id.nil?
152
+ id = [id] unless id.is_a? Array
153
+ if type.is_a? Array
154
+ if type.length == id.length
155
+ for i in 0...type.length
156
+ val_to_clear << [type[i], id[i]]
157
+ end
158
+ else
159
+ return "Type should be a String or an Array with the same size of the Id Array"
160
+ end
161
+ elsif type.is_a? String
162
+ id.each do |idCache|
163
+ val_to_clear << [type, idCache]
164
+ end
165
+ else
166
+ return "Type should be a String or an Array with the same size of the Id Array"
167
+ end
168
+ end
169
+
170
+ val_to_clear.each{|val| @cache[val[0]].delete(val[1])}
171
+ true
172
+ end
173
+ end
174
+ end
data/lib/ArangoRB_Col.rb CHANGED
@@ -34,9 +34,10 @@ class ArangoCollection < ArangoServer
34
34
  @body["type"] = 3
35
35
  end
36
36
  end
37
+ @idCache = "COL_#{@collection}"
37
38
  end
38
39
 
39
- attr_reader :collection, :body, :type
40
+ attr_reader :collection, :body, :type, :idCache
40
41
  alias name collection
41
42
 
42
43
  # === RETRIEVE ===
data/lib/ArangoRB_DB.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  # === DATABASE ===
2
2
 
3
3
  class ArangoDatabase < ArangoServer
4
+ @isSystem = false
5
+ @path = nil
6
+ @id = nil
7
+
4
8
  def initialize(database: @@database) # TESTED
5
9
  if database.is_a?(String)
6
10
  @database = database
@@ -9,9 +13,10 @@ class ArangoDatabase < ArangoServer
9
13
  else
10
14
  raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
11
15
  end
16
+ @idCache = "DB_#{@database}"
12
17
  end
13
18
 
14
- attr_reader :database # TESTED
19
+ attr_reader :database, :isSystem, :path, :id, :idCache # TESTED
15
20
  alias name database
16
21
 
17
22
  # === RETRIEVE ===
@@ -34,6 +39,16 @@ class ArangoDatabase < ArangoServer
34
39
  @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].delete_if{|k,v| k == "error" || k == "code"}
35
40
  end
36
41
 
42
+ def retrieve # TESTED
43
+ result = self.class.get("/_db/#{@database}/_api/database/current", @@request)
44
+ return result.headers["x-arango-async-id"] if @@async == "store"
45
+ result = result.parsed_response
46
+ @isSystem = result["isSystem"]
47
+ @path = result["path"]
48
+ @id = result["id"]
49
+ @@verbose ? result : result["error"] ? result["errorMessage"] : self
50
+ end
51
+
37
52
  # === POST ===
38
53
 
39
54
  def create(username: nil, passwd: nil, users: nil) # TESTED
data/lib/ArangoRB_Doc.rb CHANGED
@@ -54,9 +54,11 @@ class ArangoDocument < ArangoServer
54
54
  else
55
55
  raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
56
56
  end
57
+
58
+ @idCache = "DOC_#{@id}"
57
59
  end
58
60
 
59
- attr_reader :key, :id, :body
61
+ attr_reader :key, :id, :body, :idCache
60
62
  alias name key
61
63
 
62
64
  # === RETRIEVE ===
data/lib/ArangoRB_Edg.rb CHANGED
@@ -62,9 +62,11 @@ class ArangoEdge < ArangoDocument
62
62
  else
63
63
  raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
64
64
  end
65
+
66
+ @idCache = "EDG_#{@id}"
65
67
  end
66
68
 
67
- attr_reader :key, :id, :body
69
+ attr_reader :key, :id, :body, :idCache
68
70
 
69
71
  # === RETRIEVE ===
70
72
 
data/lib/ArangoRB_Gra.rb CHANGED
@@ -29,9 +29,11 @@ class ArangoGraph < ArangoServer
29
29
  else
30
30
  raise "orphanCollections should be an Array, not a #{orphanCollections.class}"
31
31
  end
32
+
33
+ @idCache = "GRA_#{@graph}"
32
34
  end
33
35
 
34
- attr_reader :graph, :edgeDefinitions, :orphanCollections, :database
36
+ attr_reader :graph, :edgeDefinitions, :orphanCollections, :database, :idCache
35
37
  alias name graph
36
38
 
37
39
  # === RETRIEVE ===
@@ -39,9 +39,11 @@ class ArangoIndex < ArangoServer
39
39
  else
40
40
  raise "fields should be a String or an Array, not a #{database.class}"
41
41
  end
42
+
43
+ @idCache = "IND_#{@id}"
42
44
  end
43
45
 
44
- attr_reader :body, :type, :id, :unique, :fields, :key, :sparse
46
+ attr_reader :body, :type, :id, :unique, :fields, :key, :sparse, :idCache
45
47
 
46
48
  ### RETRIEVE ###
47
49
 
data/lib/ArangoRB_Task.rb CHANGED
@@ -16,9 +16,10 @@ class ArangoTask < ArangoServer
16
16
  @command = command
17
17
  @params = params
18
18
  @created = created
19
+ @idCache = "IND_#{@id}"
19
20
  end
20
21
 
21
- attr_reader :id, :name, :type, :period, :created, :command, :params
22
+ attr_reader :id, :name, :type, :period, :created, :command, :params, :idCache
22
23
 
23
24
  def database
24
25
  ArangoDatabase.new(database: @database)
data/lib/ArangoRB_Tra.rb CHANGED
@@ -21,9 +21,11 @@ class ArangoTraversal < ArangoServer
21
21
  @database = database
22
22
  @vertices = nil
23
23
  @paths = nil
24
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
24
25
  end
25
26
 
26
- attr_accessor :sort, :direction, :maxDepth, :minDepth, :visitor, :itemOrder, :strategy, :filter, :init, :maxiterations, :uniqueness, :order, :expander, :vertices, :paths
27
+ attr_accessor :sort, :direction, :maxDepth, :minDepth, :visitor, :itemOrder, :strategy, :filter, :init, :maxiterations, :uniqueness, :order, :expander
28
+ attr_reader :idCache, :vertices, :paths
27
29
 
28
30
  ### RETRIEVE ###
29
31
 
@@ -52,6 +54,7 @@ class ArangoTraversal < ArangoServer
52
54
  else
53
55
  raise "startVertex should be a String or an ArangoDocument instance, not a #{startVertex.class}"
54
56
  end
57
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
55
58
  end
56
59
 
57
60
  def graphName=(graphName) # TESTED
@@ -62,6 +65,7 @@ class ArangoTraversal < ArangoServer
62
65
  else
63
66
  raise "graphName should be a String or an ArangoGraph instance, not a #{graphName.class}"
64
67
  end
68
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
65
69
  end
66
70
 
67
71
  def edgeCollection=(edgeCollection) # TESTED
@@ -72,18 +76,22 @@ class ArangoTraversal < ArangoServer
72
76
  else
73
77
  raise "edgeCollection should be a String or an ArangoCollection instance, not a #{edgeCollection.class}"
74
78
  end
79
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
75
80
  end
76
81
 
77
82
  def in # TESTED
78
83
  @direction = "inbound"
84
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
79
85
  end
80
86
 
81
87
  def out # TESTED
82
88
  @direction = "outbound"
89
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
83
90
  end
84
91
 
85
92
  def any # TESTED
86
93
  @direction = "any"
94
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
87
95
  end
88
96
 
89
97
  alias vertex= startVertex=
@@ -128,6 +136,7 @@ class ArangoTraversal < ArangoServer
128
136
  "vertices" => x["vertices"].map{|v| ArangoDocument.new(key: v["_key"], collection: v["_id"].split("/")[0], database: @database, body: v )}
129
137
  }
130
138
  }
139
+ @idCache = "ATR_#{@database}_#{@direction}_#{@startVertex}_" + (@graphName.nil? ? "#{@edgeCollection}" : "#{@graphName}")
131
140
  @@verbose ? result : self
132
141
  end
133
142
  end
data/lib/ArangoRB_Tran.rb CHANGED
@@ -16,9 +16,11 @@ class ArangoTransaction < ArangoServer
16
16
  @params = params
17
17
  @lockTimeout = lockTimeout
18
18
  @waitForSync = waitForSync
19
+ @result = nil
20
+ @idCache = "AT_#{@database}_#{Random.rand(0..10^12)}"
19
21
  end
20
22
 
21
- attr_reader :action, :params, :lockTimeout, :waitForSync
23
+ attr_reader :action, :params, :lockTimeout, :waitForSync, :idCache
22
24
 
23
25
  ### RETRIEVE ###
24
26
 
@@ -45,6 +47,7 @@ class ArangoTransaction < ArangoServer
45
47
  result = self.class.post("/_db/#{@database}/_api/transaction", request)
46
48
  return result.headers["x-arango-async-id"] if @@async == "store"
47
49
  result = result.parsed_response
50
+ @result = result["result"] unless result["error"]
48
51
  @@verbose ? result : result["error"] ? {"message": result["errorMessage"], "stacktrace": result["stacktrace"]} : result["result"]
49
52
  end
50
53
  end
data/lib/ArangoRB_User.rb CHANGED
@@ -6,9 +6,10 @@ class ArangoUser < ArangoServer
6
6
  @user = user
7
7
  @active = active
8
8
  @extra = extra
9
+ @idCache = "USER_#{@user}"
9
10
  end
10
11
 
11
- attr_reader :user, :active, :extra
12
+ attr_reader :user, :active, :extra, :idCache
12
13
  alias name user
13
14
 
14
15
  def [](database)
data/lib/ArangoRB_Ver.rb CHANGED
@@ -44,9 +44,10 @@ class ArangoVertex < ArangoDocument
44
44
  else
45
45
  raise "body should be a Hash, not a #{body.class}"
46
46
  end
47
+ @idCache = "VER_#{@id}"
47
48
  end
48
49
 
49
- attr_reader :key, :id, :body
50
+ attr_reader :key, :id, :body, :idCache
50
51
 
51
52
  # === RETRIEVE ===
52
53
 
data/lib/arangorb.rb CHANGED
@@ -12,3 +12,4 @@ require_relative "ArangoRB_User"
12
12
  require_relative "ArangoRB_Index"
13
13
  require_relative "ArangoRB_Task"
14
14
  require_relative "ArangoRB_Tran"
15
+ require_relative "ArangoRB_Cache"
@@ -1,3 +1,4 @@
1
1
  require "lib/arangoRB_0.1.0_helper"
2
2
  require "lib/arangoRB_1.0.0_helper"
3
3
  require "lib/arangoRB_1.1.0_helper"
4
+ require "lib/arangoRB_1.2.0_helper"
@@ -186,10 +186,6 @@ describe ArangoServer do
186
186
  # `sudo service arangodb restart`
187
187
  # expect(result).to eq "OK"
188
188
  # end
189
-
190
- # it "test" do
191
- # print ArangoServer.test body: {"num" => 1}
192
- # end
193
189
  end
194
190
 
195
191
 
@@ -3,6 +3,7 @@ require_relative './../../spec_helper'
3
3
  describe ArangoDatabase do
4
4
  context "#retrieve" do
5
5
  it "walk" do
6
+ print "\n"
6
7
  print "#{@myDatabase.name}\n"
7
8
  print "#{@myDatabase['MyCollection'].name}\n"
8
9
  print "#{@myDatabase['MyCollection'].documents.map{|x| x.name}}\n"
@@ -0,0 +1,66 @@
1
+ require_relative './../../spec_helper'
2
+
3
+ describe ArangoCache do
4
+ context "#cache" do
5
+ it "cache" do
6
+ @myDatabase.retrieve
7
+ @myCollection.retrieve
8
+ @myEdgeCollection.retrieve
9
+ @myGraph.retrieve
10
+ @myAQL.execute
11
+ @myVertex.retrieve
12
+ @myEdge.retrieve
13
+ @myIndex.retrieve
14
+ @myUser.retrieve
15
+ @myTask.retrieve
16
+ val = ArangoCache.cache data: [@myDatabase, @myCollection, @myEdgeCollection, @myGraph, @myAQL, @myVertex, @myEdge, @myIndex, @myUser, @myTask, [1,2,3]]
17
+ expect(val.length).to eq 11
18
+ end
19
+
20
+ it "cache with ID" do
21
+ myAQL2 = ArangoAQL.new query: "FOR u IN MyCollection RETURN u"
22
+ myAQL2.execute
23
+ ArangoCache.cache id: "myAQL", data: myAQL2
24
+ val = ArangoCache.uncache type: "AQL", id: "myAQL"
25
+ expect(val.result.length).to be > 0
26
+ end
27
+
28
+ it "uncache" do
29
+ val = ArangoCache.uncache data: [@myCollection, @myVertex]
30
+ val = val.map{|v| v.class.to_s}
31
+ expect(val).to eq ["ArangoCollection", "ArangoVertex"]
32
+ end
33
+ end
34
+
35
+ context "#limits" do
36
+ it "max" do
37
+ ArangoCache.cache data: @myDoc
38
+ val = ArangoCache.retrieve["Document"]
39
+ ArangoCache.max type: "Document", val: 5
40
+ ArangoCache.retrieve["Document"]
41
+ ArangoCache.cache data: @myDoc[0]
42
+ val = ArangoCache.uncache type: "Document"
43
+ expect(val.length).to eq 5
44
+ end
45
+ end
46
+
47
+ context "#clear" do
48
+ it "clear object" do
49
+ ArangoCache.clear data: @myCollection
50
+ val = ArangoCache.uncache data: @myCollection
51
+ expect(val.nil?).to be true
52
+ end
53
+
54
+ it "clear type" do
55
+ ArangoCache.clear type: "Vertex"
56
+ val = ArangoCache.retrieve
57
+ expect(val["Vertex"].empty?).to be true
58
+ end
59
+
60
+ it "clear type" do
61
+ ArangoCache.clear
62
+ val = ArangoCache.retrieve
63
+ expect(val["Database"].empty?).to be true
64
+ end
65
+ end
66
+ end
@@ -0,0 +1 @@
1
+ require "lib/1.2.0/arangoCache_helper"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arangorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,8 +30,8 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.14.0
33
- description: ArangoDB is a powerful mixed database based on documents and graphs.
34
- ArangoRB is an experimental Ruby gems that uses ArangoDB's HTTP API.
33
+ description: ArangoRB is an experimental Ruby gems based on ArangoDB's HTTP API. ArangoDB
34
+ is a powerful mixed database based on documents and graphs
35
35
  email:
36
36
  - stefano@seluxit.com
37
37
  executables: []
@@ -43,6 +43,7 @@ files:
43
43
  - LICENSE
44
44
  - README.md
45
45
  - lib/ArangoRB_AQL.rb
46
+ - lib/ArangoRB_Cache.rb
46
47
  - lib/ArangoRB_Col.rb
47
48
  - lib/ArangoRB_DB.rb
48
49
  - lib/ArangoRB_Doc.rb
@@ -76,9 +77,11 @@ files:
76
77
  - spec/lib/1.0.0/arangoU_helper.rb
77
78
  - spec/lib/1.1.0/arangoRB_helper.rb
78
79
  - spec/lib/1.1.0/arangoRB_walks_helper.rb
80
+ - spec/lib/1.2.0/arangoCache_helper.rb
79
81
  - spec/lib/arangoRB_0.1.0_helper.rb
80
82
  - spec/lib/arangoRB_1.0.0_helper.rb
81
83
  - spec/lib/arangoRB_1.1.0_helper.rb
84
+ - spec/lib/arangoRB_1.2.0_helper.rb
82
85
  - spec/spec_helper.rb
83
86
  homepage: https://github.com/StefanoMartin/ArangoRB
84
87
  licenses: