Skip to content

orbitdb/nested-db

Repository files navigation

@orbitdb/nested-db

Nested key-value database type for OrbitDB.

orbit-db-nested tests codecov

Installation

$ pnpm add @orbitdb/nested-db

Introduction

As Nested database is like a KeyValue database, but it can contain nested values that can be accessed as JSON.

Examples

A simple example with Nested:

import { createOrbitDB } from "@orbitdb/core";
import { Nested } from "@orbitdb/nested-db";

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

const orbitdb = await createOrbitDB({ ipfs })

const db = await orbitdb.open({ type: "nested" });

await db.put("a", 1);
await db.put("b/c", 2);
await db.put(["b", "d"], 3)  // Alternative syntax

const all = await db.all();  // { a: 1, b: { c: 2, d: 3 } }

await db.get("b")  // { c: 2, d: 3 }

await db.del("b");
await db.all();  // { "a": 1 }

A more complex example with object types:

import { createOrbitDB } from "@orbitdb/core";
import { Nested } from "@orbitdb/nested-db";

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

const orbit = await createOrbitDB({ ipfs })

const db = await orbitdb.open({ type: "nested" });

await db.putNested({ a: { b: 1, c: 2 } });
await db.putNested({ d: 3 });

const all = await db.all();  // { a: { b: 1, c: 2}, d: 3 }

About

Nested key-value database for OrbitDB

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published