entity_store_sequel 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3956cd44cc5c897c19cb96966e46e80e84f7e07
4
- data.tar.gz: 9a6703b7c60cfba40ef47cd61a844431dfd8c94a
3
+ metadata.gz: 1899036c5a8d1dddb1db7d3983403d52457b2f0f
4
+ data.tar.gz: 351364c47638483e1f5e9720d5a51587100cba99
5
5
  SHA512:
6
- metadata.gz: 698435ba4a53e4243fbae71ec7593fd279fe641ad1f703dc719bf17442e3cfdad333f12a10384f90b2af429ee3f2bdd79602584a19996baa3a5ce689fa160cb1
7
- data.tar.gz: 00fbf106ab1bbf35c64d280d92fe6b1d292bdff255de8f76bae8e93c833550d120d2e9b377f14c075c07ba62956a8a3d46ece3ab5a8e5f8c8ce0b46989290cd8
6
+ metadata.gz: 2ecacf83b990024c8d66f42c2b54a225361d02e061c7445d977380cad6edca430c6937dbaa479b92eb46b2daad599cac654e3672fa344c203006ae85ad2b5d01
7
+ data.tar.gz: 4384bb30c9f78e3f041a2a2a4a95c9747247acf866c190b9234da0f25be64de1cf6b98fe9eb71dba927864f4c78442bfec0238e12ea50c6c66a7e264291bcfc8
@@ -121,7 +121,7 @@ module EntityStoreSequel
121
121
  :_entity_id => event.entity_id.to_s,
122
122
  :entity_version => event.entity_version,
123
123
  :at => event.attributes[:at],
124
- :data => PigeonHole.generate(hash_without_keys(event.attributes, :entity_id, :at)),
124
+ :data => PigeonHole.generate(hash_without_keys(event.attributes, :entity_id, :at, :entity_version)),
125
125
  }
126
126
  events.insert(doc)
127
127
  end
@@ -195,18 +195,24 @@ module EntityStoreSequel
195
195
  def get_events(criteria)
196
196
  return {} if criteria.empty?
197
197
 
198
- result = {}
199
-
200
- criteria.each do |item|
201
- raise ArgumentError.new(":id missing from criteria") unless item[:id]
202
-
203
- query = events.where(:_entity_id => item[:id])
198
+ query = events
204
199
 
200
+ criteria.each_with_index do |item, i|
201
+ filter_method = filter_method_name(i)
205
202
  if item[:since_version]
206
- query = query.where('entity_version > ?', item[:since_version])
203
+ query = query.send(filter_method, '_entity_id = ? AND entity_version > ?', item[:id], item[:since_version])
204
+ else
205
+ query = query.send(filter_method, '_entity_id = ?', item[:id])
207
206
  end
207
+ end
208
+
209
+ result = query.to_hash_groups(:_entity_id)
210
+
211
+ result.each do |id, events|
212
+ events.sort_by! { |attrs| [attrs[:entity_version], attrs[:id].to_s] }
208
213
 
209
- result[item[:id]] = query.order(:entity_version, :id).map do |attrs|
214
+ # Convert the attributes into event objects
215
+ events.map! do |attrs|
210
216
  begin
211
217
  if self.class.native_json_hash
212
218
  hash = attrs[:data].to_h
@@ -221,9 +227,15 @@ module EntityStoreSequel
221
227
  EntityStore::Config.load_type(attrs[:_type]).new(hash)
222
228
  rescue => e
223
229
  log_error "Error loading type #{attrs[:_type]}", e
224
- next
230
+ nil
225
231
  end
226
- end.compact
232
+ end
233
+
234
+ events.compact!
235
+ end
236
+
237
+ criteria.each do |item|
238
+ result[item[:id].to_s] ||= []
227
239
  end
228
240
 
229
241
  result
@@ -231,6 +243,10 @@ module EntityStoreSequel
231
243
 
232
244
  private
233
245
 
246
+ def filter_method_name(index)
247
+ index == 0 ? :where : :or
248
+ end
249
+
234
250
  def hash_without_keys(hash, *keys)
235
251
  hash_dup = hash.dup
236
252
  keys.each { |key| hash_dup.delete(key) }
@@ -1,3 +1,3 @@
1
1
  module EntityStoreSequel
2
- VERSION = "0.0.8".freeze
2
+ VERSION = "0.0.9".freeze
3
3
  end
@@ -66,6 +66,24 @@ describe PostgresEntityStore do
66
66
  store.add_events([ second_event, unrelated_event, first_event, third_event, fourth_event ])
67
67
  end
68
68
 
69
+ context "multiple entities" do
70
+ subject { store.get_events( [{ id: event_entity_id }, { id: unknown_id }]) }
71
+
72
+ context "all events" do
73
+ let(:event_entity_id) { entity_id }
74
+ let(:unknown_id) { random_object_id }
75
+ let(:since_version) { 0 }
76
+
77
+ it "should return the four events in order for known id" do
78
+ subject[event_entity_id].should == [first_event, second_event, third_event, fourth_event]
79
+ end
80
+
81
+ it "should return no events in order unknown id" do
82
+ subject[unknown_id].should be_empty
83
+ end
84
+ end
85
+ end
86
+
69
87
  subject { store.get_events( [{ id: event_entity_id, since_version: since_version }])[event_entity_id] }
70
88
 
71
89
  context "all events" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entity_store_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Binns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 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: sequel