@@ -8,7 +8,6 @@ Each message contains an event and the associated headers.
88 More information about the message can be found [here](message.md).
99
1010The store is optimized to efficiently store and load events for aggregates.
11- We currently only offer one [ doctrine dbal] ( https://www.doctrine-project.org/projects/dbal.html ) store.
1211
1312## Create DBAL connection
1413
@@ -29,8 +28,14 @@ $connection = DriverManager::getConnection(
2928
3029## Configure Store
3130
31+ We currently offer two stores, both based on the [ doctrine dbal] ( https://www.doctrine-project.org/projects/dbal.html ) library.
32+ The default store is the ` DoctrineDbalStore ` and the new experimental store is the ` StreamDoctrineDbalStore ` .
33+
34+ ### DoctrineDbalStore
35+
36+ This is the current default store for event sourcing.
3237You can create a store with the ` DoctrineDbalStore ` class.
33- The store needs a dbal connection, an event serializer, an aggregate registry and some options.
38+ The store needs a dbal connection, an event serializer and has some optional parameters like options.
3439
3540``` php
3641use Doctrine\DBAL\Connection;
@@ -41,21 +46,17 @@ use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
4146$store = new DoctrineDbalStore(
4247 $connection,
4348 DefaultEventSerializer::createFromPaths(['src/Event']),
44- null,
45- [/** options */],
4649);
4750```
4851Following options are available in ` DoctrineDbalStore ` :
4952
50- | Option | Type | Default | Description |
51- | -------------------| ------------------| ------------| ----------------------------------------------|
52- | table_name | string | eventstore | The name of the table in the database |
53- | aggregate_id_type | "uuid"| "string" | uuid | The type of the ` aggregate_id ` column |
54- | locking | bool | true | If the store should use locking for writing |
55- | lock_id | int | 133742 | The id of the lock |
56- | lock_timeout | int | -1 | The timeout of the lock. -1 means no timeout |
57-
58- ## Schema
53+ | Option | Type | Default | Description |
54+ | -------------------| -----------------| ------------| ----------------------------------------------|
55+ | table_name | string | eventstore | The name of the table in the database |
56+ | aggregate_id_type | "uuid"/"string" | uuid | The type of the ` aggregate_id ` column |
57+ | locking | bool | true | If the store should use locking for writing |
58+ | lock_id | int | 133742 | The id of the lock |
59+ | lock_timeout | int | -1 | The timeout of the lock. -1 means no timeout |
5960
6061The table structure of the ` DoctrineDbalStore ` looks like this:
6162
@@ -72,13 +73,59 @@ The table structure of the `DoctrineDbalStore` looks like this:
7273| archived | bool | If the event is archived |
7374| custom_headers | json | Custom headers for the event |
7475
75- With the help of the ` SchemaDirector ` , the database structure can be created, updated and deleted.
76-
7776!!! note
7877
7978 The default type of the `aggregate_id` column is `uuid` if the database supports it and `string` if not.
8079 You can change the type with the `aggregate_id_type` to `string` if you want use custom id.
8180
81+ ### StreamDoctrineDbalStore
82+
83+ We offer a new experimental store called ` StreamDoctrineDbalStore ` .
84+ This store is decoupled from the aggregate and can be used to store events from other sources.
85+ The difference to the ` DoctrineDbalStore ` is that the ` StreamDoctrineDbalStore ` merge the aggregate id
86+ and the aggregate name into one column named ` stream ` . Additionally, the column ` playhead ` is nullable.
87+ This store introduces two new methods ` streams ` and ` remove ` .
88+
89+ The store needs a dbal connection, an event serializer and has some optional parameters like options.
90+
91+ ``` php
92+ use Doctrine\DBAL\Connection;
93+ use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
94+ use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
95+
96+ /** @var Connection $connection */
97+ $store = new StreamDoctrineDbalStore(
98+ $connection,
99+ DefaultEventSerializer::createFromPaths(['src/Event']),
100+ );
101+ ```
102+ Following options are available in ` StreamDoctrineDbalStore ` :
103+
104+ | Option | Type | Default | Description |
105+ | -------------------| -----------------| -------------| ----------------------------------------------|
106+ | table_name | string | event_store | The name of the table in the database |
107+ | locking | bool | true | If the store should use locking for writing |
108+ | lock_id | int | 133742 | The id of the lock |
109+ | lock_timeout | int | -1 | The timeout of the lock. -1 means no timeout |
110+
111+ The table structure of the ` StreamDoctrineDbalStore ` looks like this:
112+
113+ | Column | Type | Description |
114+ | ------------------| ----------| --------------------------------------------------|
115+ | id | bigint | The index of the whole stream (autoincrement) |
116+ | stream | string | The name of the stream |
117+ | playhead | ?int | The current playhead of the aggregate |
118+ | event | string | The name of the event |
119+ | payload | json | The payload of the event |
120+ | recorded_on | datetime | The date when the event was recorded |
121+ | new_stream_start | bool | If the event is the first event of the aggregate |
122+ | archived | bool | If the event is archived |
123+ | custom_headers | json | Custom headers for the event |
124+
125+ ## Schema
126+
127+ With the help of the ` SchemaDirector ` , the database structure can be created, updated and deleted.
128+
82129!!! tip
83130
84131 You can also use doctrine migration to create and keep your schema in sync.
@@ -92,11 +139,11 @@ Additionally, it implements the `DryRunSchemaDirector` interface, to show the sq
92139``` php
93140use Doctrine\DBAL\Connection;
94141use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
95- use Patchlevel\EventSourcing\Store\DoctrineDbalStore ;
142+ use Patchlevel\EventSourcing\Store\Store ;
96143
97144/**
98145 * @var Connection $connection
99- * @var DoctrineDbalStore $store
146+ * @var Store $store
100147 */
101148$schemaDirector = new DoctrineSchemaDirector(
102149 $connection,
@@ -179,13 +226,13 @@ use Doctrine\Migrations\DependencyFactory;
179226use Doctrine\Migrations\Provider\SchemaProvider;
180227use Patchlevel\EventSourcing\Schema\DoctrineMigrationSchemaProvider;
181228use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
182- use Patchlevel\EventSourcing\Store\DoctrineDbalStore ;
229+ use Patchlevel\EventSourcing\Store\Store ;
183230
184231// event sourcing schema director configuration
185232
186233/**
187234 * @var Connection $connection
188- * @var DoctrineDbalStore $store
235+ * @var Store $store
189236 */
190237$schemaDirector = new DoctrineSchemaDirector(
191238 $connection,
@@ -355,11 +402,39 @@ $store->save(...$messages);
355402
356403 Use transactional method if you want call multiple save methods in a transaction.
357404
358- ### Delete & Update
405+ ### Update
359406
360- It is not possible to delete or update events.
407+ It is not possible to update events.
361408In event sourcing, the events are immutable.
362409
410+ ### Remove
411+
412+ You can remove a stream with the ` remove ` method.
413+
414+ ``` php
415+ use Patchlevel\EventSourcing\Store\StreamStore;
416+
417+ /** @var StreamStore $store */
418+ $store->remove('profile-*');
419+ ```
420+ !!! note
421+
422+ The method is only available in the `StreamStore` like `StreamDoctrineDbalStore`.
423+
424+ ### List Streams
425+
426+ You can list all streams with the ` streams ` method.
427+
428+ ``` php
429+ use Patchlevel\EventSourcing\Store\StreamStore;
430+
431+ /** @var StreamStore $store */
432+ $streams = $store->streams(); // ['profile-1', 'profile-2', 'profile-3']
433+ ```
434+ !!! note
435+
436+ The method is only available in the `StreamStore` like `StreamDoctrineDbalStore`.
437+
363438### Transaction
364439
365440There is also the possibility of executing a function in a transaction.
0 commit comments