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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e81c642170575ae02a6faf8f0ec2c4fe71bf4b00eb2fabfd5f9f8099fdb5bd6
|
4
|
+
data.tar.gz: 5b0463a52fc3b0382f6d083ad087c353753214a01b1e17220cd61f769aa4e058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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:
|
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
|
-
|
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
|