How to use on browser along with other Cordova platforms
brodycj opened this issue · comments
@brodycj - C. Jonathan Brody commented
It is possible to use this component to support SQLite database access on browser along with other Cordova platforms.
const newPromiseHelper = require('sql-promise-helper').newPromiseHelper;
const db = (window.cordova.platformId === 'browser') ?
window.openDatabase('my.db', '1.0', 'Test', 2*1024*1024) :
window.sqlitePlugin.openDatabase({name: 'my.db', location: 'default'});
const helper = newPromiseHelper(db);
helper.executeStatement('SELECT UPPER(?) AS myResult', ['String test']).then(function(rs) {
console.log('GOT RESULT: ' + rs.rows.item(0).myResult);
});
(lower database size limit is needed to avoid a permission request popup on Safari browser)
This sample will use Web SQL on browser but not on any other platforms, avoiding a possible pitfall in case of missing sqlite plugin.
I will document this when I get a chance, hopefully someday soon.