Registry / database / cordova-plugin-nano-sqlite

cordova-plugin-nano-sqlite

JSON →
library1.7.0jsnpmunverified

A Cordova plugin that enables NanoSQL to use native SQLite on iOS/Android while falling back to IndexedDB/WebSQL in the browser with the same API. Version 1.7.0 is the latest stable release. It provides full TypeScript support, an ORM, runtime type casting, undo/redo, and supports standard RDBMS queries like joins, groupby, and ordering. Differentiators include seamless cross-platform testing and a unified API for browser and device, unlike other SQLite plugins that require separate APIs.

npm install cordova-plugin-nano-sqlite
INSTALL
IMPORT
SIG · CORDOVA-PLUGIN-NAN
C
cordova-plugin-nano-sqlite
databasejavascriptv1.7.0
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.

getMode
import { getMode } from 'cordova-plugin-nano-sqlite/lib/sqlite-adapter';
const { getMode } = require('cordova-plugin-nano-sqlite');
getMode is a named export from the internal module, not the package root.
nSQL
import { nSQL } from 'nano-sql';
import { nSQL } from 'cordova-plugin-nano-sqlite';
nSQL belongs to the 'nano-sql' package, not this plugin.
nSQLite adapter
const mode = window.nSQLite.getMode();
const mode = nSQLite.getMode();
When using script tags, nSQLite is on the window object; for bundlers, import getMode from the adapter module.

Demonstrates setting up a model and connecting with SQLite mode, then performing a simple upsert and select.

import { getMode } from 'cordova-plugin-nano-sqlite/lib/sqlite-adapter'; import { nSQL } from 'nano-sql'; // Wait for device ready or DOMContentLoaded document.addEventListener(typeof cordova !== 'undefined' ? 'deviceready' : 'DOMContentLoaded', () => { // Define model and connect nSQL('users') .model([ { key: 'id', type: 'int', props: ['pk', 'ai'] }, { key: 'name', type: 'string' }, { key: 'age', type: 'int' } ]) .config({ mode: getMode() }) .connect(); // Query after connection nSQL().onConnected(() => { nSQL('users') .query('upsert', { name: 'bill', age: 20 }) .exec() .then(() => nSQL().query('select').exec()) .then(result => console.log(result)); }); });
Debug
Known issues
breakingVersion 1.3.0 requires cordova-sqlite-storage < 2.3.0; newer versions may break.
fix
Downgrade cordova-sqlite-storage to 2.2.1 or update to latest cordova-plugin-nano-sqlite.
affects: <=1.3.0
deprecatedUsing require() style CommonJS imports may fail in bundlers; ESM is required.
fix
Use ES module imports: import { getMode } from 'cordova-plugin-nano-sqlite/lib/sqlite-adapter';
affects: >=1.0.0
gotchaMust call getMode() and pass it in config; forgetting this defaults to incorrect storage.
fix
Always include mode: getMode() (or window.nSQLite.getMode() for script tags) in .config().
affects: >=1.0.0
gotchaPlugin does not auto-detect Cordova; you must manually check for deviceready event.
fix
Use document.addEventListener('deviceready', ...) before connecting.
affects: >=1.0.0
gotchagetMode is not exported from the package root; only from the internal adapter module.
fix
Import getMode from 'cordova-plugin-nano-sqlite/lib/sqlite-adapter'.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: nSQLite is not defined
Trying to use window.nSQLite without loading plugin script or before deviceready.
fix
Ensure plugin is installed and wait for 'deviceready' event before accessing nSQLite.
Module not found: Can't resolve 'cordova-plugin-nano-sqlite'
Importing from package root instead of internal adapter path.
fix
Use import { getMode } from 'cordova-plugin-nano-sqlite/lib/sqlite-adapter';
Error: No mode set. Please set mode via .config({ mode: ... })
Calling .connect() without specifying mode.
fix
Add mode: getMode() (or window.nSQLite.getMode()) in the config object.
cordova-sqlite-storage: Plugin not found. Check your installation.
Missing cordova-sqlite-storage dependency.
fix
Run: cordova plugin add cordova-sqlite-storage --save
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
nano-sqlrequiredCore NanoSQL library required for query building and data modeling.
cordova-sqlite-storagerequiredUnderlying SQLite storage engine for Cordova.
Agent activity
11 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
cordova-plugin-nano-sqlite — npm install cordova-plugin-nano-sqlite · libregistry