Class: SandthornDriverSequel2::Storage
- Inherits:
-
Object
- Object
- SandthornDriverSequel2::Storage
- Includes:
- EventStoreContext
- Defined in:
- lib/sandthorn_driver_sequel_2/storage.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Attributes included from EventStoreContext
Instance Method Summary collapse
-
#events ⇒ Object
Returns a Sequel::Model for accessing events.
- #events_table ⇒ Object
-
#initialize(db, context, events_file_path) ⇒ Storage
constructor
A new instance of Storage.
-
#snapshots ⇒ Object
Returns a Sequel::Model for accessing snapshots.
- #snapshots_table ⇒ Object
Methods included from EventStoreContext
#events_table_name, #snapshots_table_name, #with_context_if_exists
Constructor Details
#initialize(db, context, events_file_path) ⇒ Storage
13 14 15 16 17 18 19 20 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 13 def initialize(db, context, events_file_path) @db = db @context = context @event_file = File.open(events_file_path, "a") if events_file_path last_event = events_table.order(:sequence_number).limit(1).last last_sequence_number = last_event ? last_event[:sequence_number] : 0 @event_file_output_wrapper = FileOutputWrapper::Events.new @event_file, last_sequence_number if @event_file end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
11 12 13 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 11 def db @db end |
Instance Method Details
#events ⇒ Object
Returns a Sequel::Model for accessing events
23 24 25 26 27 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 23 def events agg = Class.new(Sequel::Model(events_table)) return @event_file_output_wrapper.events agg if @event_file agg end |
#events_table ⇒ Object
34 35 36 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 34 def events_table db[events_table_name] end |
#snapshots ⇒ Object
Returns a Sequel::Model for accessing snapshots
30 31 32 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 30 def snapshots Class.new(Sequel::Model(snapshots_table)) end |
#snapshots_table ⇒ Object
38 39 40 |
# File 'lib/sandthorn_driver_sequel_2/storage.rb', line 38 def snapshots_table db[snapshots_table_name] end |