Registry / storage / cordova-plugin-sqlite-2

cordova-plugin-sqlite-2

JSON →
library1.0.7jsnpmunverified

A lightweight Cordova/PhoneGap/Ionic plugin that provides a WebSQL-compatible API backed by native SQLite. Uses built-in Android/iOS SQLite APIs (no bundling), offers unlimited and durable storage, prepopulated database support, and works where WebSQL is unavailable (e.g., old iOS WKWebView). Over 600 automated tests. v1.0.7 is the latest stable release; maintained via minor patches. Key differentiator: simple WebSQL polyfill without the bulk of other SQLite plugins.

npm install cordova-plugin-sqlite-2
INSTALL
IMPORT
SIG · CORDOVA-PLUGIN-SQL
C
cordova-plugin-sqlite-2
storagejavascriptv1.0.7
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.

sqlitePlugin
window.sqlitePlugin.openDatabase('mydb.db')
require('cordova-plugin-sqlite-2').openDatabase
Global browser/Cordova object; must use window.sqlitePlugin because plugin attaches to window.
openDatabase
window.sqlitePlugin.openDatabase('mydb.db', '1.0', '', 1)
window.sqlitePlugin.openDatabase({name: 'mydb.db', version: '1.0'})
Extra args ignored, but object syntax with {name} supported for compatibility.
transaction
db.transaction(function(txn) { txn.executeSql('SELECT ?', ['val'], callback); })
db.executeSql('SELECT ?', ['val'], callback)
All SQL must be inside a transaction.

Create an SQLite database, create a table, insert a row, and query it.

// Install: cordova plugin add cordova-plugin-sqlite-2 var db = window.sqlitePlugin.openDatabase('mydb.db'); db.transaction(function (txn) { txn.executeSql('CREATE TABLE IF NOT EXISTS demo (id, val)', [], function () { txn.executeSql('INSERT INTO demo VALUES (?, ?)', [1, 'hello']); txn.executeSql('SELECT * FROM demo', [], function (tx, res) { console.log('Row count:', res.rows.length); }); }); });
Debug
Known issues
gotchaIn-memory databases named ':memory:' may not persist across app restarts.
fix
Use a persistent database name (e.g., 'mydb.db') to avoid data loss.
affects: >=1.0.0
gotchaDatabase location is managed by Cordova; custom locations not supported.
fix
Rely on the default location; do not attempt to specify a custom path.
affects: >=1.0.0
deprecatedWebSQL is deprecated by W3C; new apps should prefer IndexedDB if possible.
fix
Consider using IndexedDB via libraries like Dexie or LocalForage.
affects: >=1.0.0
Errors
Common errors & fixes
sqlitePlugin is not defined
Plugin not installed or not initialized in Cordova's device ready event.
fix
Ensure the plugin is added (cordova plugin add cordova-plugin-sqlite-2) and access sqlitePlugin after deviceready event.
Failed to open database: unknown error
Corrupted database file or storage permission issues on Android/iOS.
fix
Delete app data or reinstall; on Android ensure storage permissions are granted.
Cannot read property 'executeSql' of undefined
Transaction callback returned before executeSql was called.
fix
Ensure transaction callback receives txn object and you call txn.executeSql inside it.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
cordovarequiredCordova CLI required for installation
Agent activity
25 hits · last 30 days
node
24
Resources
cordova-plugin-sqlite-2 — npm install cordova-plugin-sqlite-2 · libregistry