Skip to content

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.

DriverImportUse case
In-Memory@requence/event-sourcing/memoryTesting, prototyping, single-process apps
Drizzle (PostgreSQL)@requence/event-sourcing/drizzleProduction workloads
SurrealDB@requence/event-sourcing/surrealProduction workloads on SurrealDB

All drivers expose the same createEventStore and createAggregateRoot API, so you can swap between them by changing a single import.

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')