Skip to main content
Module

x/kvdex/mod.ts>kvdex

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

Create a new database instance.

Builds the database collections and forms the schema.

Examples

Example 1

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

type User = {
  username: string
  age: number
}

const kv = await Deno.openKv()

const db = kvdex(kv, {
  numbers: collection(model<number>()),
  u64s: collection(model<Deno.KvU64>()),
  serializedStrings: collection(model<string>(), { serialize: "json" }),
  users: collection(model<User>(), {
    indices: {
      username: "primary",
      age: "secondary"
    }
  })
})

Parameters

  • The Deno KV instance to be used for storing and retrieving data.
schemaDefinition: T
  • The schema definition used to build collections and create the database schema.

Returns

A Kvdex instance with attached schema.