Skip to content

Instantly share code, notes, and snippets.

@brycebaril
Created June 30, 2013 00:24
Show Gist options
  • Save brycebaril/5893248 to your computer and use it in GitHub Desktop.
Save brycebaril/5893248 to your computer and use it in GitHub Desktop.
var lvlup = require("levelup")
var db = lvlup("/tmp/source_db")
var batch = 10000
function makeBatch(num) {
var b = []
for (var i = num; i < num + batch; i++) {
b.push({type: "put", key: "z~" + i, value: Math.random()})
}
return b
}
function populate(start) {
db.batch(makeBatch(start), function (err) {
if (err) throw err
start += batch
if (start < 1000000) {
console.log(start)
populate(start)
}
})
}
populate(0)
var lvlup = require("levelup")
var src = lvlup("/tmp/source_db")
var tgt = lvlup("/tmp/target_db")
var start = Date.now()
src.createReadStream()
.pipe(tgt.createWriteStream()
.on("close", function () {
console.log("Done, in %s", Date.now() - start)
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment