flying227
flying227

Reputation: 1321

Which Browser SQL Database to use?

Alright, so I need to implement a fairly large local database for the iOS and Android mobile browsers (~30 MB). I am researching the options and it looks like WebSQL (the option I wanted to use) is being actively abandoned. Also, it looks like IndexedSQL is not fully supported.

What do you recommend for a local browser database? Thanks!

Upvotes: 0

Views: 156

Answers (3)

Kevin
Kevin

Reputation: 2697

I'm replying to this in 2016 (2 years after you asked this question) and everything concerning the deprecation of WebSQL still stands. IndexedDB on the other hand, enjoys the support of all of the major browser vendors.

Now would be a good time to state that "IndexedSQL" is neither an alternative name for IndexedDB, nor a name of any other existing client-side database :) . Pointing this out may seem a bit pedantic, but it's not: IndexedDB is a non-relational document-store, and as such does not natively support SQL.

Regardless of what you call it, IndexedDB is currently the only database on the W3C standards track, and as such is the only future-proof option for anyone tasked with choosing a client-side database.

As implied by GemK, however, such a decision isn't one that necessarily has to be made; one can simply choose (or make) a library which utilizes whichever database is available on a client machine.

BakedGoods differs from such libraries already suggested here in several ways; most pertinently, it allows the storage type(s) that are to be utilized to be explicitly specified, in turn allowing the developer to introduce other factors (such as performance characteristics) in to the decision-making process.

With it, conducting storage operations in whichever of the database types is supported is a matter of...

... specifying the appropriate operation options and equivalent configs for both database types:

//If the operation is a set(), and the referenced structures 
//don't exist, they will be created automatically.

var webSQLOptionsObj = {
    databaseName: "Example_DB",
    databaseDisplayName: "Example DB",
    databaseVersion: "",
    estimatedDatabaseSize: 1024 * 1024,
    tableData: {
        name: "Main",
        keyColumnName: "lastName",
        columnDefinitions: "(lastName TEXT PRIMARY KEY, firstName TEXT)"
    }, 
    tableIndexDataArray: [name: "First_Name_Index", columnNames: "(firstName)"]
};

var indexedDBOptionsObj = {
    databaseName: "Example_DB",
    databaseVersion: 1,
    objectStoreData: {
        name: "Main",
        keyPath: lastName,
        autoIncrement: false
    },
    objectStoreIndexDataArray: [
        {name: "First_Name_Index", keyPath: "firstName", unique: false, multiEntry: false}
    ],
};

var optionsObj = {
    conductDisjointly: false, 
    webSQL: webSQLOptionsObj, 
    indexedDB: indexedDBOptionsObj
};

... and conducting the operation:

bakedGoods.set({
    data: [
        {value: {lastName: "Obama", firstName: "Barack"}}, 
        {value: {lastName: "Biden", firstName: "Joe"}}
    ],
    storageTypes: ["indexedDB", "webSQL"],
    options: optionsObj,
    complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj){}
});

Its simple interface and unmatched storage facility support comes at the cost of lack of support for some storage facility-specific configurations. For instance, it does not support the conduction of storage operations in WebSQL tables with multi-column primary keys.

So if you make heavy use of those types of features, you may want to look elsewhere.

Oh, and for the sake of complete transparency, BakedGoods is maintained by yours truly :) .

Upvotes: 0

GemK
GemK

Reputation: 862

IndexedDB with use of IndexedDBShim (a polyfill for WebSQL), for sure looks fulfills your requirement. But do notice, that IOS devices allows maximum of 50 MB storage.

I have worked on the similar requirement as of yours and this combination worked across all modern browsers.

Upvotes: 2

Kristof Degrave
Kristof Degrave

Reputation: 4180

I don't think you have an other choice than using the indexeddb. WebSQL is deprecated and localstorage is to small and not performante to serve the needs.

I wrote a library that implements a linq like interface. By using methods you can easily query the database. Example:

linq2indexeddb.from("store").where("field").equals("value").select()

Because the indexededdb is async you will get back a promise.

You can find my library at codeplex

Upvotes: 1

Related Questions