orbit-db/README.md

293 lines
12 KiB
Markdown
Raw Normal View History

2017-12-31 09:45:05 +02:00
# OrbitDB
2015-12-26 19:05:51 +02:00
2019-01-04 16:22:41 -05:00
<p align="left">
<img src="images/orbit_db_logo_color.jpg" width="256" />
2019-01-04 16:16:49 -05:00
</p>
2019-02-05 12:03:55 -05:00
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![CircleCI Status](https://circleci.com/gh/orbitdb/orbit-db.svg?style=shield)](https://circleci.com/gh/orbitdb/orbit-db) [![npm version](https://badge.fury.io/js/orbit-db.svg)](https://www.npmjs.com/package/orbit-db) [![node](https://img.shields.io/node/v/orbit-db.svg)](https://www.npmjs.com/package/orbit-db)
2016-08-09 16:56:51 +02:00
OrbitDB is a **serverless, distributed, peer-to-peer database**. OrbitDB 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 OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and offline-first web applications.
2015-12-26 19:05:51 +02:00
**Test it live at [Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/), [Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/), or [P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**!
2016-06-08 16:43:09 +02:00
2016-06-08 16:44:39 +02:00
2018-07-12 15:07:30 -04:00
OrbitDB provides various types of databases for different data models and use cases:
2016-10-04 18:40:22 +02:00
2018-07-12 15:51:36 -04:00
- **[log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress)**: an immutable (append-only) log with traversable history. Useful for *"latest N"* use cases or as a message queue.
2019-02-06 07:19:48 -08:00
- **[feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress)**: a mutable log with traversable history. Entries can be added and removed. Useful for *"shopping cart"* type of use cases, or for example as a feed of blog posts or "tweets".
2018-07-12 15:51:36 -04:00
- **[keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress)**: a key-value database just like your favourite key-value database.
- **[docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options)**: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data.
- **[counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress)**: Useful for counting events separate from log/feed data.
2017-09-18 09:11:01 +02:00
2018-07-20 09:22:53 -04:00
All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on top of [ipfs-log](https://github.com/orbitdb/ipfs-log), an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. If none of the OrbitDB database types match your needs and/or you need case-specific functionality, you can easily [implement and use a custom database store](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#custom-stores) of your own.
2016-06-08 16:44:39 +02:00
2018-07-12 15:07:30 -04:00
#### Project status & support
Status: **in active development**
***NOTE!*** *OrbitDB is **alpha-stage** software. It means OrbitDB hasn't been security audited and programming APIs and data formats can still change. We encourage you to [reach out to the maintainers](https://gitter.im/orbitdb/Lobby) if you plan to use OrbitDB in mission critical systems.*
This is the Javascript implementation and it works both in **Browsers** and **Node.js** with support for Linux and OS X (Windows is not supported yet). The minimum required version of Node.js is now 8.6.0 due to the usage of `...` spread syntax. LTS versions (even numbered versions 8, 10, etc) are preferred.
To use with older versions of Node.js, we provide an ES5-compatible build through the npm package, located in `dist/es5/` when installed through npm.
2017-03-21 18:27:40 +01:00
#### Community Calls
We also have regular community calls, which we announce in the issues in [the @orbitdb welcome repository](https://github.com/orbitdb/welcome/issues). Join us!
2016-10-10 08:49:38 -04:00
## Table of Contents
<!-- toc -->
2016-10-10 08:49:38 -04:00
- [Usage](#usage)
* [CLI](#cli)
* [Module with IPFS Instance](#module-with-ipfs-instance)
* [Module with IPFS Daemon](#module-with-ipfs-daemon)
2016-10-10 08:49:38 -04:00
- [API](#api)
- [Examples](#examples)
* [Install dependencies](#install-dependencies)
* [Browser example](#browser-example)
* [Node.js example](#nodejs-example)
2018-07-12 15:07:30 -04:00
- [Packages](#packages)
* [OrbitDB Store Packages](#orbitdb-store-packages)
2016-10-10 08:49:38 -04:00
- [Development](#development)
* [Run Tests](#run-tests)
* [Build](#build)
* [Benchmark](#benchmark)
* [Logging](#logging)
- [Frequently Asked Questions](#frequently-asked-questions)
2016-10-10 08:49:38 -04:00
- [Contributing](#contributing)
- [Sponsors](#sponsors)
2016-10-10 08:49:38 -04:00
- [License](#license)
<!-- tocstop -->
2016-10-04 22:07:24 +02:00
## Usage
2016-11-02 13:50:15 +01:00
Read the **[GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** guide for a more in-depth tutorial and to understand how OrbitDB works.
2017-09-18 09:11:01 +02:00
### CLI
For the CLI tool to manage orbit-db database, see **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**.
It can be installed from npm with:
2017-09-18 09:11:01 +02:00
```
npm install orbit-db-cli -g
```
2018-07-12 15:07:30 -04:00
### Module with IPFS Instance
If you're using `orbitd-db` to develop **browser** or **Node.js** applications, use it as a module with the javascript instance of IPFS
2017-09-18 09:11:01 +02:00
Install dependencies:
2017-09-18 09:11:01 +02:00
2016-08-09 16:56:51 +02:00
```
2019-06-04 13:32:06 -04:00
npm install orbit-db ipfs@0.35.0
2016-08-09 16:56:51 +02:00
```
2016-07-26 11:45:12 +01:00
```javascript
const IPFS = require('ipfs')
2016-08-09 16:56:51 +02:00
const OrbitDB = require('orbit-db')
// OrbitDB uses Pubsub which is an experimental feature
// and need to be turned on manually.
2018-07-12 15:07:30 -04:00
// Note that these options need to be passed to IPFS in
2018-09-16 23:04:56 +02:00
// all examples even if not specified so.
const ipfsOptions = {
EXPERIMENTAL: {
pubsub: true
2018-07-12 15:07:30 -04:00
}
}
// Create IPFS instance
const ipfs = new IPFS(ipfsOptions)
2017-01-17 09:38:18 +01:00
ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', async () => {
2019-02-20 14:36:38 +00:00
const orbitdb = await OrbitDB.createInstance(ipfs)
2018-07-12 15:07:30 -04:00
// Create / Open a database
const db = await orbitdb.log('hello')
await db.load()
// Listen for updates from peers
db.events.on('replicated', (address) => {
console.log(db.iterator({ limit: -1 }).collect())
})
// Add an entry
const hash = await db.add('world')
console.log(hash)
// Query
const result = db.iterator({ limit: -1 }).collect()
console.log(JSON.stringify(result, null, 2))
2017-01-17 09:38:18 +01:00
})
2016-07-26 11:45:12 +01:00
```
2018-07-12 15:07:30 -04:00
### Module with IPFS Daemon
Alternatively, you can use [ipfs-api](https://npmjs.org/package/ipfs-api) to use `orbit-db` with a locally running IPFS daemon. Use this method if you're using `orbitd-db` to develop **backend** or **desktop** applications, eg. with [Electron](https://electron.atom.io).
2016-11-02 13:50:15 +01:00
2018-07-12 15:07:30 -04:00
Install dependencies:
2016-11-02 13:50:15 +01:00
2018-07-12 15:07:30 -04:00
```
2019-02-20 14:36:38 +00:00
npm install orbit-db ipfs-http-client
2018-07-12 15:07:30 -04:00
```
```javascript
2019-02-20 14:36:38 +00:00
const IpfsClient = require('ipfs-http-client')
2018-07-12 15:07:30 -04:00
const OrbitDB = require('orbit-db')
2019-02-20 14:36:38 +00:00
const ipfs = IpfsClient('localhost', '5001')
const orbitdb = await OrbitDB.createInstance(ipfs)
const db = await orbitdb.log('hello')
// Do something with your db.
2019-05-01 15:11:23 -04:00
// Of course, you may want to wrap these in an async function.
2018-07-12 15:07:30 -04:00
```
2016-10-10 08:49:38 -04:00
## API
See [API.md](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation.
2018-07-12 15:07:30 -04:00
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
```
You'll also need babel and webpack, if you don't have them installed already:
```
npm install --global babel-cli
npm install --global webpack
```
2018-07-12 15:07:30 -04:00
Some dependencies depend on native addon modules, so you'll also need to meet [node-gyp's](https://github.com/nodejs/node-gyp#installation) installation prerequisites. Therefore, Linux users may need to
```
make clean && make
```
2018-07-12 15:07:30 -04:00
to redo the local package-lock.json with working native dependencies.
2016-10-04 22:07:24 +02:00
### Browser example
In macOS:
```
npm run build
npm run examples:browser-macos
```
In Linux:
2016-10-04 22:07:24 +02:00
```
npm run build
npm run examples:browser-linux
2016-04-15 16:28:56 +02:00
```
<p align="left">
<img src="https://raw.githubusercontent.com/orbitdb/orbit-db/master/images/example1.png" width="33%">
</p>
2016-10-04 22:07:24 +02:00
Check the code in [examples/browser/browser.html](https://github.com/orbitdb/orbit-db/blob/master/examples/browser/browser.html) and try the [live example](https://ipfs.io/ipfs/QmRosp97r8GGUEdj5Wvivrn5nBkuyajhRXFUcWCp5Zubbo/).
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
```
<img src="https://raw.githubusercontent.com/orbitdb/orbit-db/master/images/orbit-db-demo3.gif" width="66%">
2016-10-04 22:07:24 +02:00
**Eventlog**
See 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
```
node examples/eventlog.js
2016-07-31 11:16:14 +02:00
```
More examples at [examples](https://github.com/orbitdb/orbit-db/tree/master/examples).
2016-04-15 15:53:17 +02:00
2018-07-12 15:07:30 -04:00
## Packages
2018-07-12 15:07:30 -04:00
OrbitDB uses the following modules:
2018-07-12 15:07:30 -04:00
- [ipfs](https://github.com/ipfs/js-ipfs)
- [ipfs-log](https://github.com/orbitdb/ipfs-log)
2018-07-19 08:54:33 -04:00
- [ipfs-pubsub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room)
2018-07-12 15:07:30 -04:00
- [crdts](https://github.com/orbitdb/crdts)
- [orbit-db-cache](https://github.com/orbitdb/orbit-db-cache)
2018-07-12 15:51:36 -04:00
- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub)
2019-02-20 14:36:38 +00:00
- [orbit-db-identity-provider](https://github.com/orbitdb/orbit-db-identity-provider)
- [orbit-db-access-controllers](https://github.com/orbitdb/orbit-db-access-controllers)
### OrbitDB Store Packages
2018-07-12 15:07:30 -04:00
- [orbit-db-store](https://github.com/orbitdb/orbit-db-store)
- [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore)
- [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore)
- [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore)
- [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore)
- [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore)
2018-07-12 15:07:30 -04:00
To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/.
2019-01-09 10:53:43 -05:00
Community-maintained Typescript typings are available here: https://github.com/orbitdb/orbit-db-types
2019-01-08 17:40:23 -05:00
2016-10-04 18:40:22 +02:00
## Development
2015-12-27 17:27:17 +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
### Build
2016-10-04 22:07:24 +02:00
```
2016-10-04 18:40:22 +02:00
npm run build
```
2015-12-27 17:27:17 +02:00
### Benchmark
```
node benchmarks/benchmark-add.js
```
2018-07-12 15:33:28 -04:00
See [benchmarks/](https://github.com/orbitdb/orbit-db/tree/master/benchmarks) for more benchmarks.
2017-11-28 13:22:44 +01:00
### Logging
To enable OrbitDB's logging output, set a global ENV variable called `LOG` to `debug`,`warn` or `error`:
```
LOG=debug node <file>
```
2016-01-19 21:59:53 +08:00
## Frequently Asked Questions
We have an FAQ! [Go take a look at it](FAQ.md). If a question isn't there, open an issue and suggest adding it. We can work on the best answer together.
2016-10-04 18:40:22 +02:00
## Contributing
**Take a look at our organization-wide [Contributing Guide](https://github.com/orbitdb/welcome/blob/master/contributing.md).** You'll find most of your questions answered there. Some questions may be answered in the [FAQ](FAQ.md), as well.
As far as code goes, 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 Gitter](https://gitter.im/orbitdb/Lobby), or in the [issues section](https://github.com/orbitdb/orbit-db/issues).
We also have **regular community calls**, which we announce in the issues in [the @orbitdb welcome repository](https://github.com/orbitdb/welcome/issues). Join us!
2019-02-05 12:10:19 -05:00
If you want to code but don't know where to start, check out 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).
2016-10-04 22:07:24 +02:00
Please note that we have a [Code of Conduct](CODE_OF_CONDUCT.md), and that all activity in the [@orbitdb](https://github.com/orbitdb) organization falls under it. Read it when you get the chance, as being part of this community means that you agree to abide by it. Thanks.
## Sponsors
The development of OrbitDB has been sponsored by:
* [Haja Networks](https://haja.io)
* [Protocol Labs](https://protocol.ai/)
* [Maintainer Mountaineer](https://maintainer.io)
If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode.
2016-10-04 18:40:22 +02:00
## License
2018-08-14 14:03:51 -04:00
[MIT](LICENSE) © 2015-2018 Protocol Labs Inc., Haja Networks Oy