function createInMemory
createInMemory<
TDoc,
TKey,
TQuery extends InMemoryQuery<TDoc> = InMemoryQuery<TDoc>,
>
(): InMemoryConnector<TDoc, TQuery, TKey>

Creates an in-memory NoSQL document store for testing and development.

Documents are stored in a Map and will be lost when the process exits. Queries use predicate functions to filter documents.

Examples

Basic usage

import { Collection, createInMemory } from "@anabranch/nosql";

const connector = createInMemory<User, (u: User) => boolean, string>();
const users = await Collection.connect(connector, "users").run();

await users.put("user-1", { name: "Alice", status: "active" }).run();
const user = await users.get("user-1").run();

Query with predicate

const activeUsers = await users
  .find((u) => u.status === "active")
  .map((u) => u.name)
  .collect();

Type Parameters

TDoc
TKey

Return Type

Usage

import { createInMemory } from ".";