Moving from the Couch to the LawnChair
Author: Dion Almaer
24
Nov
We have mentioned attempts at doing Couch in the browser before, and now we have a new project.
Brian LeRoux of PhoneGap/Nitobi fame, has taken a lighter couch outside as he announces Lawnchair that aims at being applicable for mobile Web usage (but can of course work anywhere else):
Features
- micro tiny storage without the nasty SQL: pure and delicious JSON
- clean and simple oo design with one db table per store
- key/value store.. specifying a key is optional
- happily and handily will treat your store as an array of objects
- terse syntax for searching and therefore finding of objects
Give it a hack:
JAVASCRIPT:
-
-
// create a store
-
var people = new Lawnchair('people');
-
-
// -- adding to the store
-
// 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'});
-
-
// -- Getting content out
-
-
// 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)');
-
-
// -- Removal
-
-
// 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();
-
Related News :