I need a client side browser database. What are my options [closed]

Solution 1:

Indexed Database (Can I use)
Web SQL (Can I use)
localStorage

Solution 2:

I'm about 5 years late in answering this, but given that there are errors and outdated data in some of the existing answers, and unaddressed points in the original question, I figured i'd throw in my two cents.

First, contrary to what others have implied on here, localStorage is not a database. It is (or should be perceived as) a persistent, string-based key-value store...

...which may be perfectly fine for your needs (and brings me to my second point).

  • Do you need explicit or implicitly relationships between your data items?
  • How about the ability to query over said items?
  • Or more than 5 MB in space?

If you answered "no" to all all of the above, go with localStorage and save yourself from the headaches that are the WebSQL and IndexedDB APIs. Well, maybe just the latter headache, since the former has been deprecated.

There are also several other client-side storage facilities (native and non-native) you may want to look in to, some of which are deprecated* but still see support from some browsers:

  • userData*
  • The rest of webStorage (sessionStorage and globalStorage*)
  • HTML5 File System*
  • Flash Locally Shared Objects
  • Silverlight Isolated Storage

Check out BakedGoods if you want to utilize any of these facilities, and more, without having to write low-level storage operation code. With it, placing data in one (or more) of them, for example, is as simple as:

bakedGoods.set({
    data: [{key: "key1", value: "val1"}, {key: "key2", value: "val2"}],
    storageTypes: ["silverlight", "fileSystem", "localStorage"],
    options: optionsObj,
    complete: function(byStorageTypeStoredKeysObj, byStorageTypeErrorObj){}
});

Oh, and for the sake of complete transparency, BakedGoods is maintained by this guy right here :) .

Solution 3:

Use PouchDB.

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

It helps building applications that works online as well as offline.

Basically, it stores the last fetched data in the in-browser database (uses IndexedDB, WebSQL under the hood) and then syncs again when the network gets active.

Solution 4:

I came across a JavaScript Database http://www.taffydb.com/ still trying it out myself, hope this helps.

Solution 5:

If you are looking for a NoSQL-style db on the client you can check out http://www.forerunnerdb.com. It supports the same query language as MongoDB and has a data-binding module if you want your DOM to reflect changes to your data automatically.

It is also open source, is constantly being updated with new features and the community around it is growing rapidly.

Disclaimer, I'm the lead developer of the project.