Skip to content

orbitdb/set-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
Jan 25, 2024
Jan 20, 2024
Jan 20, 2024
Jan 20, 2024
Jan 19, 2024
Jan 19, 2024
Jan 19, 2024
Jan 19, 2024
Jan 19, 2024
Jan 19, 2024
Jan 25, 2024
Jan 20, 2024
Jan 20, 2024
Jan 19, 2024
Jan 19, 2024
Jan 19, 2024

Repository files navigation

@orbitdb/set-db

Set database type for orbit-db.

orbit-db-set tests codecov

Installation

$ pnpm add @orbitdb/set-db

Introduction

As Set database is like a Feed, but each value can only be present once. Works for primitive types as well as more complex objects.

Examples

A simple example with Set:

import { createOrbit } from "@orbitdb/core";
import { registerSet } from "@orbitdb/set-db";

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

const orbit = await createOrbit({ ipfs })

const db = await orbit.open({ type: "set" });

await db.add(1);
await db.add(2);

const all = await db.all();  // [1, 2]

await db.add(1);
await db.all()  // Yay !! Still [1, 2]

As more complex example with object types:

import { createOrbit } from "@orbitdb/core";
import { registerSet } from "@orbitdb/set-db";

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

const orbit = await createOrbit({ ipfs })

const db = await orbit.open({ type: "set" });

await db.add({a: 1});
await db.add({a: 2});

const all = await db.all();  // [{a: 1}, {a: 2}]

await db.add({a: 1});
await db.all()  // Yay !! Still [{a: 1}, {a: 2}]