Skip to main content
Module

x/kvdex/mod.ts>IndexableCollection

High-level abstraction layer for Deno KV 🦕📁
Go to Latest
class IndexableCollection
extends Collection<T1, T2>
import { IndexableCollection } from "https://deno.land/x/kvdex@v0.18.4/mod.ts";

Represents a collection of object documents stored in the KV store.

Contains methods for working on documents in a collection, including methods exclusive to indexable collections.

Constructors

new
IndexableCollection(
kv: Deno.Kv,
key: KvKey,
model: Model<T1>,
queueHandlers: Map<string, QueueMessageHandler<QueueValue>[]>,
idempotentListener: () => void,
options: T2,
)

Properties

readonly
primaryIndexList: string[]
readonly
secondaryIndexList: string[]

Methods

protected
setDocument(
id: KvId | null,
value: T1,
options: SetOptions | undefined,
overwrite?,
): Promise<CommitResult<T1> | Deno.KvCommitError>
protected
updateDocument(
doc: Document<T1>,
data: UpdateData<T1>,
options: SetOptions | undefined,
): Promise<CommitResult<T1> | Deno.KvCommitError>

PROTECTED METHODS

delete(...ids: KvId[])
deleteByPrimaryIndex<K extends PrimaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
options?: FindOptions,
)

Delete a document by a primary index.

deleteBySecondaryIndex<K extends SecondaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
options?: ListOptions<T1>,
)

Delete documents by a secondary index. The method takes an optional options argument that can be used for filtering of documents, and pagination.

findByPrimaryIndex<K extends PrimaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
options?: FindOptions,
)

Find a document by a primary index.

findBySecondaryIndex<K extends SecondaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
options?: ListOptions<T1>,
)

Find documents by a secondary index. Secondary indices are not unique, and therefore the result is an array of documents. The method takes an optional options argument that can be used for filtering of documents, and pagination.

updateByPrimaryIndex<K extends PrimaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
data: UpdateData<T1>,
options?: SetOptions,
): Promise<CommitResult<T1> | Deno.KvCommitError>

Update a document by a primary index.

updateBySecondaryIndex<K extends SecondaryIndexKeys<T1, T2["indices"]>>(
index: K,
value: CheckKeyOf<K, T1>,
data: UpdateData<T1>,
options?: UpdateManyOptions<T1>,
)

Update documents in the collection by a secondary index.