Tuesday, November 24th, 2009

Moving from the Couch to the LawnChair

Category: Database, JavaScript

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

Related Content:

8 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

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.