Skip to main content
Module

x/kvdex/mod.ts>IndexableCollection

Database wrapper for Deno KV
Go to Latest
class IndexableCollection
extends Collection<T1>
Re-export
import { IndexableCollection } from "https://deno.land/x/kvdex@v0.3.2/mod.ts";

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

Contains methods for working on documents in the collection, including exclusive indexing methods.

Constructors

new
IndexableCollection(
kv: Deno.Kv,
collectionKey: KvKey,
indexRecord?: T2,
)

Create a new IndexableCollection for handling object documents in the KV store.

Type Parameters

T1 extends Model
T2 extends IndexRecord<T1>

Properties

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

Methods

add(data: T1)
addMany<TEntries extends [T1, ...T1[]]>(...entries: TEntries): Promise<Deno.KvCommitResult | Deno.KvCommitError>

Find a document by index value. Note that selecting an index that was not defined when creating the collection will always return null.

Example:

// Returns a single result
const userByUsername = await db.users.findByPrimaryIndex({
  username: "oli"
})

Finds documents by a given set of secondary indices. If multiple are specified, results are combined.

Example:

// Returns a list of user documents
const usersByAge = await db.users.findBySecondaryIndex({
  age: 24
})
set(id: KvId, data: T1)
update<TId extends KvId>(id: TId, data: Partial<T1>): Promise<CommitResult<T1, TId>>