blob: 75bff4e5218fc2321bd5c5d6e3775d9c16e37045 [file] [log] [blame]
import WebSqlPouchCore from 'pouchdb-adapter-websql-core';
import jsExtend from 'js-extend'; var extend = jsExtend.extend;
function websql(optsOrName, version, description, size) {
if (typeof sqlitePlugin !== 'undefined') {
// The SQLite Plugin started deviating pretty heavily from the
// standard openDatabase() function, as they started adding more features.
// It's better to just use their "new" format and pass in a big ol'
// options object.
return sqlitePlugin.openDatabase(optsOrName);
}
// Traditional WebSQL API
return openDatabase(optsOrName, version, description, size);
}
function WebSQLPouch(opts, callback) {
var _opts = extend({
websql: websql
}, opts);
WebSqlPouchCore.call(this, _opts, callback);
}
WebSQLPouch.valid = function () {
// SQLitePlugin leaks this global object, which we can use
// to detect if it's installed or not. The benefit is that it's
// declared immediately, before the 'deviceready' event has fired.
return typeof openDatabase !== 'undefined' ||
typeof SQLitePlugin !== 'undefined';
};
WebSQLPouch.use_prefix = true;
export default function (PouchDB) {
PouchDB.adapter('websql', WebSQLPouch, true);
}