Skip to main content
Module

x/kvdex/mod.ts>collection

High-level abstraction layer for Deno KV 🦕🗝️
Go to Latest
function collection
import { collection } from "https://deno.land/x/kvdex@0.33.1/mod.ts";

Create a new collection within a database context.

Examples

Example 1

import { model, collection, kvdex } from "jsr:@olli/kvdex"

type User = {
  username: string
  age: number
}

const db = kvdex(kv, {
  numbers: collection(model<number>()),
  users: collection(model<User>(), {
    idGenerator: () => crypto.randomUUID(),
    serialize: "json",
    indices: {
      username: "primary",
      age: "secondary"
    }
  })
})

Type Parameters

TInput
TOutput extends KvValue
TOptions extends CollectionOptions<TOutput>

Parameters

  • Collection model.
optional
options: TOptions
  • Collection options.

Returns

A collection builder function.