Skip to content

Repository files navigation

@orbitdb/nested-db

Nested key-value database type for OrbitDB.

orbit-db-nested testscodecov

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,useDatabaseType}from"@orbitdb/core";import{Nested}from"@orbitdb/nested-db";// Register nested database type. IMPORTANT - must call before creating orbit instance !useDatabaseType(Nested);constorbitdb=awaitcreateOrbitDB({ ipfs })constdb=awaitorbitdb.open({type: "nested"});awaitdb.put("a",1);awaitdb.put("b/c",2);awaitdb.put(["b","d"],3)// Alternative syntaxconstall=awaitdb.all();// { a: 1, b: { c: 2, d: 3 }}awaitdb.get("b")// { c: 2, d: 3 }awaitdb.del("b");awaitdb.all();// { "a": 1 }

A more complex example with object types:

import{createOrbitDB,useDatabaseType}from"@orbitdb/core";import{Nested}from"@orbitdb/nested-db";// Register nested database type. IMPORTANT - must call before creating orbit instance !useDatabaseType(Nested);constorbit=awaitcreateOrbitDB({ ipfs })constdb=awaitorbitdb.open({type: "nested"});awaitdb.insert({a: {b: 1},d: 3});awaitdb.insert("a",{c: 2});constall=awaitdb.all();// { a: { b: 1, c: 2}, d: 3 }

About

Nested key-value database for OrbitDB

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages