Nested key-value database type for OrbitDB.
$ pnpm add @orbitdb/nested-db
As Nested
database is like a KeyValue
database, but it can contain nested values that can be accessed as JSON.
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 }