Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Utilities for working with Deno KV
Allows for the import and export of data from a Deno.Kv
store.
Exporting Data
Data can be exported from a Deno.Kv
store using the
exportEntries
function. This function will return a stream of
newline-delimited JSON records that can be consumed by a client. The exported
data can be returned as a stream of bytes, a stream of strings or as a
Response
with the exported data as the body of the response.
Example: Exporting Data as a Stream of Bytes
import { exportEntries } from "@deno/kv-utils/import-export"; import { assert } from "@std/assert"; const db = await Deno.openKv(); const stream = exportEntries(db, { prefix: ["person"] }); for await (const chunk of stream) { assert(chunk.byteLength); } db.close();
Example: Exporting Data as a Stream of Strings
import { exportEntries } from "@deno/kv-utils/import-export"; import { assert } from "@std/assert"; const db = await Deno.openKv(); const stream = exportEntries(db, { prefix: ["person"] }, { type: "string" }); for await (const chunk of stream) { assert(typeof chunk === "string"); } db.close();
Example: Exporting Data as a Response
import { exportEntries } from "@deno/kv-utils/import-export"; const db = await Deno.openKv(); const server = Deno.serve((_req) => exportEntries( db, { prefix: ["person"] }, { type: "response" } )); await server.finished; db.close();
Importing Data
Data can be imported into a Deno.Kv
store using the
importEntries
function. This function will read a stream of
newline-delimited JSON records and import them into the store. The import
process can be controlled with options to overwrite existing entries, provide
a prefix for the imported keys, and to handle errors that occur during the
import process.
Example: Importing Data from a Byte Array
import { importEntries } from "@deno/kv-utils/import-export"; import { assert } from "@std/assert"; const db = await Deno.openKv(); const data = new TextEncoder().encode('{"key":[{"type":"string","value":"a"}],"value":{"type":"bigint","value":"100"},"versionstamp":"00000000000000060000"}\n'); const result = await importEntries(db, data); assert(result.count === 1); db.close();
Imports entries into a Deno.Kv
store from a stream of newline-
delimited JSON records. The import process can be controlled with options to
overwrite existing entries, provide a prefix for the imported keys, and to
handle errors that occur during the import process.
Options which can be set when calling exportEntries
to export
entries as a stream of bytes (Uint8Array
chunks).
Options which can be set when calling exportEntries
to export
entries as a Response
with the exported data as the body of the
Response
.
Options which can be set when calling exportEntries
to export
entries as a stream of string records.
Options which can be set when calling importEntries
.
Options which can be set when calling exportEntries
.
The media type for JSON Lines which is compatible with NDJSON.
The media type for JSONL which is compatible with NDJSON.
The media type for NDJSON which is a newline-delimited JSON format.
Add Package
deno add jsr:@deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";
Import directly with a jsr specifier
import * as mod from "jsr:@deno/kv-utils/import-export";
Add Package
pnpm i jsr:@deno/kv-utils
pnpm dlx jsr add @deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";
Add Package
yarn add jsr:@deno/kv-utils
yarn dlx jsr add @deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";
Add Package
vlt install jsr:@deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";
Add Package
npx jsr add @deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";
Add Package
bunx jsr add @deno/kv-utils
Import symbol
import * as mod from "@deno/kv-utils/import-export";