https://github.com/orbitdb/set-db
Set database for orbit-db
https://github.com/orbitdb/set-db
Last synced: 11 months ago
JSON representation
Set database for orbit-db
- Host: GitHub
- URL: https://github.com/orbitdb/set-db
- Owner: orbitdb
- License: agpl-3.0
- Created: 2024-01-20T00:45:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-07T12:01:27.000Z (12 months ago)
- Last Synced: 2025-07-07T13:22:11.552Z (12 months ago)
- Language: TypeScript
- Size: 1.24 MB
- Stars: 0
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @orbitdb/set-db
Set database type for OrbitDB.
[](https://github.com/orbitdb/set-db/actions/workflows/run-test.yml)
[](https://codecov.io/gh/orbitdb/set-db)
## Installation
```
$ pnpm add @orbitdb/set-db
```
## Introduction
As `Set` database is like a [`Feed`](https://github.com/reseau-constellation/set), but each value can only be present once. Works for primitive types as well as more complex objects.
## Examples
A simple example with `Set`:
```ts
import { createOrbitDB } from "@orbitdb/core";
import { registerSet } from "@orbitdb/set-db";
// Register set database type. IMPORTANT - must call before creating orbit instance !
registerSet();
const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.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:
```ts
import { createOrbitDB } from "@orbitdb/core";
import { registerSet } from "@orbitdb/set-db";
// Register set database type. IMPORTANT - must call before creating orbit instance !
registerSet();
const orbit = await createOrbitDB({ ipfs })
const db = await orbitdb.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}]
```