entity_store_sequel 0.2.2 → 0.3.0

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
  SHA256:
3
- metadata.gz: c42131de7211c31322b1b2756dffc2d4618bc4f7acdedea190613e6838b42eef
4
- data.tar.gz: 389dcf4874fb1469e58533dbbee84839b628c91409611342e17f93177305ed96
3
+ metadata.gz: 8e81c642170575ae02a6faf8f0ec2c4fe71bf4b00eb2fabfd5f9f8099fdb5bd6
4
+ data.tar.gz: 5b0463a52fc3b0382f6d083ad087c353753214a01b1e17220cd61f769aa4e058
5
5
  SHA512:
6
- metadata.gz: c3a3b060c3098f60d88991fb7282506a1aa54a82e3ddb967388bfcbcd0530f5c10305d2c13cc72848fc7553f8c91fc671a818db771c8512a75dbfbb5cec6e56b
7
- data.tar.gz: 9eb6147831a2e4ff174d6b0b30ab52d5231e9642b7bb4f900cc3f0964134598bdaa2727ad446a3c46892f45fe31ab23bf8dfe237a6535188b0fc233c97b1e116
6
+ metadata.gz: 727a2f7db49b844f065e25dda18433916a9a5b8773e936ce7cb5ee6c068c3ff238a242aba7548d03b8d8af8e4de1bd4193a81642fe967c3fbe222ee2ef44ad7f
7
+ data.tar.gz: a999ecfe3f45f38fc16250f81fb64e73d06e480d753562eca0ce40d900d06c1349f17bd949312c343f4b42cce8d2818ab42c1ec8822c7818ea1e030e7018cb3e
@@ -129,20 +129,42 @@ module EntityStoreSequel
129
129
  add_events_with_ids(events_with_id)
130
130
  end
131
131
 
132
+ def upsert_events(items)
133
+ events_with_id = items.map do |e|
134
+ [ e._id, e ]
135
+ end
136
+
137
+ filtered_events = []
138
+ events_with_id.each do |id, event|
139
+ next if events.where(id: id.to_s).count > 0
140
+
141
+ filtered_events << event
142
+
143
+ doc = event_doc(id, event)
144
+ events.insert(doc)
145
+ end
146
+
147
+ filtered_events
148
+ end
149
+
132
150
  def add_events_with_ids(event_id_map)
133
151
  event_id_map.each do |id, event|
134
- doc = {
135
- :id => id.to_s,
136
- :_type => event.class.name,
137
- :_entity_id => event.entity_id.to_s,
138
- :entity_version => event.entity_version,
139
- :at => event.attributes[:at],
140
- :data => PigeonHole.generate(hash_without_keys(event.attributes, :entity_id, :at, :entity_version)),
141
- }
152
+ doc = event_doc(id, event)
142
153
  events.insert(doc)
143
154
  end
144
155
  end
145
156
 
157
+ def event_doc(id, event)
158
+ {
159
+ :id => id.to_s,
160
+ :_type => event.class.name,
161
+ :_entity_id => event.entity_id.to_s,
162
+ :entity_version => event.entity_version,
163
+ :at => event.attributes[:at],
164
+ :data => PigeonHole.generate(hash_without_keys(event.attributes, :entity_id, :at, :entity_version, :_id)),
165
+ }
166
+ end
167
+
146
168
  # Public: loads the entity from the store, including any available snapshots
147
169
  # then loads the events to complete the state
148
170
  #
@@ -259,6 +281,25 @@ module EntityStoreSequel
259
281
 
260
282
  private
261
283
 
284
+ def get_raw_events(entity_id)
285
+ rows = events.where(:_entity_id => entity_id).order_by(:entity_version, :id)
286
+ rows.map do |attrs|
287
+ if self.class.native_json_hash
288
+ hash = attrs[:data].to_h
289
+ else
290
+ hash = PigeonHole.parse(attrs[:data])
291
+ end
292
+
293
+ hash[:_id] = attrs[:id]
294
+ hash[:_type] = attrs[:_type]
295
+ hash[:entity_version] = attrs[:entity_version]
296
+ hash[:entity_id] = attrs[:_entity_id]
297
+ hash[:at] = attrs[:at]
298
+
299
+ hash
300
+ end
301
+ end
302
+
262
303
  def filter_method_name(index)
263
304
  index == 0 ? :where : :or
264
305
  end
@@ -1,3 +1,3 @@
1
1
  module EntityStoreSequel
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Binns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -116,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.4
119
+ rubygems_version: 3.0.3
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: Sequel body for Entity Store