def init_example_application_with_sqlalchemy():
    init_example_application(
        entity_record_manager=SQLAlchemyRecordManager(
            record_class=IntegerSequencedItem,
            session=db.session,
        )
    )
Пример #2
0
 def setup_event_store(self):
     super(SnapshottingApplication, self).setup_event_store()
     # Setup snapshot store, using datastore session, and SnapshotRecord class.
     # Todo: Refactor this into a new create_sqlalchemy_snapshotstore() function.
     self.snapshot_store = EventStore(
         SQLAlchemyRecordManager(session=self.datastore.session,
                                 record_class=self.snapshot_record_class
                                 or SnapshotRecord),
         SequencedItemMapper(sequence_id_attr_name='originator_id',
                             position_attr_name='originator_version'))
Пример #3
0
def create_event_store(db) -> EventStore:
    record_manager = SQLAlchemyRecordManager(session=db.session,
                                             sequenced_item_class=StoredEvent,
                                             record_class=StoredEventRecord,
                                             application_name="CompanyApp",
                                             contiguous_record_ids=True)
    event_mapper = SequencedItemMapper(sequenced_item_class=StoredEvent,
                                       cipher=cipher)
    event_store = EventStore(record_manager=record_manager,
                             event_mapper=event_mapper)
    return event_store
Пример #4
0
 def __init__(self, datastore):
     event_store = EventStore(
         record_manager=SQLAlchemyRecordManager(
             session=datastore.session,
             record_class=IntegerSequencedNoIDRecord),
         event_mapper=SequencedItemMapper(
             sequence_id_attr_name="originator_id",
             position_attr_name="originator_version",
         ),
     )
     self.repository = EventSourcedRepository(event_store=event_store)
     self.persistence_policy = PersistencePolicy(
         persist_event_type=ExampleAggregateRoot.Event,
         event_store=event_store)
 def __init__(self, session):
     self.event_store = EventStore(
         record_manager=SQLAlchemyRecordManager(
             session=session,
             record_class=StoredEventRecord,
             sequenced_item_class=StoredEvent,
         ),
         sequenced_item_mapper=SequencedItemMapper(
             sequenced_item_class=StoredEvent,
             sequence_id_attr_name='originator_id',
             position_attr_name='originator_version',
         ))
     self.repository = ExampleRepository(event_store=self.event_store, )
     self.persistence_policy = PersistencePolicy(self.event_store)
    def test(self):
        self.datastore.setup_connection()
        self.datastore.setup_tables()
        record_manager = SQLAlchemyRecordManager(
            record_class=IntegerSequencedNoIDRecord,
            session=self.datastore.session,
        )

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_record_manager=record_manager
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_record_manager=record_manager
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))

        # Close single instance.
        close_example_application()

        # Can't get the single instance before it has been constructed.
        with self.assertRaises(AssertionError):
            get_example_application()

        # Construct single instance.
        init_example_application(
            entity_record_manager=record_manager
        )

        # Can't construct single instance twice.
        with self.assertRaises(AssertionError):
            init_example_application(
                entity_record_manager=record_manager
            )

        # Get the single instance.
        app1 = get_example_application()
        app2 = get_example_application()
        self.assertEqual(id(app1), id(app2))
Пример #7
0
 def __init__(self, datastore):
     event_store = EventStore(
         record_manager=SQLAlchemyRecordManager(
             session=datastore.session, record_class=IntegerSequencedNoIDRecord
         ),
         event_mapper=SequencedItemMapper(
             sequence_id_attr_name="originator_id",
             position_attr_name="originator_version",
         ),
     )
     # Todo: Remove having two repositories, because they are identical.
     self.aggregate1_repository = AggregateRepository(event_store=event_store)
     self.aggregate2_repository = AggregateRepository(event_store=event_store)
     self.persistence_policy = PersistencePolicy(
         persist_event_type=ExampleAggregateRoot.Event, event_store=event_store
     )
 def __init__(self, session):
     self.event_store = EventStore(
         record_manager=SQLAlchemyRecordManager(
             session=session,
             record_class=ExtendedIntegerSequencedRecord,
             sequenced_item_class=ExtendedSequencedItem,
         ),
         event_mapper=ExtendedSequencedItemMapper(
             sequenced_item_class=ExtendedSequencedItem,
             sequence_id_attr_name="originator_id",
             position_attr_name="originator_version",
             other_attr_names=("timestamp", ),
         ),
     )
     self.repository = ExampleRepository(event_store=self.event_store)
     self.persistence_policy = PersistencePolicy(
         event_store=self.event_store, persist_event_type=DomainEvent)
Пример #9
0
 def __init__(self, datastore):
     event_store = EventStore(record_manager=SQLAlchemyRecordManager(
         session=datastore.session,
         record_class=IntegerSequencedNoIDRecord,
     ),
                              sequenced_item_mapper=SequencedItemMapper(
                                  sequence_id_attr_name='originator_id',
                                  position_attr_name='originator_version',
                              ))
     self.aggregate1_repository = AggregateRepository(
         event_store=event_store, )
     self.aggregate2_repository = AggregateRepository(
         event_store=event_store, )
     self.persistence_policy = PersistencePolicy(
         event_type=ExampleAggregateRoot.Event,
         event_store=event_store,
     )
Пример #10
0
import uuid
from eventsourcing.infrastructure.sequenceditemmapper import SequencedItemMapper
from eventsourcing.infrastructure.eventsourcedrepository import EventSourcedRepository
from eventsourcing.infrastructure.eventstore import EventStore
from eventsourcing.infrastructure.sequenceditem import StoredEvent
from eventsourcing.infrastructure.sqlalchemy.datastore import SQLAlchemyDatastore, SQLAlchemySettings
from eventsourcing.infrastructure.sqlalchemy.manager import SQLAlchemyRecordManager
from eventsourcing.infrastructure.sqlalchemy.records import StoredEventRecord

datastore = SQLAlchemyDatastore(
    tables=(StoredEventRecord, ),
    settings=SQLAlchemySettings(uri='sqlite:///mydatabase'))

datastore.setup_connection()
datastore.setup_tables()

recordmanager = SQLAlchemyRecordManager(session=datastore.session,
                                        record_class=StoredEventRecord,
                                        application_name=uuid.uuid4().hex,
                                        contiguous_record_ids=True,
                                        sequenced_item_class=StoredEvent)

sequenceitemmapper = SequencedItemMapper(sequenced_item_class=StoredEvent)

eventstore = EventStore(record_manager=recordmanager,
                        sequenced_item_mapper=sequenceitemmapper)

repository = EventSourcedRepository(event_store=eventstore)
Пример #11
0
def init_example_application_with_sqlalchemy():
    init_application(entity_record_manager=SQLAlchemyRecordManager(
        record_class=EventRecord,
        session=db.session,
    ))