GithubHelp home page GithubHelp logo

imclab / hyperlog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mafintosh/hyperlog

0.0 1.0 0.0 99 KB

Database that replicates based on scuttlebutt logs and causal linking

License: MIT License

JavaScript 100.00%

hyperlog's Introduction

hyperlog

Database that replicates based on scuttlebutt logs and causal linking

Currently a work in progress. See pfraze/phoenix#170 for more info

var hyperlog = require('hyperlog')

// currently you NEED to pass a globally unique id - this will change in the future
var log = hyperlog(db) // where db is a levelup instance

// add a node with value 'hello' and no links
log.add(null, 'hello', function(err, node) {
  console.log('inserted node', node)

  // insert 'world' with a link back to the above node
  log.add([node.key], 'world', function(err, node) {
    console.log('inserted new node', node)
  })
})

To replicate this log with another once simple pipe the replicate streams together. After the replication stream finished call resolve to apply the changes fetched to your log

var l1 = hyperlog(db1)
var l2 = hyperlog(db2)

var a = l1.replicate()
var b = l2.replicate()

a.pipe(b).pipe(a)

a.on('end', function() {
  a.resolve(function() {
    console.log('the changes received from b are now applied :)')
  })
})

A detailed write-up on how this replication protocol works will be added to this repo in the near future. For now I refer to the source code and the above link.

License

MIT

hyperlog's People

Contributors

ekg avatar mafintosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.