Home

Awesome

orbit-db-counterstore

Gitter Matrix Discord npm version

Counters database for OrbitDB

A simple counters database. Useful for example counting events separate from data.

Used in orbit-db.

Table of Contents

Install

This project uses npm and nodejs

npm install orbit-db ipfs

Usage

First, create an instance of OrbitDB:

import * as IPFS from 'ipfs'
import OrbitDB from 'orbit-db'

const ipfs = new IPFS()
const orbitdb = OrbitDB.createInstance(ipfs)

Get a log database and add an entry to it:

const counter = await orbitdb.counter('visitors')
await counter.inc()
console.log(counter.value)
// 1
await counter.inc(4)
console.log(counter.value)
// 5

Later, when the database contains data, load the history and query when ready:

const counter = await orbitdb.counter('visitors')
counter.events.on('ready', () => {
  await counter.inc()
  console.log(counter.value)
  // 6
})

See example/index.html for a detailed example. Note that to run this example, you need to have a local IPFS daemon running at port 5001.

API

See OrbitDB's API Documentation for full details.

Contribute

Please, feel free to contribute! Take a look at the issues, and comment on an existing issue or create a new one if you have questions, bugs, or suggestions. For larger PRs, open an issue first if you could - drive-by PRs are also welcomed.

Please abide by the Code of Conduct. For more on contributing to OrbitDB, check out the docs in orbitdb/welcome.

License

MIT © 2016-2018 Protocol Labs Inc., Haja Networks Oy