brodybits / sql-promise-helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use on browser along with other Cordova platforms

brodybits opened this issue · comments

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.