Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Forked from brianleroux/get.js
Created May 11, 2010 20:01
Show Gist options
  • Save philippbosch/397776 to your computer and use it in GitHub Desktop.
Save philippbosch/397776 to your computer and use it in GitHub Desktop.
// 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(r);
});
// 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