Drivers Overview
@requence/event-sourcing ships with pluggable storage drivers that implement the low-level persistence layer — event storage, checkpoints, and snapshots. The core library defines the interfaces; each driver provides a concrete createEventStore function that wires everything together.
| Driver | Import | Use case |
|---|---|---|
| In-Memory | @requence/event-sourcing/memory | Testing, prototyping, single-process apps |
| Drizzle (PostgreSQL) | @requence/event-sourcing/drizzle | Production workloads |
| SurrealDB | @requence/event-sourcing/surreal | Production workloads on SurrealDB |
All drivers expose the same createEventStore and createAggregateRoot API, so you can swap between them by changing a single import.
Swapping Drivers
Section titled “Swapping Drivers”Because all drivers conform to the same EventStore interface, switching between them is a one-line change:
import { createEventStore, createAggregateRoot } from '@requence/event-sourcing/drizzle'import { createEventStore, createAggregateRoot } from '@requence/event-sourcing/memory'
const eventStore = createEventStore({ database: db, aggregateRoots: [user],})A common pattern is to select the driver based on the environment:
const { createEventStore } = process.env.NODE_ENV === 'test' ? await import('@requence/event-sourcing/memory') : await import('@requence/event-sourcing/drizzle')