orbit-db/README.md

158 lines
5.7 KiB
Markdown
Raw Normal View History

# orbit-db
2015-12-26 19:05:51 +02:00
2016-11-02 13:50:15 +01:00
[![npm version](https://badge.fury.io/js/orbit-db.svg)](https://badge.fury.io/js/orbit-db)
2017-03-31 11:53:01 +02:00
[![CircleCI Status](https://circleci.com/gh/orbitdb/orbit-db.svg?style=shield)](https://circleci.com/gh/orbitdb/orbit-db)
2016-11-02 13:50:15 +01:00
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![Project Status](https://badge.waffle.io/haadcode/orbit.svg?label=In%20Progress&title=In%20Progress)](https://waffle.io/haadcode/orbit?source=haadcode%2Forbit-db,haadcode%2Forbit-db-counterstore,haadcode%2Forbit-db-eventstore,haadcode%2Forbit-db-feedstore,haadcode%2Forbit-db-kvstore,haadcode%2Forbit-db-store,haadcode%2Fipfs-log)
2016-08-09 16:56:51 +02:00
> Distributed, peer-to-peer database on IPFS.
2016-11-02 13:50:15 +01:00
`orbit-db` is a serverless, distributed, peer-to-peer database. `orbit-db` uses [IPFS](https://ipfs.io) as its data storage and [IPFS Pubsub](https://github.com/ipfs/go-ipfs/blob/master/core/commands/pubsub.go#L23) to automatically sync databases with peers. It's an eventually consistent database that uses [CRDTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) for conflict-free database merges making `orbit-db` and excellent choice for offline-first applications.
2015-12-26 19:05:51 +02:00
2016-10-04 22:07:24 +02:00
Data in `orbit-db` can be stored in a
2016-06-08 16:43:09 +02:00
2017-03-31 11:53:01 +02:00
- **[Key-Value Store](https://github.com/orbitdb/orbit-db-kvstore)**
- **[Eventlog](https://github.com/orbitdb/orbit-db-eventstore)** (append-only log)
- **[Feed](https://github.com/orbitdb/orbit-db-feedstore)** (add and remove log)
- **[Documents](https://github.com/orbitdb/orbit-db-docstore)** (indexed by custom fields)
- **[Counters](https://github.com/orbitdb/orbit-db-counterstore)**
2016-06-08 16:44:39 +02:00
2016-10-04 22:07:24 +02:00
This is the Javascript implementation and it works both in **Node.js** and **Browsers**.
2016-10-04 18:40:22 +02:00
2017-03-21 18:27:40 +01:00
Try the [live demo](https://ipfs.io/ipfs/QmUETzzv9FxBwPn4H6q3i6QXTzicvV3MMuKN53JQU3yMSG/)!
2016-10-10 08:49:38 -04:00
## Table of Contents
- [Usage](#usage)
- [API](#api)
- [Examples](#examples)
- [Development](#development)
- [Background](#background)
- [Contributing](#contributing)
- [License](#license)
2016-10-04 22:07:24 +02:00
## Usage
2016-11-02 13:50:15 +01:00
2016-08-09 16:56:51 +02:00
```
2017-01-17 09:38:18 +01:00
npm install orbit-db ipfs-daemon
2016-08-09 16:56:51 +02:00
```
2016-07-26 11:45:12 +01:00
```javascript
2017-01-17 09:38:18 +01:00
const IPFS = require('ipfs-daemon/src/ipfs-node-daemon')
2016-08-09 16:56:51 +02:00
const OrbitDB = require('orbit-db')
2016-10-04 18:40:22 +02:00
2017-01-17 09:38:18 +01:00
const ipfs = new IPFS()
ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', (e) => {
const orbitdb = new OrbitDB(ipfs)
2016-10-04 18:40:22 +02:00
2017-01-17 09:38:18 +01:00
const db = orbitdb.eventlog("feed name")
2016-10-04 18:40:22 +02:00
2017-01-17 09:38:18 +01:00
db.add("hello world")
.then(() => {
const latest = db.iterator({ limit: 5 }).collect()
console.log(JSON.stringify(latest, null, 2))
})
})
2016-07-26 11:45:12 +01:00
```
2017-03-31 11:53:01 +02:00
*For more details, see examples for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/shamb0t/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).*
2016-11-02 13:50:15 +01:00
2016-10-10 08:49:38 -04:00
## API
2017-03-31 11:53:01 +02:00
See [API documentation](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbit-db-api-documentation) for the full documentation.
2017-03-31 11:53:01 +02:00
- [Getting Started](https://github.com/orbitdb/orbit-db/blob/master/API.md#getting-started)
- [orbitdb](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdb)
- [kvstore(name)](https://github.com/orbitdb/orbit-db/blob/master/API.md#kvstorename)
- [eventlog(name)](https://github.com/orbitdb/orbit-db/blob/master/API.md#eventlogname)
- [feed(name)](https://github.com/orbitdb/orbit-db/blob/master/API.md#feedname)
- [docstore(name, options)](https://github.com/orbitdb/orbit-db/blob/master/API.md#docstorename-options)
- [counter(name)](https://github.com/orbitdb/orbit-db/blob/master/API.md#countername)
- [disconnect()](https://github.com/orbitdb/orbit-db/blob/master/API.md#disconnect)
- [events](https://github.com/orbitdb/orbit-db/blob/master/API.md#events)
2016-02-26 13:39:51 +01:00
## Examples
2016-04-15 16:28:56 +02:00
### Install dependencies
2016-07-31 11:43:37 +02:00
2016-10-04 22:07:24 +02:00
```
2017-03-31 11:53:01 +02:00
git clone https://github.com/orbitdb/orbit-db.git
2016-10-04 22:07:24 +02:00
cd orbit-db
2016-07-31 11:11:33 +02:00
npm install
2016-10-04 22:07:24 +02:00
```
### Browser example
```
2016-10-04 19:00:42 +02:00
npm run build:examples
2016-10-04 18:40:22 +02:00
npm run examples:browser
2016-04-15 16:28:56 +02:00
```
2017-03-31 11:53:01 +02:00
<img src="https://raw.githubusercontent.com/orbitdb/orbit-db/feat/ipfs-pubsub/screenshots/orbit-db-demo1.gif" width="33%">
2016-10-04 22:07:24 +02:00
2017-03-31 11:53:01 +02:00
Check the code in [examples/browser/browser.html](https://github.com/orbitdb/orbit-db/blob/master/examples/browser/browser.html).
2016-10-04 22:07:24 +02:00
2016-10-04 18:40:22 +02:00
### Node.js example
2016-07-31 11:16:14 +02:00
2016-10-04 22:07:24 +02:00
```
2016-10-04 18:40:22 +02:00
npm run examples:node
2016-07-31 11:16:14 +02:00
```
2017-03-31 11:53:01 +02:00
<img src="https://raw.githubusercontent.com/orbitdb/orbit-db/feat/ipfs-pubsub/screenshots/orbit-db-demo3.gif" width="66%">
2016-10-04 22:07:24 +02:00
**Eventlog**
2017-03-31 11:53:01 +02:00
Check the code in [examples/eventlog.js](https://github.com/orbitdb/orbit-db/blob/master/examples/eventlog.js) and run it with:
2016-10-04 22:07:24 +02:00
```
LOG=debug node examples/eventlog.js
2016-07-31 11:16:14 +02:00
```
**Key-Value**
2017-03-31 11:53:01 +02:00
Check the code in [examples/keyvalue.js](https://github.com/orbitdb/orbit-db/blob/master/examples/keystore.js) and run it with:
```
LOG=debug node examples/keyvalue.js
2016-10-04 22:07:24 +02:00
```
2016-04-15 15:53:17 +02:00
2016-10-04 18:40:22 +02:00
## Development
2015-12-27 17:27:17 +02:00
2016-10-04 18:40:22 +02:00
#### Run Tests
2016-10-04 22:07:24 +02:00
```
2016-10-04 18:40:22 +02:00
npm test
```
2016-02-12 09:27:57 +01:00
2016-10-04 22:07:24 +02:00
#### Build
```
2016-10-04 18:40:22 +02:00
npm run build
```
2015-12-27 17:27:17 +02:00
#### Benchmark
```
node examples/benchmark.js
```
2016-01-19 21:59:53 +08:00
## Background
2015-12-27 17:27:17 +02:00
2017-03-31 11:53:01 +02:00
Check out a visualization of the data flow at https://github.com/haadcode/proto2.
2015-12-27 17:27:17 +02:00
**TODO**
- list of modules used
- orbit-db-pubsub
- crdts
- ipfs-log
2016-01-19 21:59:53 +08:00
2016-10-04 18:40:22 +02:00
## Contributing
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
2017-03-31 11:53:01 +02:00
We would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us on IRC #ipfs on Freenode, or in the comments of the [issues section](https://github.com/orbitdb/orbit-db/issues).
2017-03-31 11:53:01 +02:00
A good place to start are the issues labelled ["help wanted"](https://github.com/orbitdb/orbit-db/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+sort%3Areactions-%2B1-desc) or the project's [status board](https://waffle.io/orbitdb/orbit-db).
2016-10-04 22:07:24 +02:00
2016-10-04 18:40:22 +02:00
## License
[MIT](LICENSE) ©️ 2016 Haadcode