Created
November 1, 2012 18:37
-
-
Save chesles/3995631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pouch = require('pouchdb'); | |
var pouches = { | |
http1: 'http://localhost:5984/http1', | |
http2: 'http://localhost:5984/http2', | |
ldb1: 'ldb://testdb1', | |
ldb2: 'ldb://testdb2', | |
} | |
Object.keys(pouches).forEach(function(key) { | |
var url = pouches[key]; | |
pouch.destroy(url, function(err) { | |
if (err) { | |
console.log(url, err); | |
} | |
pouches[key] = pouch(url, inittest); | |
}); | |
}); | |
var count = 0; | |
function inittest(err, db) { | |
if (err) { | |
return console.log(err); | |
} | |
if (++count === Object.keys(pouches).length) { | |
start(); | |
} | |
} | |
function start() { | |
console.log('===== starting test ====='); | |
// switch out drivers here | |
var pouch1 = pouches.http1 | |
var pouch2 = pouches.ldb1 | |
pouch2.put({_id: 'test1', hello:'pouch'}, function(err, result1) { | |
console.log('--- PUT1', err, result1); | |
pouch2.replicate.to(pouch1, function(err, result2) { | |
console.log('--- replication to http complete', result2); | |
pouch1.put({_id: result1.id, _rev: result1.rev, hello: 'couch'}, function(err, result3) { | |
console.log('--- [http] PUT2:', err, result3); | |
pouch2.put({_id: result1.id, _rev: result1.rev, hello: 'world'}, function(err, result4) { | |
console.log('--- [ldb] PUT2:', err, result4); | |
pouch2.replicate.to(pouch1, function(err, result5) { | |
console.log('--- replication 2 to http complete:', err, result5); | |
console.log('-----------------------------------'); | |
function log(err, result) { | |
console.log('>>> LOG:', err, result); | |
} | |
pouch1.get(result1.id, log); | |
pouch2.get(result1.id, log); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment