kv_sqlite

Key-Value storage backed by SQLite (uses deno.land/x/sqlite)

API documentation

Generated TypeScript API documentation is available at https://deno.land/x/kv_sqlite/mod.ts

Use

import { openKVDb } from "https://deno.land/x/kv_sqlite@VERSION/mod.ts";

// Open a persistent database using the local file system (it will be created if necessary):
const kv = openKVDb("path/to/kv-database.sqlite3");

// Or open a database in-memory (not persisted)
// const kv = openKVDb();

kv.set("hello", "world");
console.log(kv.get("hello")); // "world"

// Retrieving values for non-existing keys returns `null`
console.log(kv.get("not a key yet")); // null

// Has convenience methods for working with JSON-serializable values:
kv.json.set("foo", { bar: "baz" });
console.log(kv.json.get("foo").bar); // "baz"

console.log(kv.size); // 2

// Be careful with this method (it deletes everything from the database!)
kv.clear();
console.log(kv.size); // 0

// Close the database when finished to avoid leaking resources:
kv.close();