Created
July 19, 2010 15:19
-
-
Save aezell/481537 to your computer and use it in GitHub Desktop.
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
// init the storage object | |
var people = new Lawnchair('people'); | |
// save an object | |
var me = {name: 'alex'}; | |
people.save(me); | |
// what is the people object? | |
console.log(people) | |
// save asynchronously | |
people.save({name:'kevin'}, function(r) { | |
console.log(r); | |
}); | |
// define your own key | |
var me_key = {key:'name', value: 'matt'}; | |
people.save(me_key); | |
// get a value by key | |
people.get('name', function(r) { | |
console.log(r); | |
}); | |
// get all objects | |
people.all(function(r) { | |
console.log(r); | |
}); | |
// shorthand is available | |
people.all('console.log(r)'); | |
// iterate over each value | |
people.each(function(r) { | |
$('#people').append('<li>' + r.name +'</li>'); | |
}); | |
// remove by key or object | |
people.remove('name'); | |
people.all('console.log(r)'); | |
// iterate conditionally via shorthand | |
people.find('r.name == "alex"', 'console.log(r)'); | |
// store a bunch of stuff | |
var lots = new Lawnchair('lots'); | |
for (var i = 0; i < 300; i++) { | |
lots.save({key: i, value: "dollar" + i}); | |
} | |
lots.all(function (r) { | |
console.log(r.length); | |
}); | |
lots.paged(1, function(r){ | |
console.log('first 10 records: ' + r); | |
}); | |
people.nuke(); | |
lots.nuke(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment