Proposal: Worker Threads and Synchronous DB API

Hello Group,

threads in JavaScript are a necessity for "real" apps, so having the
Worker Thread spec'd is good. 

It also means that now we should have also a synchronous DB API (like
the one Gears has), since combined with Worker Threads they make the
programming model simpler and less error-prone (e.g., exception catching
can be used for larger execution stacks) compared to the current
asynchronous-only DB API of HTML5.

For a related discussion, please see e.g., 

http://lists.w3.org/Archives/Public/public-html/2007Oct/0294.html
"Indeed, when we introduce worker pool APIs I think we'll have to
introduce a synchronous version of this API." -IH

And
http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-August/012318.h
tml


My strawman proposal for synchronous DB API (Modeled after Gears and
Current HTML5 DB API) would be along these lines:

interface Database {
  void transaction(in SQLTransactionCallback callback);
  void transaction(in SQLTransactionCallback callback, in
SQLTransactionErrorCallback errorCallback);
  void transaction(in SQLTransactionCallback callback, in
SQLTransactionErrorCallback errorCallback, in VoidCallback
successCallback);

  readonly attribute DOMString version;
  void changeVersion(in DOMString oldVersion, in DOMString newVersion,
in SQLTransactionCallback callback, in SQLTransactionErrorCallback
errorCallback, in VoidCallback successCallback);

  /* BEGIN ADDED */
  SQLTransactionSync transactionSync();  // only one transaction per
thread - otherwise throw exception

  // throw exception if preflight condition does not match. 
  // Returned object does postflight operation when commit() is called.
  SQLTransactionSync changeVersionSync(in DOMString oldVersion, in
DOMString newVersion); 
  /* END ADDED */
};

/* BEGIN ADDED */
interface SQLTransactionSync { 
  SQLResultSet executeSql(in DOMString sqlStatement);
  SQLResultSet executeSql(in DOMString sqlStatement, in ObjectArray
arguments);
  void commit();
  void rollback();
};

exception SQLException { 
    readonly attribute unsigned int code;
    readonly attribute DOMString message;
};
/* END ADDED */

Comments?

Regards, 
  Mikko Honkala

Received on Wednesday, 23 July 2008 11:07:48 UTC