class SandthornDriverSequel::EventStore

Attributes

context[R]
driver[R]

Public Class Methods

from_url(url, configuration, context = nil) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 18
def self.from_url url, configuration, context = nil
  new(SequelDriver.new(url: url), configuration, context)
end
new(connection, configuration, context = nil) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 11
def initialize connection, configuration, context = nil
  @driver = connection
  @context = context
  @event_serializer = configuration.event_serializer
  @event_deserializer = configuration.event_deserializer
end

Public Instance Methods

all(aggregate_type) click to toggle source

get methods

# File lib/sandthorn_driver_sequel/event_store.rb, line 33
def all aggregate_type
  return get_aggregate_ids(aggregate_type: aggregate_type).map do |id|
    aggregate_events(id)
  end
end
find(aggregate_id, aggregate_type, after_aggregate_version = 0) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 39
def find aggregate_id, aggregate_type, after_aggregate_version = 0
  aggregate_events(aggregate_id, after_aggregate_version)
end
get_events(*args) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 43
def get_events(*args)
  driver.execute do |db|
    event_access = get_event_access(db)
    event_access.get_events(*args)
  end
end
save_events(events, aggregate_id, class_name) click to toggle source

save methods

# File lib/sandthorn_driver_sequel/event_store.rb, line 23
def save_events events, aggregate_id, class_name
  driver.execute_in_transaction do |db|
    aggregates = get_aggregate_access(db)
    event_access = get_event_access(db)
    aggregate = aggregates.find_or_register(aggregate_id, class_name)
    event_access.store_events(aggregate, events)
  end
end

Private Instance Methods

aggregate_events(aggregate_id, after_aggregate_version = 0) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 52
def aggregate_events(aggregate_id, after_aggregate_version = 0)
  driver.execute do |db|
    event_access = get_event_access(db)
    event_access.find_events_by_aggregate_id(aggregate_id, after_aggregate_version)
  end
end
get_aggregate_access(db) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 66
def get_aggregate_access(db)
  @aggregate_access ||= AggregateAccess.new(storage(db))
end
get_aggregate_ids(aggregate_type: nil) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 59
def get_aggregate_ids(aggregate_type: nil)
  driver.execute do |db|
    access = get_aggregate_access(db)
    access.aggregate_ids(aggregate_type: aggregate_type)
  end
end
get_event_access(db) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 70
def get_event_access(db)
  @event_access ||= EventAccess.new(storage(db), @event_serializer, @event_deserializer)
end
storage(db) click to toggle source
# File lib/sandthorn_driver_sequel/event_store.rb, line 74
def storage(db)
  @storage ||= Storage.new(db, @context)
end