@@ -231,12 +231,12 @@ def read_from_specific_stream(specification)
231
231
if specification . start
232
232
condition = "event_store_events_in_streams.id #{ specification . forward? ? ">" : "<" } ?"
233
233
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 ) ) )
235
235
end
236
236
237
237
if specification . stop
238
238
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 ) ) )
240
240
end
241
241
242
242
if specification . older_than
@@ -269,13 +269,24 @@ def read_from_specific_stream(specification)
269
269
dataset
270
270
end
271
271
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 ]
274
274
. select ( :id )
275
275
. 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 ]
279
290
end
280
291
281
292
def read_from_global_stream ( specification )
@@ -295,14 +306,14 @@ def read_from_global_stream(specification)
295
306
dataset = dataset . where ( event_id : specification . with_ids ) if specification . with_ids?
296
307
297
308
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 )
299
310
condition = "event_store_events.id #{ specification . forward? ? ">" : "<" } ?"
300
311
301
312
dataset = dataset . where ( ::Sequel . lit ( condition , id ) )
302
313
end
303
314
304
315
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 )
306
317
condition = "event_store_events.id #{ specification . forward? ? "<" : ">" } ?"
307
318
308
319
dataset = dataset . where ( ::Sequel . lit ( condition , id ) )
0 commit comments