# ssb-entitydb

> An entitity database Scuttlebot applications

Latest version **1.0.0** (published 2016-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install ssb-entitydb
pnpm add ssb-entitydb
yarn add ssb-entitydb
bun add ssb-entitydb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-05-08 |
| First published | 2016-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Anders Rune Jensen |
| Maintainers | arj03 |
| Keywords | ssb, scuttlebot, db |

## Links

- npm: https://www.npmjs.com/package/ssb-entitydb
- Repository: https://github.com/arj03/ssb-entitydb
- Issues: https://github.com/arj03/ssb-entitydb/issues
- npm.io page: https://npm.io/package/ssb-entitydb

## Dependencies (6)

- [multicb](https://npm.io/package/multicb.md) ^1.2.1
- [ssb-keys](https://npm.io/package/ssb-keys.md) ^5.0.1
- [scuttlebot](https://npm.io/package/scuttlebot.md) ^8.1.0
- [ssb-client](https://npm.io/package/ssb-client.md) ^3.0.1
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.3.2
- [pull-through](https://npm.io/package/pull-through.md) ^1.0.18

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-05-08

## README

# SSB entity DB

An entity database for [Scuttlebot applications](https://github.com/ssbc/scuttlebot).

## About

This interface lets you focus on writing applications, instead of
working with the SSB log. The entities can be written or changed by
any node, and these are replicated on the mesh network. It works just
like any eventually consistent database (CouchDB, or Riak), but it's
global and p2p.

The database consists of two modes. A write mode in which values are
appended to the local database. And a reader mode which reads all logs
in a current namespace and writes a log with merged values. This
seperation is inspired by CQRS.

Multiple users may update the database without locking.

#### Conflicts

If two users update a value at the same time, then both values will be kept.
This is technically a "conflict", though you may wish to keep all values.
Anyone can resolve the conflict by writing a new value.

#### Entities

Entities consists of the following fields:

Type: The type of the entity

Id: A unique identifier for the entity. Two entities with the same id
and type are considered the same.

Metadata: Dictionary of system specific metadata such as a list of
latest sequence number for nodes, an application specific which could
include things such as timestamps and usernames. Please note that
these application specific attributes are only used for debugging, as
opposed to system specific. Sequence number of nodes should only
include the nodes participating in the namespace. And should prune
old inactive nodes.

Values: For values we differentiate between write mode and read modes.
Write can never have conflicts as they are local and as such is just a
dictionary of attribute to value mappings. One is expected to write
all values every time, not just changes. Read modes on the other hand
can potentially be in conflict if two nodes write to the same entity
without seeing each other changes (see metadata). In this case values
becomes a list of objects with the following attributes: { node:
<nodeid>, sequence: <node-sequence>, values: <values> }.

#### Deletes

The api has no specific delete operation. Delete should be implemented
as an attribute on the entity. It is the job of the reader to
interpret this in an application specific way. The default
implementation will treat `n` concurrent updates with a delete among
them as a delete.

## API

 - `entityDB()`
 - `db.write()`
 - `db.writeAll()`
 - `db.get()`
 - `db.getAllById()`
 - `db.getAll()`
 - `db.onChange()`
 - `db.onTypeChange()`
 - `db.onEntityChange()`

---

### entityDB(namespace, [options])

Creates and returns a new database instance.

#### namespace

The `namespace` string is required.

Reads and writes will be scoped to the namespace, making it easier to
avoid accidental key collisions.

---

### db.write(type, id, values, metadata, cb)

Write an entity to the log.

---

### db.writeAll(array, cb)

Complete a sequence of write operations. Array must consist of objects
with `type`, `id`, `type` and optional `metadata`.

---

### db.get(type, id, cb)

Gets the latest version (values) of an entity with a given `type` and
`id`.

---

### db.getAllById(type, id)

Streams all versions of an entity with a given `type` and `id`. Please note
this returns objects with values and metadata as opposed to get which
only returns values.

---

### db.getAll(type)

Returns as stream of sequential messages of a given `type` from the database.

---

### db.onChange()

Returns a stream of changes on all types. Please note these changes
consists of keys as well as values, which is different from the
onTypeChange, onEntityChange.

---

### db.onTypeChange(type)

Returns a stream of changes on specific `type`

---

### db.onEntityChange(type, id)

Returns a stream of changes on specific `id` with `type`.

---
_Source: https://npm.io/package/ssb-entitydb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
