Skip to content

Instantly share code, notes, and snippets.

@kylegetson
Created May 17, 2013 15:13
Show Gist options
  • Save kylegetson/5599722 to your computer and use it in GitHub Desktop.
Save kylegetson/5599722 to your computer and use it in GitHub Desktop.
get or set example
var levelup = require('levelup');
var db = levelup('./mydb', {cacheSize: 0});
function getOrSet(num){
if( num == 0 ) return;
var hash = num.toString();
db.get(hash, function(err,result){
if( err ){
db.put(hash, num, function(){
return getOrSet(--num);
});
return;
}
return getOrSet(--num);
});
}
getOrSet(500000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment