W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

Re: HTML 5 Database Storage Does Not Enable Chaining Transactions

From: Ian Hickson <ian@hixie.ch>
Date: Wed, 3 Jun 2009 07:27:36 +0000 (UTC)
To: Doug Reeder <dreeder5@columbus.rr.com>
Cc: public-webapps@w3.org
Message-ID: <Pine.LNX.4.62.0906030724240.1648@hixie.dreamhostps.com>
On Sat, 4 Apr 2009, Doug Reeder wrote:
> The scenario where I need to use HTML 5 Database storage requires 
> storing a tree of data.  Each item has a unique id, generated by the 
> database.  Child nodes have a "parentId" field which points to their 
> parent ID.  Creating the records for a new tree in the database requires 
> multiple transactions. First, the root item must be created.  When the 
> callback returns, the children of the root item can be created, because 
> the id of the root item is now known.  For each child, when the 
> appropriate callback returns, the children of the child can be created, 
> because their parent IDs are now known, and so forth.
> Minimizing the number of transactions (and thus the overall time to 
> create a database) requires there be multiple transactions outstanding 
> at any given time.  Thus, when a callback function is called, it needs 
> to determine _which_ transaction has completed.  The current version of 
> the HTML 5 Database storage spec does not make this easy. It is 
> straightforward for my app to generate a unique ID for each transaction, 
> but the spec provides no way to pass this to the callbacks.  In 
> JavaScript, I can add an "id" field to the transaction object, but then 
> the _same_ id gets passed to each statement callback, and the 
> transaction object is not passed _at all_ to the transaction success 
> callback.
> I'm sure there are other scenarios where it would be useful for a 
> statement callback to know which statement has completed, and for a 
> transaction callback to know which transaction has just completed.

Don't closures do what you want? Instead of always using the same function 
as the callback, create a new function each time, with that function 
having the identifier in question, as in:

   function getCallback(id) {
     return function (transaction) {
       // ... the callback ...

   //... n is some identifier

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 3 June 2009 07:28:11 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:12:53 UTC