Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmalard committed Jan 20, 2024
1 parent eca7472 commit 0e71abc
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
# Kuiper
Additional database types for orbit-db.
# orbit-db-set
Set database type for orbit-db.

[![Orbit-db Kuiper tests](https://github.com/reseau-constellation/orbit-db-kuiper/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/reseau-constellation/orbit-db-kuiper/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/reseau-constellation/orbit-db-kuiper/graph/badge.svg?token=7OZK4BJDej)](https://codecov.io/gh/reseau-constellation/orbit-db-kuiper)
[![orbit-db-set tests](https://github.com/reseau-constellation/orbit-db-set/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/reseau-constellation/orbit-db-set/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/reseau-constellation/orbit-db-set/graph/badge.svg?token=7OZK4BJDej)](https://codecov.io/gh/reseau-constellation/orbit-db-set)

## Installation
```
$ pnpm add @constl/orbit-db-kuiper
$ pnpm add @orbitdb/orbit-db-set
```
## Introduction
`Kuiper` brings additional database types to `orbit-db`.

* `Feed`: For those feeling nostalgic for orbit-db v.0.x. But honestly, you're probably better off with a `KeyValue` or a `Set`.
* `Set`: Like `Feed`, but each value can only be present once. Works for primitive types as well as more complex objects.
* `OrderedKeyValue`: A `KeyValue` database where you can move entries around. Ideal for situations where order is important (e.g., lists of tabs in a spreadsheet, etc.).
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

### Set
As simple example with `Set`:
A simple example with `Set`:
```ts
import { createOrbit } from "@orbitdb/core";
import { registerAll } from "@constl/orbit-db-kuiper";
import { registerSet } from "@orbitdb/set";

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

const orbit = await createOrbit({ ipfs })

Expand All @@ -39,40 +34,23 @@ await db.add(1);
await db.all() // Yay !! Still [1, 2]
```

### Feed
As more complex example with object types:
```ts
const db = await orbit.open({ type: "feed" });

await db.add({ a: 1, b: "c" });

const all = await db.all(); // [{ value: { a: 1, b: "c" }, hash: "..." }]

await db.add({ a: 1, b: "c" });
await db.all();
// [{ value: { a: 1, b: "c" }, hash: "..." }, { value: { a: 1, b: "c" }, hash: "..." }]
```

### OrderedKeyValue

```ts

const db = await orbit.open({ type: "ordered-keyvalue" });

await db.put("a", "some value");
await db.put("b", "another value");
import { createOrbit } from "@orbitdb/core";
import { registerSet } from "@orbitdb/set";

const all = await db.all();
// [{ key: "a", value: "some value", hash: "..." }, { key: "b", value: "another value", hash: "..." }]
// Register set database type. IMPORTANT - must call before creating orbit instance !
registerSet();

await db.move("a", 1)
const orbit = await createOrbit({ ipfs })

await db.all();
// [{ key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]
const db = await orbit.open({ type: "set" });

// You can also specify the position on `put`
await db.put("c", "goes first", 0);
await db.add({a: 1});
await db.add({a: 2});

await db.all();
// [{ key: "c", value: "goes first", hash: "..." }, { key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]
const all = await db.all(); // [{a: 1}, {a: 2}]

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

0 comments on commit 0e71abc

Please sign in to comment.