GithubHelp home page GithubHelp logo

couchup's Introduction

couchup

couchup is a database. The goal is to build a data model well suited for mobile applications that may need to work offline and sync later on and maintain smart client side caches. This data model is inspired by CouchDB but diverges greatly in the way it handles and resolves the revision history and conflicts. couchup implements a "most writes wins" conflict resolution scheme and does not require or even allow user specific conflict resolution.

Another goal of couchup is to be performant and modular. This repository only implements the base document storage layer. Indexes, attachments and replicators are implemented as additional modules.

The tradeoffs couchup has made in revision tree storage along with some other simple optimizations mean that couchup already has better write performance than CouchDB and the same consistency guarantees.

API

var couchup = require('couchup')
  , store = couchup('./dbdir')
  ;

db.put('databaseName', function (e, db) {
  if (e) throw e
  db.put({_id:'key', prop:'value'}, function (e, info) {
    if (e) throw e
    db.put({_id:'key', _rev:info.rev, prop:'newvalue'}, function (e, info) {
      if (e) throw e
      db.get('key', function (e, doc) {
        if (e) throw new Error('doc not found')
        console.log(doc)
      })
    })
  })
})
db.compact() // remove old revisions and sequences from the database.
db.info(function (e, i) {
  if (e) throw e
  console.log(i.update_seq, i.doc_count)
})

SLEEP Support

var changes = db.sleep()
changes.on('entry', function (entry) {
  console.log(entry.seq, entry.id)
})
changes.on('end' function () {
  console.log('done')
})

And can be used with sleep-ref for replicating over the network via tcp,tls,http and https.

var sleepref = require('sleep-ref')
  , s = sleepref(db.sleep.bind(db))
  ;
http.createServer(s.httpHandler.bind(s)).listen(8080, function () {
  db2.pull('http://localhost:8080/', function (e) {
    if (e) throw e
    // all replicated over the network
  })
})

You can also replicate between database objects in process.

db.clone(db2, function (e) {
  if (e) throw e
  // all replicated
})

Incompatibilities w/ CouchDB

Pull replication from CouchDB works and will continue to work continuously if you aren't updating the couchup node you're writing it to. Bi-Directional replication with CouchDB will eventually result in conflicts on the CouchDB side because couchup converts CouchDB's revision tree to a linear revision sequence.

Similarly, push replication to Apache CouchDB will work once but writing again will likely cause unnecessary conflicts on the CouchDB side.

couchup's People

Contributors

mikeal avatar

Watchers

 avatar  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.