GitXplorerGitXplorer
m

couchup

public
66 stars
4 forks
2 issues

Commits

List of commits on branch master.
Unverified
98c82e0e81211de44293d0d728b0c3afdba2bfe0

0.8.1

mmikeal committed 11 years ago
Unverified
34e75e6a2ef1b85cd2dac95d6e30d62b93f16246

0.8.0

mmikeal committed 11 years ago
Unverified
fe3087a23b80c5206c37792b154ca886e893f3a8

Fixing FOR REALZ THIS TIME

mmikeal committed 11 years ago
Unverified
2a4e4e2496a05f780e0b59554d8801e3eef6f310

0.7.1

mmikeal committed 11 years ago
Unverified
dbdc657e9df5c049a99015237fecad71b7a1cd8d

0.7.0

mmikeal committed 11 years ago
Unverified
d0d0338a8636bece4579181208305326614dda44

Fixing requirepath.

mmikeal committed 11 years ago

README

The README file for this repository.

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.