Class: SandthornDriverSequel2::SnapshotAccess
Instance Method Summary
collapse
#initialize
Instance Method Details
#find(snapshot_id) ⇒ Object
9
10
11
|
# File 'lib/sandthorn_driver_sequel_2/access/snapshot_access.rb', line 9
def find(snapshot_id)
storage.snapshots[snapshot_id]
end
|
#find_by_aggregate_id(aggregate_id) ⇒ Object
4
5
6
7
|
# File 'lib/sandthorn_driver_sequel_2/access/snapshot_access.rb', line 4
def find_by_aggregate_id(aggregate_id)
storage.snapshots.first(aggregate_id: aggregate_id)
end
|
#obsolete(aggregate_types: [], max_event_distance: 100) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/sandthorn_driver_sequel_2/access/snapshot_access.rb', line 21
def obsolete(aggregate_types: [], max_event_distance: 100)
aggregate_types.map!(&:to_s)
snapshot_version = Sequel.qualify(storage.snapshots_table_name, :aggregate_version)
aggregate_version = Sequel.qualify(storage.aggregates_table_name, :aggregate_version)
aggregate_id = Sequel.qualify(storage.aggregates_table_name, :aggregate_id)
query = storage.aggregates.left_outer_join(storage.snapshots, aggregate_id: :aggregate_id)
query = query.select { (aggregate_version - snapshot_version).as(distance) }
query = query.select_append(aggregate_id, :aggregate_type)
query = query.where { (aggregate_version - coalesce(snapshot_version, 0)) > max_event_distance }
if aggregate_types.any?
query = query.where(aggregate_type: aggregate_types)
end
query.all
end
|
#record_snapshot(aggregate_id, snapshot_data) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/sandthorn_driver_sequel_2/access/snapshot_access.rb', line 13
def record_snapshot(aggregate_id, snapshot_data)
previous_snapshot = find_by_aggregate_id(aggregate_id)
perform_snapshot(aggregate_id, previous_snapshot, snapshot_data)
end
|