yathit / ydn-db

Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction.
Apache License 2.0
503 stars 41 forks source link

Cordova sqlite plugin openDB changes #101

Open lwbdev opened 8 years ago

lwbdev commented 8 years ago

Hi, it looks like the author of the cordova sqlite plugin (@brodybits) changed the arguments/parameters for the opendatabase call for the sqlite plugin. This means using sqlite as a mechanism no longer works with the latest version of the plugin since ydn-db uses the old openDatabase calls.

See https://github.com/litehelpers/Cordova-sqlite-storage.

yathit commented 8 years ago

Could you use this plugin?

yathit commented 8 years ago

This is a breaking change request. My first reaction is NO. There are other plugin as well. Breaking from WebSQL API is not going to happen. In this case, simply use an adaptor function to use the two library togather.

lwbdev commented 8 years ago

Hi,

Thanks for your quick response. Unfortunately, I cannot use the the enterprise version you linked to as it does not support Windows 10/UAP. I'm actually using this version here https://github.com/litehelpers/cordova-sqlite-ext which does support Windows 10/UAP and has the same issue with the openDatabase call change.

Aside from the openDatabase call, the plugin still adheres to the WebSQL API. I suppose I can create a wrapper function that overwrite the window.sqlitePlugin.openDatabase function, but I thought it would be easier if ydn-db could also use the modified openDatabase call just for the sqlite mechanism with a way to pass in the open arguments to the sqlite plugin (i.e. Database location). I also tried to overwrite window.openDatabase to use that to call window.sqlite.openDatabase (and using "websql" instead of "sqlite" as the mechanism), but was ultimately unsuccessful because the sqlite plugin does not implement version change API for WebSQL.

lwbdev commented 8 years ago

As you suggested I was able to write an adaptor function. For anyone else in my shoes, here's the code:

if (window.sqlitePlugin) {
    window.sqlitePlugin.__openDatabase = window.sqlitePlugin.openDatabase;
    window.sqlitePlugin.openDatabase = function(arg) {
        if (typeof(arg) == "object") {
            return window.sqlitePlugin.__openDatabase(arg);
        } else {
            return window.sqlitePlugin.__openDatabase({
                name: arg,
                iosDatabaseLocation: "Documents"
            });
        }
    }
}

Thanks again for all the hard work with ydn-db and your helpful suggestions!

yathit commented 8 years ago

@lwbdev 👍 thanks.