Update README

This commit is contained in:
haad 2016-07-31 11:16:14 +02:00
parent d5fa79515c
commit 4d6747a71b

150
README.md
View File

@ -48,6 +48,40 @@ npm install orbit-db
``` ```
## Examples ## Examples
### Browser examples
Build the examples:
```bash
npm install
npm run build:examples
```
Then open `examples/browser.html` or `examples/index.html`. See the full example [here](https://github.com/haadcode/orbit-db/blob/master/examples/browser/browser.html).
```html
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript" src="../dist/orbitdb.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../node_modules/logplease/dist/logplease.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript">
const ipfs = window.Ipfs();
OrbitDB.connect('localhost:3333', 'user1', '', ipfs)
.then((orbit) => orbit.kvstore('test'))
.then((db) => db.put('hello', 'world'))
.then((res) => {
const result = db.get(key)
console.log(result)
})
</script>
</body>
</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)* *To run the examples, make sure to run a local [orbit-server](https://github.com/haadcode/orbit-server)*
@ -71,40 +105,6 @@ Benchmark writes:
node examples/benchmark.js <host:port> <username> <channel>; node examples/benchmark.js <host:port> <username> <channel>;
``` ```
### Browser examples
Build the examples:
```bash
npm install
npm run build:examples
```
Then open `examples/browser.html` or `examples/index.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="../dist/orbitdb.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../node_modules/logplease/dist/logplease.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript">
const ipfs = IpfsApi();
OrbitDB.connect('localhost:3333', 'user1', '', ipfs)
.then((orbit) => orbit.kvstore('test'))
.then((db) => db.put('hello', 'world'))
.then((res) => {
const result = db.get(key)
console.log(result)
})
</script>
</body>
</html>
```
## API ## API
**NOTE: the API documentation is currently out of date. It will be updated soon!** **NOTE: the API documentation is currently out of date. It will be updated soon!**
@ -183,8 +183,6 @@ async(() => {
``` ```
### Development ### Development
#### Source Code
The entry point for the code is [src/Client.js](https://github.com/haadcode/orbit-db/blob/master/src/Client.js) and the DB implementation is [src/OrbitDB.js](https://github.com/haadcode/orbit-db/blob/master/src/OrbitDB.js)
#### Run Tests #### Run Tests
```bash ```bash
@ -201,83 +199,3 @@ mocha -w
npm install npm install
npm run build npm run build
``` ```
### TODO
- make ipfs-log emit events ('data', 'load')
- Store: this._log.events.on('data', (log, entries) => this._index.updateIndex(log, entries))
- merge 'readable' and 'data' events (only one)
## Notes
### Data structure description
*For future [IPLD](https://github.com/ipfs/ipld-examples) references*
List snapshots are posted to pubsub:
```
> QmRzWAiFdLkdkwBDehzxhHdhfwbDKDnzqBnX53va58PuQu
> ...
```
**Get a list snapshot**
`ipfs object get QmRzWAiFdLkdkwBDehzxhHdhfwbDKDnzqBnX53va58PuQu`
```json
{
"Links": [],
"Data": {
"id": "user123",
"items": [
"QmNwREbsgGgiQPXxpvGanD55inFjUXjpEqjiPtpa39P7Mn",
"QmQxndNEzWxKT5KRqRsty7JDGcbPVazaYPCqfB5z1mxmon",
"QmUN1X97M2t8MX55H8VoPGXu2fLBpr91iCAzHkXudSMvDE"
]
}
}
```
**Get the item**
`ipfs object get QmNwREbsgGgiQPXxpvGanD55inFjUXjpEqjiPtpa39P7Mn`
```json
{
"Links": [],
"Data": {
"id": "user123",
"data": "QmasZEUwc67yftPvdSxRLWenmvF8faLnS7TMphQpn4PCWZ",
"next": [
"QmS17ABxzFEVoHv5WEvATetNEZhN2vkNApRPcFQUaJfij3"
]
}
}
```
**Get the item's data (operation)**
`ipfs object get QmasZEUwc67yftPvdSxRLWenmvF8faLnS7TMphQpn4PCWZ`
```json
{
"Links": [],
"Data": {
"op": "PUT",
"key": "default",
"value": "QmaAPEKDdaucQZRseJmKmWwZhgftBSwj8TD1xEomgcxo1X",
"meta":{
"type": "text",
"size": -1,
"from": "user123",
"ts": 1456494484094
}
}
}
```
**Get the value**
`ipfs object get QmaAPEKDdaucQZRseJmKmWwZhgftBSwj8TD1xEomgcxo1X`
```json
{
"Links": [],
"Data": {
"content": "LambOfGod 347",
"ts": 1456494484089
}
}
```