Created
January 6, 2011 13:41
-
-
Save pgte/767890 to your computer and use it in GitHub Desktop.
alfred_example.js
This file contains 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 USERS = { | |
1: {name: 'Pedro', age: 35, sex: 'm'} | |
, 2: {name: 'John', age: 32, sex: 'm'} | |
, 3: {name: 'Bruno', age: 28, sex: 'm'} | |
, 4: {name: 'Sandra', age: 35, sex: 'f'} | |
, 5: {name: 'Patricia', age: 42, sex: 'f'} | |
, 6: {name: 'Joana', age: 29, sex: 'f'} | |
, 7: {name: 'Susana', age: 30, sex: 'f'} | |
}; | |
var alfred = require('alfred'); | |
alfred.open('/tmp/dbtest', function(err, db) { | |
if (err) { throw err; } | |
db.ensureKeyMapAttached('users', function(err, users_key_map) { | |
console.log('users key map attached'); | |
var put_count = 0; | |
for (id in USERS) { | |
if (USERS.hasOwnProperty(id)) { | |
db.users.put(id, USERS[id], function(err) { | |
if (err) { throw err; } | |
console.log('user with id ' + id + ' inserted.'); | |
put_count ++; | |
if (put_count == 7) { | |
console.log('going to end...'); | |
db.close(function(err) { | |
if (err) { throw err; } | |
console.log('ended.'); | |
}); | |
} | |
}); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment