Game Development Reference
In-Depth Information
IndexedDB
As exciting as the web storage API might seem so far, there are cases when our
needs might be such that serializing and unserializing data, as we use local or ses-
sion storage, might not be quite sufficient. For example, imagine we have a few hun-
dred (or perhaps, several thousand) similar records stored in local storage (say we're
storing enemy description cards that are part of an RPG game). Think about how you
would do the following using local storage:
• Retrieve, in alphabetical order, the first five records stored
• Delete all records stored that contain a particular characteristic (such as
an enemy that doesn't survive in water, for example)
• Retrieve up to three records stored that contain a particular characteristic
(for example, the enemy has a Hit Point score of 42,000 or more)
The point is this: any querying that we may want to make against the data stored in
local storage or session storage, must be handled by our own code. In other words,
we'd be spending a lot of time and effort writing code just to help us get to some data.
Let alone the fact that any complex data stored in local or session storage is conver-
ted to literal objects, and any and all functions that were once part of those objects
are now gone, unless we write even more code to handle some sort of custom unseri-
alizing.
In case you have not guessed it by now, IndexedDB solves these and other problems
very beautifully. At its heart, IndexedDB is a NoSQL database engine that allows us to
store whole objects and index them for fast insertions, deletions, and retrievals. The
database system also provides us with a powerful querying engine, so that we can
perform very advanced computations on the data that we have persisted.
The following figure shows some of the similarities between IndexedDB and a tradi-
tional relational database. In relational databases, data is stored as a group of rows
within a specific table structure. In IndexedDB, on the other hand, data is grouped in
broadly-defined buckets known as data stores.
Search WWH ::




Custom Search