Sunday, November 25, 2007

HTML5 SQL Player using Gears

Dimitri Glazkov is a developer from Birmingham who has been following Gears and HTML5 development. He wrote a wrapper around Gears that adapts the Gears SQL interface to the HTML5 Database specification and a test page to drive it:

HTML5 SQL Player

Notably, this wrapper is very faithful to the spec. Everything is asynchronous where it is supposed to be -- even opening a transaction is non-blocking, just as it is in the spec.

This is done by implementing a client-server protocol between a Gears WorkerPool (the server) and the wrapper API (the client). Each SQL statement the client needs to execute is proxied to the server using SendMessage() and the client waits for an asynchronous callback containing the result. A typical SQL transaction will contain many statements and these all must be routed to the same Gears Database object on the server.

For an interesting read, check out the source. It is a really good example of mapping an single-threaded asynchrous API to a synchronous multi-threaded one.

It's nice to see this work being done. It shows that as long as the basic web development model of JavaScript/CSS/DOM is preserved, developers can deal with pretty dramatic API differences.

No comments: