eventsauce / message-repository-for-doctrine
Message Repository for Doctrine DBAL 3
Fund package maintenance!
frankdejonge
Installs: 448 407
Dependents: 3
Suggesters: 1
Security: 0
Stars: 0
Watchers: 1
Forks: 1
pkg:composer/eventsauce/message-repository-for-doctrine
Requires
- doctrine/dbal: ^3.1|^4.0
- eventsauce/eventsauce: ^3.0
- eventsauce/id-encoding: ^1.0
- eventsauce/message-repository-table-schema: ^1.0
- eventsauce/uuid-encoding: ^1.0
- ramsey/uuid: ^4.1
README
MessageRepository implementation that uses Doctrine DBAL for event persistence.
Usage
use EventSauce\MessageRepository\DoctrineMessageRepository\DoctrineUuidV4MessageRepository; use EventSauce\MessageRepository\TableSchema\DefaultTableSchema; use EventSauce\UuidEncoding\BinaryUuidEncoder; $messageRepository = new DoctrineUuidV4MessageRepository( connection: $doctrineDbalConnection, tableName: $tableName, serializer: $eventSauceMessageSerializer, tableSchema: new DefaultTableSchema(), // optional uuidEncoder: new BinaryUuidEncoder(), // optional );
Table Schema
TableSchema allows customizing the table and column names used when performing
database operations, as well as allowing for additional headers to be added.
Default Table Schema
The default implementation DefaultTableSchema uses the following column names:
event_idprimary key (text/UUID)aggregate_root_idaggregate root ID (text/UUID)versionaggregate root version (int)payloadencoded event payload (text/JSON)
Legacy Table Schema
For users upgrading from EventSauce pre-1.0, there is a LegacyTableSchema:
event_idprimary key (text/UUID)event_typethe serialized event name (text)aggregate_root_idaggregate root ID (text/UUID)aggregate_root_versionaggregate root version (int)time_of_recordingwhen the event was written (timestamp)payloadencoded event payload (text/JSON)
Custom Implementations
Custom implementations of TableSchema can use the additionalColumns method to
write other Header values to columns, which can be useful for indexing.
UUID Encoder
UuidEncoder allows customizing how the UUIDs used for the event ID and the
aggregate root ID are converted to string when written to the database.
Binary UUID Encoder
UuidBinaryEncoder encodes the UUID using $uuid->getBytes() to generate a binary
text version of the UUID, which should be used when the database does not have a
native uuid type.
String UUID Encoder
UuidStringEncoder encodes the UUID using $uuid->toString() to generate a plain
text version of the UUID, which should be used when the database has a uuid type.
Custom Implementations
Custom implementations of UuidEncoder can be used to optimize UUID storage as needed.