Skip to main content

nexus-persistence-dbal

Doctrine DBAL adapter for Nexus persistence — SQL-backed event store, snapshot store, and durable state store using parameterized queries.

What's in this package

Install

composer require nexus-actors/persistence-dbal

Quick example

src/Persistence/DbalSetup.php
use Doctrine\DBAL\DriverManager;
use Monadial\Nexus\Persistence\Dbal\DbalEventStore;
use Monadial\Nexus\Persistence\Dbal\DbalSnapshotStore;
use Monadial\Nexus\Persistence\Dbal\Schema\PersistenceSchemaManager;

$conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => 'nexus.db']);

(new PersistenceSchemaManager($conn))->createSchema();

$eventStore = new DbalEventStore($conn);
$snapshotStore = new DbalSnapshotStore($conn);

All three stores stamp each persisted envelope with the actor system's writer_id (ULID) for writer-conflict detection. A MessageSerializer is a required second constructor argument (no default): use PhpNativeSerializer::forTrustedData() for self-produced trusted rows, new PhpNativeSerializer(allowedClasses: [...]) to restrict native deserialization, or the Valinor mapper for untrusted data.

See also