Skip to content

Commit 0e5c75c

Browse files
committed
Batches with bitemporal query test
1 parent 84c576b commit 0e5c75c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def read_from_global_stream(specification)
325325
)
326326
end
327327

328-
dataset = dataset.order(:created_at) if specification.time_sort_by_as_at?
328+
dataset = dataset.order(::Sequel[:event_store_events][:created_at]) if specification.time_sort_by_as_at?
329329
dataset = dataset.order(::Sequel.lit(coalesced_date)) if specification.time_sort_by_as_of?
330330
dataset = dataset.limit(specification.limit) if specification.limit?
331331
dataset = dataset.order(::Sequel[:event_store_events][:id]) unless specification.time_sort_by
@@ -335,7 +335,7 @@ def read_from_global_stream(specification)
335335
end
336336

337337
def coalesced_date
338-
"COALESCE(event_store_events.valid_at, event_store_events.created_at)"
338+
"COALESCE(`event_store_events`.`valid_at`, `event_store_events`.`created_at`)"
339339
end
340340

341341
def time_comparison_field(specification)

contrib/ruby_event_store-sequel/spec/event_repository_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,39 @@ module Sequel
155155
end
156156

157157

158+
specify "with batches and bi-temporal queries use offset + limit" do
159+
repository.append_to_stream(
160+
[
161+
SRecord.new(
162+
event_id: e1 = SecureRandom.uuid,
163+
timestamp: Time.new(2020, 1, 1),
164+
valid_at: Time.new(2020, 1, 9)
165+
),
166+
SRecord.new(
167+
event_id: e2 = SecureRandom.uuid,
168+
timestamp: Time.new(2020, 1, 3),
169+
valid_at: Time.new(2020, 1, 6)
170+
),
171+
SRecord.new(
172+
event_id: e3 = SecureRandom.uuid,
173+
timestamp: Time.new(2020, 1, 2),
174+
valid_at: Time.new(2020, 1, 3)
175+
)
176+
],
177+
Stream.new("Dummy"),
178+
ExpectedVersion.any
179+
)
180+
181+
expect {
182+
repository.read(specification.in_batches.as_at.result).to_a
183+
}.to match_query(%r{
184+
SELECT\s+(.*)\s+FROM\s+.event_store_events.\s+ORDER\s+BY\s+.event_store_events.\..created_at.\s+LIMIT.\d+\sOFFSET.\d+
185+
}x, 2)
186+
expect {
187+
repository.read(specification.in_batches.as_of.result).to_a
188+
}.to match_query(/SELECT.*FROM .*event_store_events.* ORDER BY COALESCE.*event_store_events.*valid_at.*event_store_events.*created_at.*LIMIT \d+ OFFSET \d+/,
189+
2)
190+
end
158191

159192
private
160193

0 commit comments

Comments
 (0)