https://github.com/orbitdb/ordered-keyvalue-db
Ordered keyvalue database type for orbit-db
https://github.com/orbitdb/ordered-keyvalue-db
Last synced: 3 months ago
JSON representation
Ordered keyvalue database type for orbit-db
- Host: GitHub
- URL: https://github.com/orbitdb/ordered-keyvalue-db
- Owner: orbitdb
- License: agpl-3.0
- Created: 2024-01-20T22:10:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T05:31:01.000Z (over 1 year ago)
- Last Synced: 2024-12-31T12:26:19.677Z (over 1 year ago)
- Language: TypeScript
- Size: 518 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @orbitdb/ordered-keyvalue-db
Ordered keyvalue database type for OrbitDB.
[](https://github.com/orbitdb/ordered-keyvalue-db/actions/workflows/tests.yml)
[](https://codecov.io/gh/orbitdb/ordered-keyvalue-db)
## Installation
```
$ pnpm add @orbitdb/ordered-keyvalue-db
```
## Introduction
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.).
## Examples
```ts
import { createOrbitDB } from "@orbitdb/core";
import { registerOrderedKeyValue } from "@orbitdb/ordered-keyvalue-db";
// Register database type. IMPORTANT - must call before creating orbit instance !
registerOrderedKeyValue();
const orbit = await createOrbitDB({ ipfs })
const db = await orbit.open({ type: "ordered-keyvalue" });
await db.put("a", "some value");
await db.put("b", "another value");
const all = await db.all();
// [{ key: "a", value: "some value", hash: "..." }, { key: "b", value: "another value", hash: "..." }]
await db.move("a", 1)
await db.all();
// [{ key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]
// You can also specify the position on `put`
await db.put("c", "goes first", 0);
await db.all();
// [{ key: "c", value: "goes first", hash: "..." }, { key: "b", value: "another value", hash: "..." }, { key: "a", value: "some value", hash: "..." }]
```