Activate your free membership today | Log-in

Tuesday, November 24th, 2009

Moving from the Couch to the LawnChair

Category: Database, JavaScript

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:
  1.  
  2. // create a store
  3. var people = new Lawnchair('people');
  4.  
  5. // -- adding to the store
  6. // Saving a document
  7. var me = {name:'brian'};
  8. people.save(me);
  9.  
  10. // Saving a document async
  11. people.save({name:'frank'}, function(r) {
  12.     console.log(r);
  13. });
  14.  
  15. // Specifying your own key
  16. people.save({key:'whatever', name:'dracula'});
  17.  
  18. // -- Getting content out
  19.  
  20. // Get that document
  21. people.get(me.key, function(r){
  22.     console.log(r);
  23. });
  24.  
  25. // Returns all documents as an array to a callback
  26. people.all(function(r){
  27.     console.log(r);
  28. });
  29.  
  30. // List all with shortcut syntax
  31. people.all('console.log(r)');
  32.  
  33. // -- Removal
  34.  
  35. // Remove a document directly
  36. people.get(me.key, function(r){
  37.     people.remove(me);
  38. });
  39.  
  40. // Remove a document by key
  41. people.save({key:'die', name:'duder'});
  42. people.remove('die');
  43.  
  44. // Destroy all documents
  45. people.nuke();
  46.  

Posted by Dion Almaer at 6:20 am
9 Comments

+++--
3.3 rating from 8 votes

9 Comments »

Comments feed TrackBack URI

looks interesting, however, i’m not sure how i feel about “people.nuke();” haha

Comment by jaimz — November 24, 2009

Why do i want to use this over localStorage?

localStorage.setItem("name", "Brian");
var name = localStorage.getItem("name");

localStorage.setItem("data", {"foo":"bar","flip":"rep","arr":[1,3,4]});
var data = localStorage.getItem("data");

Comment by Jaaap — November 24, 2009

@Jaaap — many stores and searching. A slightly better api. The future ability to back the store by other technology (such as local,global,session storage) to make it more portable is planned.

Comment by brianleroux — November 24, 2009

Always loved anything to do with CouchDB — @Brianleroux, ever done any work with IBM’s Domino Framework?

Comment by mdmadph — November 24, 2009

@brianleroux – I’m with jaaap on this; show me the chocolate chips and I’ll choose your cookies, or I’m going to pick vanilla.

Comment by sixtyseconds — November 24, 2009

@mdmadph: no but I’m a big fan of document stores.

@sixtyseconds: About to release android 1.5,1.6 and 2.0 support so there’s your cookies buddy.

Early versions of Android only support the gears sqlite interface (different than the webkit sqlite api) and no localStorage. Consistant API and mobile web friendly is the goal.

Comment by brianleroux — November 26, 2009

also have a look at Syncopate, another Web Database/HTML5 wrapper:

http://github.com/thynctank/Syncopate

Comment by thynctank — November 26, 2009

and the buy aion gold security aion power levelingofjustice. roll forming machinewe have buy wow goldalso come to this hallowed spot
shanghai escortto remindamerica cheap wow goldof the fierce urgency of now. this is no time to engagein the luxury of cooling off or

Comment by qqlovee — December 7, 2009

Lawnchair has create 3 databases in Safari with the same name. How do I delete ( remove, drop, etc ) the databases create with this?

Comment by xfactor69 — February 6, 2010

Leave a comment

You must be logged in to post a comment.