DedrisFrameworkDedrisFramework

← Plugins  /  SQLite Storage

💾

SQLite Storage

cordova-sqlite-storage
iOS Android

This community plugin gives your app a real, persistent SQLite database with a familiar transaction-based API. Unlike localStorage, the data is stored natively and isn't cleared by the web view — ideal for structured records, offline caches and larger datasets.

Installation

terminal
cordova plugin add cordova-sqlite-storage

Opening a database

Open (or create) a database via window.sqlitePlugin after deviceready:

syntax
var db = window.sqlitePlugin.openDatabase({
  name: "dedris.db",
  location: "default"
});

Core methods

MethodDescription
sqlitePlugin.openDatabase(options)Open or create a database and return a handle.
db.transaction(fn, error, success)Run a read/write transaction; rolls back automatically on error.
db.executeSql(sql, params, success, error)Run a single statement outside an explicit transaction.
tx.executeSql(sql, params, success, error)Run a statement inside a transaction; success receives a result set.
db.close(success, error)Close the database handle.

Usage example

Create a table, insert a row, and read it back:

www/js/app.js
document.addEventListener("deviceready", onReady, false);

function onReady() {
  var db = window.sqlitePlugin.openDatabase({ name: "dedris.db", location: "default" });

  db.transaction(function (tx) {
    tx.executeSql("CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)");
    tx.executeSql("INSERT INTO notes (body) VALUES (?)", ["Hello"]);
  }, function (err) {
    console.error("Tx error: " + err.message);
  }, function () {
    db.executeSql("SELECT * FROM notes", [], function (rs) {
      console.log("Rows: " + rs.rows.length);
    });
  });
}

Tips

📚 Source: the technical reference on this page is based on the cordova-sqlite-storage project (MIT licensed), maintained by the open-source community. Descriptions and examples have been rewritten in DedrisFramework's own words. This plugin is not part of the Apache Cordova core.
← Back to plugins Start a project