-
-
Save philippbosch/397776 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
// 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)'); |
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 people = new Lawnchair('people'); |
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
// 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) | |
}); |
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
// 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(); |
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
// 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