Last April, Atul Varma of Mozilla posted an article on an implementation of a local storage wrapper that mimicked CouchDB's map-reduce query interface.

In the comments, my friend Mikeal posted If you could add replication this would give the current Weave stuff a run for it's money

I thought about it and this seemed like a perfect solution to what I see as one of the most important areas in the development of the web platform. Ever since Mikeal got me interested in CouchDB, I've followed its development, and been excited at how native to the web it feels. Using nothing but a REST interface, and javascript for queries, it is marvellously fast and simple.

A javascript library that wrapped both local storage and the REST interface to a CouchDB server could exploit couch's replication and versioning to provide a simple storage API whilst offline, and then transparently sync it to the server once connectivity resumed.

In a world where HTML5 is becoming the only open platform for mobile app development, and where locally stored and owned data is becoming rare, this concept was not only exciting from an engineering standpoint, but also tied in with my ideological views on open data.

For a year, the idea percolated through my head, but until about a month ago I hadn't done anything about it.

After leaving Slide last month, I had lot of free time to work on personal projects. I forked a repository on github and began almost immediately. Within a few days I had replication working.

I've been working on it off and on ever since. I'd love to hear your feedback — it's not in a stable state yet, although the unit tests run and replication to localhost works, but I'd love to get as much feedback on the API design as possible before I release a 0.1 version, as it'll be much harder to make such changes if people start to use it.

So what's on the todo-list?

Well, as was pointed out to me by the intimidatingly smart people at couchio, I'm doing replication all wrong - I need to store _seq numbers and a by sequence tree. That's the next major change I plan to make.

I also want to get Futon working on it, which will require a lot of work.

As always, feel free to fork it or comment on my commits.

(Unrelated, I'm supporting myself with contracting at the moment, so if you need some web development then please feel free to contact me)
Comment on this

This is not an open forum — abusive or worthless comments will be deleted

  1. Tys von Gaza

    This looks really great, looking forward to a semi-stable release!

    Keep it up.


  2. Sky

    Hi, I've been stepping through the code, trying to work out how it sticks together.

    I've come across a line that always fails if local storage is working, and I was wondering as to the reasoning for it. It fails on the second load of test.html

    690 of browser-couch.js
    if (newEdits && orig && orig._rev != obj._rev){ //throw error
    An error is thrown because obj._rev is undefined whereas orig._rev has the value from local storage.

    Can you remember what the reasoning for this line of code was? Should an extra condition for || obj._rev == undefined fix the problem without breaking whatever error this line is trying to catch?


  3. Sky

    Sorry, that should be adding && obj._rev != undefined resulting in

    if (newEdits && orig && orig._rev != obj._rev && obj._rev != undefined){


  4. Peter Braden

    Hi Sky,

    I don't remember writing that line of code, it's entirely possible that it's a bug. Patches welcome!

    Thanks,

    Peter


Newest Items

Photography

  • Introducing BrowserCouch
  • Introducing BrowserCouch

Recent Writing

Subscribe

Like what you see?

Subscribe to the RSS feed and be notified whenever there's something new…