You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IndexedDB is a database inside a browser to save and retrieve objects on the browser/client. The JQuery IndexedDB Plugin is a wrapper on the IndexedDB API for JQuery.
5
+
6
+
Links
7
+
------
7
8
8
-
Background
9
-
-----------
10
-
The IndexedDB API is in its draft state but is already available in Firefox 4 and Chrome 12 Canary Builds. Internet Explorer also has a version of it on their HTML5 prototypes site. In my previous posts, I have also written about IndexedDB API examples using TrialTool.
9
+
* Home page - http://nparashuram.com/jquery-indexeddb/index.html
10
+
* Download the plugin - http://nparashuram.com/jquery-indexeddb/jquery.indexeddb.js
* API Documentation - https://github.com/axemclion/jquery-indexeddb/blob/gh-pages/docs/README.md
11
13
12
-
Problem
13
-
--------
14
-
I wrote a couple of "non-production" applications and noticed that I was frequently copying non-application-logic, IndexedDB-related code across applications. Should that code be a part of a library? In my opinion, the amount of boiler plate code written to perform simple tasks like persisting or fetching data is not little.
14
+
Summary
15
+
-------
16
+
The Jquery IndexedDB Plugin brings to goodness of Jquery to the browser's native IndexedDB API. It supports method chaining, promises and smart defaults, enabling you to get more done with less code. It also abstracts out differences in browser implementations.
15
17
16
18
Code
17
19
----
@@ -34,25 +36,4 @@ A typical operation using the IndexedDB API would involve using the request mode
34
36
35
37
The above code would increase if objects have to be created with version transaction, and error conditions are to be added.
36
38
37
-
Solution
38
-
--------
39
-
The IndexedDB Jquery plugin is an attempt to reduce this boiler plate code in addition to bring back concepts like method chaining and Deferred calls.
40
-
41
-
The philosophy followed in the library is the same as the `$.ajax()` call that is more than just a wrapper over the XMLHTTPRequest object.
42
-
Some Jquery goodness that I wanted while I designed the API include
43
-
44
-
1. Method chaining, access to most probable next operation in a chain. For example, once an objectStore is referenced, the next operations usually are CRUD, cursors or indexes. These operations should be available in the chain.
45
-
2. APIs for most common functions. For example, most people would not want to care about transactions. They would simply like transactions to be implicit and hence, the API opens a READ_WRITE transaction. Alternatively, the user can also explicitly open transactions and use them.
46
-
3. Since the IndexedDB API is an asynchronous API, use of `Deferreds()` for completion. This model is much more familiar than the request and request.result model exposed in IndexedDB API.
47
-
4. Default error handling, taking advantage of error event propagation in IndexedDB. Error cases are not common and should not be required at every step. The promises in `Deferreds()` are easier to handle errors.
48
-
5. Falling back on smart defaults. For example, when a user accesses an object store and it does no exist, they would probably want to create on a version change transaction. This is done in the object store call by default. However, the user can explicitly specify that the call should fail if the objectStore does not exist.
49
-
50
-
The equivalent code for the snippet above looks something like this
The library is currently hosted here on GitHub and the examples illustrating the API are available at http://nparashuram.com/trialtool/index.html#example=/IndexedDB/jquery/trialtool.html.
57
-
58
-
Watch out this space for more updates on my experiments with IndexedDB.
0 commit comments