Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use on browser along with other Cordova platforms #4

Open
brodycj opened this issue Apr 17, 2018 · 0 comments
Open

How to use on browser along with other Cordova platforms #4

brodycj opened this issue Apr 17, 2018 · 0 comments
Assignees

Comments

@brodycj
Copy link
Owner

brodycj commented Apr 17, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant