mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Update README, fix examples
This commit is contained in:
parent
5cc2e8ee26
commit
0119a46fa5
57
README.md
57
README.md
@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Distributed, peer-to-peer Key-Value Store and Event Log on IPFS.
|
Distributed, peer-to-peer **Key-Value Store and Event Log** on IPFS.
|
||||||
|
|
||||||
This is the Javascript implementation and it works both in **Node.js** and **Browsers**.
|
This is the Javascript implementation and it works both in **Node.js** and **Browsers**.
|
||||||
|
|
||||||
- Stores all data in IPFS, including the database index
|
- Stores all data in IPFS, including the database index
|
||||||
- Aggregation happens on client side and data is eventually consistent
|
- Aggregation happens on client side and data is eventually consistent
|
||||||
- Uses a LWW-element-set [CRDT](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) and (sort of) Vector Clocks for partial ordering
|
- Uses a LWW-element-set [CRDT](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) and [ipfs-log](https://github.com/haadcode/ipfs-log) for partial order
|
||||||
- Designed to work offline first and to be easily embeddable to applications
|
- Designed to work offline first and to be easily embeddable to applications
|
||||||
|
|
||||||
_Currently requires [orbit-server](https://github.com/haadcode/orbit-server) for pubsub communication. This will change in the future as soon as IPFS provides pubsub._
|
_Currently requires [orbit-server](https://github.com/haadcode/orbit-server) for pubsub communication. This will change in the future as soon as IPFS provides pubsub._
|
||||||
|
|
||||||
_OrbitDB calls its namespaces channels. A channel is similar to "table", "keyspace", "topic", "feed" or "collection" in other db systems._
|

|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
```
|
```
|
||||||
@ -21,29 +21,22 @@ npm install orbit-db
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
### Browser examples
|
|
||||||
In order to run the browser example, you need to have a local IPFS daemon running. Start it with the following command:
|
|
||||||
```
|
|
||||||
API_ORIGIN=* ipfs daemon
|
|
||||||
```
|
|
||||||
|
|
||||||
Then open `examples/browser.html`. See the example code [here](https://github.com/haadcode/orbit-db/blob/master/examples/browser.html).
|
|
||||||
|
|
||||||
### Node.js examples
|
### Node.js examples
|
||||||
|
*To run the examples, make sure to run a local [orbit-server](https://github.com/haadcode/orbit-server)*
|
||||||
|
|
||||||
Before running the examples, install dependencies with:
|
Before running the examples, install dependencies with:
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Key-Value store example:
|
Key-Value store [example](https://github.com/haadcode/orbit-db/blob/master/examples/keyvalue.js):
|
||||||
```
|
```
|
||||||
node examples/keyvalue.js <host> <username> <channel> <key> <value>
|
node examples/keyvalue.js <host> <username> <channel> <key> <value>
|
||||||
node examples/keyvalueReader.js <host> <username> <channel> <key>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Event log example (run several in separate shells):
|
Event log [example](https://github.com/haadcode/orbit-db/blob/master/examples/eventlog.js) (run several in separate shells):
|
||||||
```
|
```
|
||||||
node examples/reader.js <host> <username> <channel> <data> <interval in ms>
|
node examples/eventlog.js <host> <username> <channel> <data> <interval in ms>
|
||||||
```
|
```
|
||||||
|
|
||||||
Benchmark writes:
|
Benchmark writes:
|
||||||
@ -51,9 +44,43 @@ Benchmark writes:
|
|||||||
node examples/benchmark.js <host> <username> <channel>;
|
node examples/benchmark.js <host> <username> <channel>;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Browser examples
|
||||||
|
In order to run the browser example, you need to have a local IPFS daemon running. Start it with the following command:
|
||||||
|
```
|
||||||
|
API_ORIGIN=* ipfs daemon
|
||||||
|
```
|
||||||
|
|
||||||
|
Then open `examples/browser.html`. See the full example [here](https://github.com/haadcode/orbit-db/blob/master/examples/browser.html).
|
||||||
|
|
||||||
|
```html
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" src="orbitdb.min.js" charset="utf-8"></script>
|
||||||
|
<script type="text/javascript" src="ipfsapi.min.js" charset="utf-8"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const ipfs = ipfsAPI();
|
||||||
|
OrbitDB.connect('localhost', 3333, 'user1', '', ipfs).then((orbit) => {
|
||||||
|
orbit.channel('test').then((db) => {
|
||||||
|
db.put('hello', 'world').then((res) => {
|
||||||
|
const result = db.get(key);
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
_See usage example below_
|
_See usage example below_
|
||||||
|
|
||||||
|
_OrbitDB calls its namespaces channels. A channel is similar to "table", "keyspace", "topic", "feed" or "collection" in other db systems._
|
||||||
|
|
||||||
connect(host, port, username, password)
|
connect(host, port, username, password)
|
||||||
|
|
||||||
channel(name, password)
|
channel(name, password)
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
var async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
var OrbitClient = require('../src/Client');
|
const ipfsd = require('ipfsd-ctl');
|
||||||
var Timer = require('./Timer');
|
const OrbitDB = require('../src/Client');
|
||||||
|
const Timer = require('./Timer');
|
||||||
|
|
||||||
// usage: benchmark.js <host> <username> <channel>;
|
// usage: benchmark.js <host> <username> <channel>;
|
||||||
|
|
||||||
@ -16,10 +17,20 @@ const password = '';
|
|||||||
|
|
||||||
const channelName = process.argv[4] ? process.argv[4] : 'c1';
|
const channelName = process.argv[4] ? process.argv[4] : 'c1';
|
||||||
|
|
||||||
|
const startIpfs = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipfsd.disposableApi((err, ipfs) => {
|
||||||
|
if(err) console.error(err);
|
||||||
|
resolve(ipfs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let run = (async(() => {
|
let run = (async(() => {
|
||||||
try {
|
try {
|
||||||
// Connect
|
// Connect
|
||||||
const orbit = await(OrbitClient.connect(host, port, username, password));
|
const ipfs = await(startIpfs());
|
||||||
|
const orbit = await(OrbitDB.connect(host, port, username, password, ipfs));
|
||||||
const db = await(orbit.channel(channelName));
|
const db = await(orbit.channel(channelName));
|
||||||
|
|
||||||
// Metrics
|
// Metrics
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
const async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
const await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
const OrbitClient = require('../src/Client');
|
const ipfsd = require('ipfsd-ctl');
|
||||||
|
const OrbitDB = require('../src/Client');
|
||||||
const Timer = require('./Timer');
|
const Timer = require('./Timer');
|
||||||
|
|
||||||
// usage: reader.js <host> <username> <channel> <data> <interval in ms>
|
// usage: reader.js <host> <username> <channel> <data> <interval in ms>
|
||||||
@ -17,9 +18,19 @@ const password = '';
|
|||||||
const channelName = process.argv[4] ? process.argv[4] : 'test';
|
const channelName = process.argv[4] ? process.argv[4] : 'test';
|
||||||
const prefix = process.argv[5] ? process.argv[5] : 'Hello';
|
const prefix = process.argv[5] ? process.argv[5] : 'Hello';
|
||||||
|
|
||||||
|
const startIpfs = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipfsd.disposableApi((err, ipfs) => {
|
||||||
|
if(err) console.error(err);
|
||||||
|
resolve(ipfs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let run = (async(() => {
|
let run = (async(() => {
|
||||||
try {
|
try {
|
||||||
const orbit = await(OrbitClient.connect(host, port, username, password));
|
const ipfs = await(startIpfs());
|
||||||
|
const orbit = await(OrbitDB.connect(host, port, username, password, ipfs));
|
||||||
const db = await(orbit.channel(channelName));
|
const db = await(orbit.channel(channelName));
|
||||||
|
|
||||||
let count = 1;
|
let count = 1;
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
const async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
const await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
const OrbitClient = require('../src/Client');
|
const ipfsd = require('ipfsd-ctl');
|
||||||
|
const OrbitDB = require('../src/Client');
|
||||||
const Timer = require('./Timer');
|
const Timer = require('./Timer');
|
||||||
|
|
||||||
// usage: keyvalue.js <host> <username> <channel> <key> <value>
|
// usage: keyvalue.js <host> <username> <channel> <key> <value>
|
||||||
@ -16,10 +17,20 @@ const password = '';
|
|||||||
|
|
||||||
const channel = process.argv[4] ? process.argv[4] : 'testing123';
|
const channel = process.argv[4] ? process.argv[4] : 'testing123';
|
||||||
|
|
||||||
|
const startIpfs = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipfsd.disposableApi((err, ipfs) => {
|
||||||
|
if(err) console.error(err);
|
||||||
|
resolve(ipfs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let run = (async(() => {
|
let run = (async(() => {
|
||||||
try {
|
try {
|
||||||
const orbit = await(OrbitClient.connect(host, port, username, password));
|
const ipfs = await(startIpfs());
|
||||||
const db = await(orbit.channel(channelName));
|
const orbit = await(OrbitDB.connect(host, port, username, password, ipfs));
|
||||||
|
const db = await(orbit.channel(channel));
|
||||||
|
|
||||||
let count = 1;
|
let count = 1;
|
||||||
|
|
||||||
@ -27,7 +38,7 @@ let run = (async(() => {
|
|||||||
const key = process.argv[5] ? process.argv[5] : 'greeting';
|
const key = process.argv[5] ? process.argv[5] : 'greeting';
|
||||||
const value = process.argv[6] ? process.argv[6] : 'Hello world';
|
const value = process.argv[6] ? process.argv[6] : 'Hello world';
|
||||||
const timer = new Timer(true);
|
const timer = new Timer(true);
|
||||||
db.put(key, value + " " + count);
|
await(db.put(key, value + " " + count));
|
||||||
const result = db.get(key);
|
const result = db.get(key);
|
||||||
|
|
||||||
console.log("---------------------------------------------------")
|
console.log("---------------------------------------------------")
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const async = require('asyncawait/async');
|
|
||||||
const await = require('asyncawait/await');
|
|
||||||
const OrbitClient = require('../src/Client');
|
|
||||||
const Timer = require('./Timer');
|
|
||||||
|
|
||||||
// usage: keyvalueReader.js <host> <username> <channel> <key>
|
|
||||||
|
|
||||||
// orbit-server
|
|
||||||
const host = process.argv[2] ? process.argv[2] : 'localhost'
|
|
||||||
const port = 3333;
|
|
||||||
|
|
||||||
const username = process.argv[3] ? process.argv[3] : 'LambOfGod';
|
|
||||||
const password = '';
|
|
||||||
|
|
||||||
const channelName = process.argv[4] ? process.argv[4] : 'testing123';
|
|
||||||
const key = process.argv[5] ? process.argv[5] : 'greeting';
|
|
||||||
|
|
||||||
let run = (async(() => {
|
|
||||||
try {
|
|
||||||
const orbit = await(OrbitClient.connect(host, port, username, password));
|
|
||||||
const db = await(orbit.channel(channelName));
|
|
||||||
|
|
||||||
let count = 1;
|
|
||||||
|
|
||||||
setInterval(async(() => {
|
|
||||||
let timer = new Timer(true);
|
|
||||||
const result = db.get(key);
|
|
||||||
|
|
||||||
console.log("---------------------------------------------------")
|
|
||||||
console.log("Key | Value")
|
|
||||||
console.log("---------------------------------------------------")
|
|
||||||
console.log(`${key} | ${result}`);
|
|
||||||
console.log("---------------------------------------------------")
|
|
||||||
console.log(`Query #${count} took ${timer.stop(true)} ms\n`);
|
|
||||||
|
|
||||||
count ++;
|
|
||||||
}), 1000);
|
|
||||||
} catch(e) {
|
|
||||||
console.error("error:", e);
|
|
||||||
console.error(e.stack);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}))();
|
|
||||||
|
|
||||||
module.exports = run;
|
|
@ -31,6 +31,7 @@
|
|||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"lodash": "^4.3.0",
|
"lodash": "^4.3.0",
|
||||||
"mocha": "^2.4.5",
|
"mocha": "^2.4.5",
|
||||||
|
"orbit-common": "^0.2.5",
|
||||||
"stream-http": "^2.2.1",
|
"stream-http": "^2.2.1",
|
||||||
"webpack": "^1.12.15"
|
"webpack": "^1.12.15"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user