博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OrbitDB-Peer 2 Peer Database using CRDTs
阅读量:7182 次
发布时间:2019-06-29

本文共 3814 字,大约阅读时间需要 12 分钟。

hot3.png

A peer-to-peer database for the decentralized web

OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses as its data storage and to automatically sync databases with peers. It's an eventually consistent database that uses for conflict-free database merges making OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and offline-first web applications.

Data in OrbitDB can be stored in a

  • (append-only log)
  • (same as log database but entries can be removed)
  • (store indexed JSON documents)

This is the Javascript implementation and it works both in Node.js and Browsers.

To get started, try the , read the or check , or !

Table of Contents

Usage

Read the guide for a more in-depth tutorial and to understand how OrbitDB works.

CLI

For the CLI tool to manage orbit-db database, see .

It can be installed from Npm with:

npm install orbit-db-cli -g

As a library

Install dependencies:

npm install orbit-db ipfs

Use it as a module:

const IPFS = require('ipfs')const OrbitDB = require('orbit-db')// OrbitDB uses Pubsub which is an experimental feature// and need to be turned on manually.// Note that these options need to be passed to IPFS in // all examples even if not specfied so.const ipfsOptions = {  EXPERIMENTAL: {    pubsub: true  },}// Create IPFS instanceconst ipfs = new IPFS(ipfsOptions)ipfs.on('error', (e) => console.error(e))ipfs.on('ready', async () => {  // Create a database  const orbitdb = new OrbitDB(ipfs)  const db = await orbitdb.log('database name')  // Add an entry to the database  const hash = await db.add('hello world')  // Get last 5 entries  const latest = db.iterator({ limit: 5 }).collect()  console.log(JSON.stringify(latest, null, 2))})

For more details, see examples for , , , and .

The minimum required version of Node.js is now 8.0.0. 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.

API

See for the full documentation.

Examples

Install dependencies

git clone https://github.com/orbitdb/orbit-db.gitcd orbit-dbnpm install

You'll also need babel and webpack, if you don't have them installed already:

npm install --global babel-clinpm install --global webpack

Browser example

npm run buildnpm run examples:browser

Check the code in and try the .

Node.js example

npm run examples:node

Eventlog

See the code in and run it with:

node examples/eventlog.js

More examples at .

Custom Store Types

You can add custom store types to OrbitDB:

// define custom store typeclass CustomStore extends DocumentStore {  constructor (ipfs, id, dbname, options) {    super(ipfs, id, dbname, options)    this._type = CustomStore.type  }  static get type () {    return 'custom'  }}// add custom type to orbitdbOrbitDB.addDatabaseType(CustomStore.type, CustomStore)// instantiate custom storelet orbitdb = new OrbitDB(ipfs, dbPath)let store = orbitdb.create(name, CustomStore.type)

Development

Run Tests

npm test

Build

npm run build

Benchmark

node benchmarks/benchmark-add.js

See for more benchmarks.

Logging

To enable OrbitDB's logging output, set a global ENV variable called LOG to debug,warn or error:

LOG=debug node 

Background

Uses the following modules:

To understand a little bit about the architecture, check out a visualization of the data flow at or a live demo: .

Contributing

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 on Freenode, or in the comments of the .

A good place to start are the issues labelled or the project's .

Sponsors

The development of OrbitDB has been sponsored by:

If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode.

转载于:https://my.oschina.net/u/2306127/blog/1613651

你可能感兴趣的文章
Codeforces 437C The Child and Toy(贪心)
查看>>
蓝桥杯 大臣的旅费
查看>>
hql中不能写count(1)能够写count(a.id)
查看>>
Atitit。Time base gc 垃圾 资源 收集的原理与设计
查看>>
还是态度问题
查看>>
判断记录是否存在的通用方法
查看>>
sift算法c语言实现
查看>>
报表中的Excel操作之Aspose.Cells(Excel模板)
查看>>
(二)STM32中中断优先级理解
查看>>
gulp教程之gulp-imagemin
查看>>
C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别
查看>>
【C语言入门教程】3.3 条件控制语句
查看>>
CLGeocoder Error Domain=kCLErrorDomain Code=2
查看>>
Spring中的@scope注解
查看>>
M2M
查看>>
Spring MVC的web.xml配置详解(转)
查看>>
iptables禁止外网访问redis server服务默认端口6379的命令
查看>>
硅谷新闻9--图片三级缓存
查看>>
洛谷P1220关路灯[区间DP 提前计算代价]
查看>>
登录验证过滤器
查看>>