Registry / database / sql-promise-helper

sql-promise-helper

JSON →
library0.0.1-pre03jsnpmunverified

A promise-based wrapper for Web SQL and Cordova SQLite databases (v0.0.1-pre03). This library allows developers to execute SQL statements in batch transactions and chain operations using Promises, simplifying asynchronous database handling. It supports both the standard Web SQL interface (window.openDatabase) and the Cordova SQLite plugin (window.sqlitePlugin). The package is in pre-release stage and depends on the standard Promise object (polyfill required for older environments). It differentiates from other SQL promise libraries by focusing on batch transaction support with a simple, minimal API.

npm install sql-promise-helper
INSTALL
IMPORT
SIG · SQL-PROMISE-HELPER
S
sql-promise-helper
databasejavascriptv0.0.1-pre03
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

newPromiseHelper
import { newPromiseHelper } from 'sql-promise-helper'
import newPromiseHelper from 'sql-promise-helper'
Named export, not default. CommonJS users use require('sql-promise-helper').newPromiseHelper.
newPromiseHelper
const { newPromiseHelper } = require('sql-promise-helper')
const newPromiseHelper = require('sql-promise-helper')
Must destructure the named export. ES6 import is also supported.
newBatchTransaction
const tx = helper.newBatchTransaction()
const tx = new newPromiseHelper.db.newBatchTransaction()
Method on a promise helper instance, not a constructor or static.

Demonstrates creating a database, constructing a promise helper, executing batch statements, committing, and querying results using Promises.

// ES6 import import { newPromiseHelper } from 'sql-promise-helper'; // Open database (Web SQL or Cordova SQLite) const db = window.openDatabase('test.db', '1.0', 'Test', 5*1024*1024); // Create helper instance const helper = newPromiseHelper(db); // Create a batch transaction 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']); // Commit and query tx.commit() .then(() => helper.executeStatement('SELECT * FROM tt')) .then(rs => { const firstRow = rs.rows.item(0); console.log('Result length:', rs.rows.length, 'First:', JSON.stringify(firstRow)); }) .catch(err => console.error('Error:', err.message));
Debug
Known issues
gotchaThe library requires the standard Promise object. If the environment lacks Promise (e.g., older browsers), a polyfill must be included or the library will fail.
fix
Include a Promise polyfill like 'es6-promise' or 'promise-polyfill' before using this library.
affects: >=0.0.0
deprecatedWeb SQL is deprecated by W3C and not supported in some modern browsers (e.g., Firefox). Cordova SQLite plugin should be used for broader compatibility.
fix
Use Cordova SQLite plugin via 'window.sqlitePlugin.openDatabase' instead of 'window.openDatabase'.
affects: >=0.0.0
gotchaThe import must use named import { newPromiseHelper }, not default import.
fix
Use import { newPromiseHelper } from 'sql-promise-helper' or const { newPromiseHelper } = require('sql-promise-helper').
affects: >=0.0.0
gotchaThe `newPromiseHelper` function expects a database object; passing a wrong type (e.g., string) will cause runtime errors.
fix
Ensure the argument is a valid Web SQL or Cordova SQLite database instance.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: newPromiseHelper is not a function
Importing as default instead of named export.
fix
Use const { newPromiseHelper } = require('sql-promise-helper');
ReferenceError: Promise is not defined
Environment lacks native Promise (e.g., older browser).
fix
Add a Promise polyfill before using this library.
TypeError: helper.newBatchTransaction is not a function
Helper was created incorrectly, e.g., using a string instead of a database object.
fix
Verify that newPromiseHelper(db) receives a valid database instance.
Upgrade
Version history
0.0.1-pre03latest on npm
Audit
Dependencies
promise-polyfilloptionalRequired for environments without native Promise support (e.g., older browsers)
Agent activity
18 hits · last 30 days
node
14
Meta
1
Amazon
1
OpenAI (training)
1
Resources
sql-promise-helper — npm install sql-promise-helper · libregistry