A CouchDB implementation on top of levelup.
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.
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.
var couchup = require'couchup'store = couchup'./dbdir';dbput'databaseName'if e throw edbput_id:'key' prop:'value'if e throw edbput_id:'key' _rev:inforev prop:'newvalue'if e throw edbget'key'if e throw 'doc not found'console.logdoc
dbcompact // remove old revisions and sequences from the database.
db.infoif e throw econsole.logiupdate_seq idoc_count
var changes = dbsleepchangeson'entry'console.logentryseq entryidchangeson'end'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 = sleeprefdbsleepbinddb;httpcreateServershttpHandlerbindslisten8080db2pull''if e throw e// all replicated over the network
You can also replicate between database objects in process.
dbclonedb2if e throw e// all replicated
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.