Skip to content

KVReadModelStore

API reference for KVReadModelStore

@delta-base/toolkit


Cloudflare KV implementation of the IReadModelStore interface. Uses Cloudflare’s KV namespace to store, retrieve, delete, and list key-value pairs. Updated to use native batch operations for better performance.

new KVReadModelStore(namespace, options): KVReadModelStore

Creates a new KV read model store.

any

The Cloudflare KV namespace to use for storage

Optional configuration for the store

string

Optional prefix to apply to all keys This can be used to create virtual “tables” within a single KV namespace

KVReadModelStore

batchDelete(keys, options?): Promise<boolean[]>

Batch deletion of multiple items

string[]

WriteOptions

Promise<boolean[]>

IReadModelStore.batchDelete


batchGet<T>(keys, options?): Promise<object[]>

Native batch retrieval of multiple items by their keys using KV’s new batch API This is much more efficient than individual get operations

T = unknown

string[]

Array of keys to retrieve (max 100 keys)

ReadOptions

Optional settings for the batch get operation

Promise<object[]>

A promise that resolves with an array of key-value pairs

IReadModelStore.batchGet


batchGetWithMetadata<T>(keys, options?): Promise<object[]>

Enhanced batch get with metadata support

T = unknown

string[]

ReadOptions

Promise<object[]>


batchPut<T>(items, options?): Promise<void>

Batch storage of multiple items

T = unknown

object[]

WriteOptions & ExpirationOptions

Promise<void>

IReadModelStore.batchPut


delete(key, options?): Promise<boolean>

Deletes a value by its key.

string

The key of the value to delete

WriteOptions

Optional settings for the delete operation

Promise<boolean>

A promise that resolves to true if the key existed and was deleted, false otherwise

IReadModelStore.delete


get<T>(key, options?): Promise<null | T>

Retrieves a value by its key.

T = unknown

string

The key of the value to retrieve

ReadOptions

Optional settings for the retrieval operation

Promise<null | T>

A promise that resolves with the value, or null if not found

IReadModelStore.get


getAll<T>(options?): Promise<object[]>

Retrieves all values, optionally filtered by a key prefix.

T = unknown

QueryOptions

Optional settings for retrieving all values

Promise<object[]>

A promise that resolves with an array of key-value pairs

IReadModelStore.getAll


getCapabilities(): StoreCapabilities

Returns enhanced capabilities for KV store

StoreCapabilities

IReadModelStore.getCapabilities


getNativeClient<C>(): C

Gets access to the native KV namespace

C = any

C

IReadModelStore.getNativeClient


getWithMetadata<T>(key, options?): Promise<{ metadata: null | Record<string, unknown>; value: null | T; }>

Helper method to add metadata support

T = unknown

string

ReadOptions

Promise<{ metadata: null | Record<string, unknown>; value: null | T; }>


listKeys(options?): Promise<{ cursor?: string; keys: object[]; list_complete: boolean; }>

Lists keys in the store, optionally filtered by prefix.

Optional settings for the list operation

string

number

string

string

Promise<{ cursor?: string; keys: object[]; list_complete: boolean; }>

A promise that resolves with the list result containing keys and metadata

IReadModelStore.listKeys


put<T>(key, value, options?): Promise<void>

Stores a value with the given key.

T = unknown

string

The key under which to store the value

T

The value to store (will be serialized to JSON if it’s not a string or ArrayBuffer)

WriteOptions & ExpirationOptions & MetadataOptions

Optional settings for the storage operation

Promise<void>

A promise that resolves when the value has been stored

IReadModelStore.put


query<T>(options): Promise<object[]>

Enhanced query with better prefix support

T = unknown

QueryOptions & object

Promise<object[]>

IReadModelStore.query