0.2.0-pre01 • Published 10 years ago

web-sql-batch-helper v0.2.0-pre01

Weekly downloads
3
License
ISC OR MIT OR Apa...
Repository
github
Last release
10 years ago

Web SQL batch helper

Specify Web or Cordova SQL batch in multiple steps. Useful with libraries like Oboe.js.

LICENSE: ISC, MIT, or Apache 2.0

Sample usage

Normal CommonJS

var newBatchHelper = require('web-sql-batch-helper').newBatchHelper;

var db = window.openDatabase('test.db', '1.0', 'Test', 5*1024*1024);

var helper = newBatchHelper(db);

var tx = helper.newBatchTransaction();
tx.executeStatement('DROP TABLE IF EXISTS tt');
tx.executeStatement('CREATE TABLE tt(a,b)');
tx.executeStatement('INSERT INTO tt VALUES(?,?)', [101, 'Alice']);
tx.commit().then(function() {
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM tt', null, function(ignored, rs) {
      alert('GOT RESULT LENGTH: ' + rs.rows.length + ' FIRST: ' + JSON.stringify(rs.rows.item(0)));
    });
  }, function(error) {
    alert('step 2 error: ' + error.message);
  });
});

or with sqlite plugin:

var newBatchHelper = require('web-sql-batch-helper').newBatchHelper;

var db = window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});

var helper = newBatchHelper(db);

var tx = helper.newBatchTransaction();
tx.executeStatement('DROP TABLE IF EXISTS tt');
tx.executeStatement('CREATE TABLE tt(a,b)');
tx.executeStatement('INSERT INTO tt VALUES(?,?)', [101, 'Alice']);
tx.commit().then(function() {
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM tt', null, function(ignored, rs) {
      alert('GOT RESULT LENGTH: ' + rs.rows.length + ' FIRST: ' + JSON.stringify(rs.rows.item(0)));
    });
  }, function(error) {
    alert('step 2 error: ' + error.message);
  });
});

ES6

import {newBatchHelper} from 'web-sql-batch-helper';

const db = window.openDatabase('test.db', '1.0', 'Test', 5*1024*1024);

const helper = newBatchHelper(db);

const tx = helper.newBatchTransaction();
tx.executeStatement('DROP TABLE IF EXISTS tt');
tx.executeStatement('CREATE TABLE tt(a,b)');
tx.executeStatement('INSERT INTO tt VALUES(?,?)', [101, 'Alice']);
tx.commit().then(() => {
  db.transaction((tx) => {
    tx.executeSql('SELECT * FROM tt', null, function(ignored, rs) {
      alert('GOT RESULT LENGTH: ' + rs.rows.length + ' FIRST: ' + JSON.stringify(rs.rows.item(0)));
    });
  }, (error) => {
    alert('step 2 error: ' + error.message);
  });
}, (error) => {
  alert('BATCH ERROR: ' + error.message);
});

Then assemble the bundle using a tool such as RollupJS or JSPM.

GENERAL NOTE: Use of const and let may not work with some older browsers and devices. Possible solutions include:

  • Just use var instead.
  • Use a tool like BabelJS (commonly used with JSPM, RollupJS, WebPack, etc.)
0.2.0-pre01

10 years ago

0.1.0-pre8b

10 years ago

0.1.0-pre5

10 years ago

0.1.0-pre3

10 years ago

0.1.0-pre2

10 years ago

0.1.0-pre1

10 years ago

0.0.2-aa1

10 years ago

0.0.1

10 years ago