@orbitdb/ordered-keyvalue-db
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@orbitdb/ordered-keyvalue-db

Ordered keyvalue database type for orbit-db.

Tests codecov

Installation

$ pnpm add @orbitdb/ordered-keyvalue

Introduction

A KeyValue database where you can move entries around. Ideal for situations where order is important (e.g., lists of tabs in a spreadsheet, etc.).

Examples

import { createOrbit } from "@orbitdb/core";
import { registerOrderedKeyValue } from "@orbitdb/ordered-keyvalue";

// Register database type. IMPORTANT - must call before creating orbit instance !
registerOrderedKeyValue();

const orbit = await createOrbit({ ipfs })

const db = await orbit.open({ type: "ordered-keyvalue" });

await db.put("a", "some value");
await db.put("b", "another value");

const all = await db.all();
// [{ key: "a", value: "some value", hash: "..." }, { key: "b", value: "another value", hash: "..." }]

await db.move("a", 1)

await db.all();
// [{ key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]

// You can also specify the position on `put`
await db.put("c", "goes first", 0);

await db.all();
// [{ key: "c", value: "goes first", hash: "..." }, { key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]

Readme

Keywords

Package Sidebar

Install

npm i @orbitdb/ordered-keyvalue-db

Weekly Downloads

1,651

Version

1.0.0

License

AGPL-3.0-or-later

Unpacked Size

276 kB

Total Files

46

Last publish

Collaborators

  • julien.malard
  • aphelionz
  • spauldingsmails
  • haad