Basic CRUD with Collection
Basic CRUD with Collection
import { Collection, createInMemory } from "@anabranch/nosql"; interface User { name: string status: "active" | "pending" | "inactive" } const connector = createInMemory<User, 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(); console.log(user?.name); // "Alice"
A NoSQL document collection with Task/Stream semantics.
-
connect<TDoc, TQuery, TKey>(): Task<Collection<TDoc, TQuery, TKey>, CollectionConnectionFailed>connector: DocumentConnector<TDoc, TQuery, TKey>,name: string
Connects to a collection via a connector and returns a Collection.
-
create<TDoc, TQuery, TKey>(): Collection<TDoc, TQuery, TKey>adapter: DocumentAdapter<TDoc, TQuery, TKey>,name: string
Creates a Collection from an already-connected adapter.
-
delete(key: TKey): Task<void, CollectionDeleteFailed>
Deletes a document by its key.
-
find(query: TQuery): Source<TDoc, CollectionFindFailed>
Queries documents and returns a stream of results.
-
get(key: TKey): Task<TDoc | null, CollectionGetFailed>
Fetches a single document by its key.
-
put(): Task<void, CollectionPutFailed>key: TKey,doc: TDoc
Upserts a document.
-
putMany(entries: { key: TKey; doc: TDoc; }[]): Task<void, CollectionPutManyFailed>
Batch writes multiple documents.
Error thrown when connecting to a collection fails.
-
collection: string
Name of the collection.
- name: string
Error thrown when a document delete operation fails.
-
collection: string
Name of the collection.
-
key: unknown
Key that was being deleted.
- name: string
Error thrown when a query operation fails.
-
collection: string
Name of the collection.
- name: string
Error thrown when a document get operation fails.
-
collection: string
Name of the collection.
-
key: unknown
Key that was being retrieved.
- name: string
Error thrown when a document put operation fails.
-
collection: string
Name of the collection.
-
key: unknown
Key that was being written.
- name: string
Error thrown when a batch put operation fails.
-
collection: string
Name of the collection.
- name: string
Creates an in-memory NoSQL document store for testing and development.
Document adapter interface for NoSQL database operations.
-
delete(key: TKey): Promise<void>
Deletes a document by its key.
-
get(key: TKey): Promise<TDoc | null>
Fetches a single document by its primary key/reference.
-
put(): Promise<void>key: TKey,doc: TDoc
Upserts a document.
-
putMany(entries: { key: TKey; doc: TDoc; }[]): Promise<void>
Batch writes multiple documents.
-
query(query: TQuery): AsyncIterable<TDoc>
Executes a native query and yields results as an AsyncIterable. The adapter handles underlying pagination (e.g., Datastore's endCursor or DynamoDB's LastEvaluatedKey) internally.
Connector that produces connected DocumentAdapter instances.
-
connect(): Promise<DocumentAdapter<TDoc, TQuery, TKey>>
Acquires a connected adapter.
-
end(): Promise<void>
Closes all connections and cleans up resources. After calling end(), the connector cannot be used to create new adapters.
Connector interface for the in-memory document store.
Predicate function type for filtering documents in the in-memory store.
Registry of error constructors for instanceof checks.