Skip to Content
DocsDatabase adaptersMemory

Memory adapter

@quickben/db-memory keeps data in process memory. Use it in tests, demos and docs. Data is lost when the process exits.

pnpm add @quickben/db-memory
import { defineConfig } from "@quickben/core"; import { memoryAdapter } from "@quickben/db-memory"; import { posts, tags, users } from "./collections"; export default defineConfig({ db: memoryAdapter({ initialData: { tags: [ { id: "t1", name: "news", createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }, ], }, }), collections: [users, tags, posts], });

Options

OptionPurpose
initialDataDocuments to load before the first call, keyed by slug. Stored as given.

Behavior

TopicBehavior
TransactionsCopy-on-write. Changes apply to the latest data on commit. Unique values are checked again on commit.
IsolationReads outside a transaction do not see its writes until commit.
raw{ collections }: the documents the adapter can see, keyed by slug and id.
ContractReference adapter for the shared contract tests.

Tests

Use createQuickben to get a fresh instance per test:

import { createQuickben } from "@quickben/core"; const fresh = await createQuickben(config); await fresh.create("tags", { name: "test" }, { user });

The config holds one adapter. For isolated tests, build the config in a function that calls memoryAdapter() each time.

Last updated on