Skip to content

Commit 117f817

Browse files
pjurewiczfidel
authored andcommitted
adjust also ruby_event_store-sequel
1 parent a5e365c commit 117f817

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ def read_from_specific_stream(specification)
231231
if specification.start
232232
condition = "event_store_events_in_streams.id #{specification.forward? ? ">" : "<"} ?"
233233
dataset =
234-
dataset.where(::Sequel.lit(condition, find_event_id(specification.start, specification.stream.name)))
234+
dataset.where(::Sequel.lit(condition, find_event_id_in_stream(specification.start, specification.stream.name)))
235235
end
236236

237237
if specification.stop
238238
condition = "event_store_events_in_streams.id #{specification.forward? ? "<" : ">"} ?"
239-
dataset = dataset.where(::Sequel.lit(condition, find_event_id(specification.stop, specification.stream.name)))
239+
dataset = dataset.where(::Sequel.lit(condition, find_event_id_in_stream(specification.stop, specification.stream.name)))
240240
end
241241

242242
if specification.older_than
@@ -269,13 +269,24 @@ def read_from_specific_stream(specification)
269269
dataset
270270
end
271271

272-
def find_event_id(specification_event_id, specification_stream_name)
273-
@db[:event_store_events_in_streams]
272+
def find_event_id_in_stream(specification_event_id, specification_stream_name)
273+
event = @db[:event_store_events_in_streams]
274274
.select(:id)
275275
.where(event_id: specification_event_id, stream: specification_stream_name)
276-
.first[
277-
:id
278-
]
276+
.first
277+
raise EventNotFound.new(specification_event_id) unless event
278+
279+
event[:id]
280+
end
281+
282+
def find_event_id_globally(specification_event_id)
283+
event = @db[:event_store_events]
284+
.select(:id)
285+
.where(event_id: specification_event_id)
286+
.first
287+
raise EventNotFound.new(specification_event_id) unless event
288+
289+
event[:id]
279290
end
280291

281292
def read_from_global_stream(specification)
@@ -295,14 +306,14 @@ def read_from_global_stream(specification)
295306
dataset = dataset.where(event_id: specification.with_ids) if specification.with_ids?
296307

297308
if specification.start
298-
id = @db[:event_store_events].select(:id).where(event_id: specification.start).first[:id]
309+
id = find_event_id_globally(specification.start)
299310
condition = "event_store_events.id #{specification.forward? ? ">" : "<"} ?"
300311

301312
dataset = dataset.where(::Sequel.lit(condition, id))
302313
end
303314

304315
if specification.stop
305-
id = @db[:event_store_events].select(:id).where(event_id: specification.stop).first[:id]
316+
id = find_event_id_globally(specification.stop)
306317
condition = "event_store_events.id #{specification.forward? ? "<" : ">"} ?"
307318

308319
dataset = dataset.where(::Sequel.lit(condition, id))

0 commit comments

Comments
 (0)