Skip to main content
Home

Built and signed on GitHub Actions

Utilities for working with Deno KV

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
a month ago (0.1.4)

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();

Classes

c
ImportError

An error that can occur when importing records into a Deno.Kv store. Information associated with the error is available with the cause being set to the original error that was thrown.

Functions

f
exportEntries

Exports entries from a Deno.Kv store as a Response where the body of the response is a stream of newline-delimited JSON records that match the provided selector.

f
importEntries

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.

Interfaces

I
ExportEntriesOptionsBytes

Options which can be set when calling exportEntries to export entries as a stream of bytes (Uint8Array chunks).

I
ExportEntriesOptionsResponse

Options which can be set when calling exportEntries to export entries as a Response with the exported data as the body of the Response.

I
ExportEntriesOptionsString

Options which can be set when calling exportEntries to export entries as a stream of string records.

I

Type Aliases

T
ExportEntriesOptions

Options which can be set when calling exportEntries.

Variables

v
MEDIA_TYPE_JSON_LINES

The media type for JSON Lines which is compatible with NDJSON.

v
MEDIA_TYPE_JSONL

The media type for JSONL which is compatible with NDJSON.

v
MEDIA_TYPE_NDJSON

The media type for NDJSON which is a newline-delimited JSON format.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@deno/kv-utils

Import symbol

import * as mod from "@deno/kv-utils/import-export";
or

Import directly with a jsr specifier

import * as mod from "jsr:@deno/kv-utils/import-export";

Add Package

pnpm i jsr:@deno/kv-utils
or (using pnpm 10.8 or older)
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
or (using Yarn 4.8 or older)
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";