Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created November 22, 2009 06:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianleroux/240460 to your computer and use it in GitHub Desktop.
Save brianleroux/240460 to your computer and use it in GitHub Desktop.
Lawnchair example usage
// Get that document
people.get(me.key, function(r){
console.log(r);
});
// Returns all documents as an array to a callback
people.all(function(r){
console.log(r);
});
// List all with shortcut syntax
people.all('console.log(r)');
var people = new Lawnchair('people');
// Classic iteration
people.each(function(r){
console.log(r);
});
// Classic with terse shorthand syntax
people.each('console.log(r)');
// Iterate documents conditionally!
// The first function is a conditional. The second is a callback to execute on records returned by the first
people.find(
function(r) {
return r.name == brian;
},
function(r) {
console.log(r);
}
);
// Iterate conditionally via shorthand
people.find('r.name == "brian"', 'console.log(r)');
// You can mix and match shorthand btw
people.find('r.name == "brian"', function(r){
console.log(r)
});
// Remove a document directly
people.get(me.key, function(r){
people.remove(me);
});
// Remove a document by key
people.save({key:'die', name:'duder'});
people.remove('die');
// Destroy all documents
people.nuke();
// Saving a document
var me = {name:'brian'};
people.save(me);
// Saving a document async
people.save({name:'frank'}, function(r) {
console.log(r);
});
// Specifying your own key
people.save({key:'whatever', name:'dracula'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment