37
CHAPTER 3. HTML5
27
within the browser. This would give applications the ability to save in-
formation within the browser, so that they may access information even
when oine. The WebSQL API was introduced so that information could
be recorded and retrieved based on well established Structured Query Lan-
guage (SQL) statements, however towardsthe end of the2010 theW3C group
decided that introducing SQL statements within JavaScript, was not a very
compatible design and dropped it. This was then replaced by the IndexedDB
API, which has a more JavaScript related API which deals with with data in
the form ofthe JavaScriptObject Notation (JSON). The HTML5IndexedDB
API allows applications to have a persistent storage of information locally
within the browser. The availability of this stored oine information is the
same as the File API discussed previously, where the information is saved
separately for dierent domains and browsers.
The indexed database consists of object stores, these are the data structures
that contain all the data. In relational databases these are known as tables.
The indexed database consists of three types of transaction modes which
allow access and modication to the object stores, they are ’readonly’, ’read-
write’ and ’versionchange’ transactions. The ’readonly’ transactions where
data is not modied, can have many instances running in parallel, as these
instances would not have any impact on each other. The ’readwrite’ trans-
action on the other hand can only have one instance accessing a given object
store running at a time, in order to ensure that transactions are mutually
exclusive. It is also important to note that the object store schema cannot be
modied in this transaction mode. Finally the ’versionchange’ transaction
mode is the only one in which the object store schema can be modied.
The IndexedDB API brings in a unique problemas to how thebrowser should
handle the data when the object store schema has been updated. We should
remember that when a new version has been deployed, all previous versions
would be available with the user base, so if the designed application cannot
aord to lose previously stored data, it would have to write code that han-
dles the smooth transition of data from all the previous versions to the new
object store schema. This is a problem that is specic to having a database
on the client side, as server side databases would only have to be migrated
from one schema version to another and would be re
ected globally. This is
also where the ’versionchange’ transaction mode becomes important.