Class: SandthornDriverSequel2::EventAccess
- Inherits:
-
Access::Base
- Object
- Access::Base
- SandthornDriverSequel2::EventAccess
- Defined in:
- lib/sandthorn_driver_sequel_2/access/event_access.rb
Instance Method Summary collapse
-
#after_snapshot(snapshot) ⇒ Object
Returns events that occurred after the given snapshot.
-
#aggregate_ids(aggregate_type: nil) ⇒ Object
Returns aggregate ids.
- #find_events_by_aggregate_id(aggregate_id) ⇒ Object
- #get_events(*args) ⇒ Object
-
#store_events(events) ⇒ Object
EventAccess Reads and writes events.
Methods inherited from Access::Base
Constructor Details
This class inherits a constructor from SandthornDriverSequel2::Access::Base
Instance Method Details
#after_snapshot(snapshot) ⇒ Object
Returns events that occurred after the given snapshot
34 35 36 37 38 39 40 |
# File 'lib/sandthorn_driver_sequel_2/access/event_access.rb', line 34 def after_snapshot(snapshot) _aggregate_version = snapshot.aggregate_version aggregate_id = snapshot.aggregate_id wrap(storage.events .where(aggregate_id: aggregate_id) .where { aggregate_version > _aggregate_version }.all) end |
#aggregate_ids(aggregate_type: nil) ⇒ Object
Returns aggregate ids.
50 51 52 53 54 55 56 |
# File 'lib/sandthorn_driver_sequel_2/access/event_access.rb', line 50 def aggregate_ids(aggregate_type: nil) events = storage.events if aggregate_type events = events.where(aggregate_type: aggregate_type.to_s) end events.select_map(:aggregate_id).uniq end |
#find_events_by_aggregate_id(aggregate_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sandthorn_driver_sequel_2/access/event_access.rb', line 16 def find_events_by_aggregate_id(aggregate_id) #aggregate_version = Sequel.qualify(storage.events_table_name, :aggregate_version) #aggregate_aggregate_id = Sequel.qualify(storage.aggregates_table_name, :aggregate_id) #events_aggregate_id = Sequel.qualify(storage.events_table_name, :aggregate_id) wrap(storage.events.where(:aggregate_id => aggregate_id) .select( :sequence_number, :aggregate_id, :aggregate_version, :aggregate_type, :event_name, :event_data, :timestamp) .order(:sequence_number) .all) end |
#get_events(*args) ⇒ Object
42 43 44 45 46 |
# File 'lib/sandthorn_driver_sequel_2/access/event_access.rb', line 42 def get_events(*args) query_builder = EventQuery.new(storage) query_builder.build(*args) wrap(query_builder.events) end |
#store_events(events) ⇒ Object
EventAccess
Reads and writes events.
6 7 8 9 10 11 12 13 14 |
# File 'lib/sandthorn_driver_sequel_2/access/event_access.rb', line 6 def store_events(events) events = Utilities.array_wrap(events) = Time.now.utc events.each do |event| store_event(, event) end #puts aggregate.inspect # aggregate.save end |