Download the PHP package wwwision/dcb-eventstore without Composer
On this page you can find all versions of the php package wwwision/dcb-eventstore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wwwision/dcb-eventstore
More information about wwwision/dcb-eventstore
Files in wwwision/dcb-eventstore
Package dcb-eventstore
Short Description Implementation of the Dynamic Consistency Boundary pattern described by Sara Pellegrini
License MIT
Informations about the package dcb-eventstore
Dynamic Consistency Boundary Event Store
Interfaces and types for Event Stores implementing Dynamic Consistency Boundaries according to the specification.
To actually commit events, a corresponding adapter package is required!
Adapters
The following adapter implementations can be used with this package:
| Adapter | Storage/Engine | Transport, SDK |
|---|---|---|
| ekvedaras/dcb-eventstore-illuminate | SQLite, MySQL/MariaDB, PostgreSQL | Laravel Database |
| wwwision/dcb-eventstore-doctrine | SQLite, MySQL/MariaDB, PostgreSQL | Doctrine DBAL |
| wwwision/dcb-eventstore-esdb | EventSourcing Database (file based, proprietary) | HTTP |
| wwwision/dcb-eventstore-umadb | UmaDB (file based, open source) | Rust FFI (via custom PHP Extension) |
| wwwision/dcb-eventstore-umadb-grpc | UmaDB (file based, open source) | gRPC (via official PHP Extension) |
Feel free to contact me or extend this list via pull request if you wrote another adapter implementation
Usage
Install via composer:
Create Event Store instance
Instantiation of Event Stores depend on the corresponding adapter package. This package comes with an in-memory Event Store for testing, that can be created like so:
Read Events
The read() function allows to read events.
To obtain a stream of all events in the Event Store, Query::all() can be used:
The result is an iterable stream of SequencedEvents, that contain the originally appended event, the position of that event in the stream and some metadata:
Filter events
Query::fromItems() can be used to filter events, by their type:
...by tags:
...or by a combination:
Multiple QueryItems can be specified to filter events that match any of the specified items:
[!NOTE] Tags within a single QueryItem are conjunctive (combined with AND) while individual QueryItems are disjunctive (combined with OR)
Read Options
An optional 2nd argument can be specified in order to define custom limits/orderings:
By default events are always ordered by their SequencePosition in ascending order i.e. FIFO.
Sometimes it can be useful to order events in descending order, for example in order to provide cursor-based pagination:
This can also be used to load the last event(s) with a certain type or tag:
Write Events
The append() function allows to write events.
Unconditional writes
DCB is all about enforcing consistency when appending new events. But in some cases (e.g. when importing data or for testing purposes) it can be necessary to write events without enforcing any constraint.
Therefor, the appendCondition parameter can be left out:
Multiple events can be written atomically using Events:
Append Condition
The following call appends a ProductDefined event, but fails if a corresponding event for the same product id was appended previously (or practically at the same time, i.e. this operation ensures transaction safety):
In the previous example, no event in the entire stream must match the specified query – it can be compared with a NoStream expectation of a traditional event store.
But DCB also supports to specify a "safe point" using the optional after parameter of the AppendCondition:
Higher Level API
This package mainly implements the low-level DCB specification (see dcb.events website). It's highly advised to introduce a higher level abstraction for the usage within the actual application logic.
Feel free to get in touch to see how this can be combined with the idea of composed projections in practice!
Contribution
Contributions in the form of issues, pull requests or discussions are highly appreciated
License
See LICENSE