Git Product home page Git Product logo

cordova-sqlite-storage-helper's Introduction

Cordova SQlite storage helper

Helper tools for Cordova-sqlite-storage see: https://github.com/litehelpers/Cordova-sqlite-storage.

This tool allows using SQLite storage for mobile devices or web browsers. Its mechanism automatically selects the way needed for open databases using cordova-sqlite-storage plugin or WebSQL implementation, depending on the platform.

Installation

First, execute the default installation of Cordova-sqlite-storage plugin then add following scripts in your page:

<script type="text/javascript" src="js/DeviceInfo.js"></script>
<script type="text/javascript" src="js/SQLiteStorageHelper.js"></script>

How to use (Methods)

  • init(name, location)
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        //Initialize after device is ready
        SQLiteStorageHelper.init("mydb.db", "default");
    }

Little trick checking a mobile device or web browser:

bindEvents: function ()
{
    if (DeviceInfo.isMobile) 
        document.addEventListener("deviceready", this.onDeviceReady, false);
     else 
        this.onDeviceReady(); //this is the browser
},
  • getDb()
var db = SQLiteStorageHelper.getDb();
  • onDbSuccess(msg)
SQLiteStorageHelper.onDbSuccess("executed");
  • onDbError(err)
SQLiteStorageHelper.onDbSuccess("error");
  • execute(sql, parameters, successCallBack, errorCallBack)
SQLiteStorageHelper.execute("SELECT name FROM sqlite_master WHERE type=? AND name NOT IN(?,?)", 
["table", "__WebKitDatabaseInfoTable__", "sqlite_sequence"],
function (tx, res) {
    for (var i = 0; i < res.rows.length; i++) 
        self.dropTable(res.rows[i].name);
});
  • executeTransaction(sql, parameters, successCallBack, errorCallBack)
SQLiteStorageHelper.execute("SELECT name FROM sqlite_master WHERE type=? AND name NOT IN(?,?)", 
["table", "__WebKitDatabaseInfoTable__", "sqlite_sequence"],
function (tx, res) {
    for (var i = 0; i < res.rows.length; i++) 
        self.dropTable(res.rows[i].name);
});
  • executeBatch(batch, successCallBack, errorCallBack)
SQLiteStorageHelper.executeBatch([Scripts1, Scripts1, ...]);
  • getWhere(data)
var where = SQLiteStorageHelper.getWhere([{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...]);

Output Object
//values: Col1=? AND Col2=?
//parameters: [1, 2]
  • select(obj)
SQLiteStorageHelper.insert({
    table: "MyTable",
    where: [{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...],
});
  • update(obj)
SQLiteStorageHelper.insert({
    table: "MyTable",
    data: [{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...],
    where: [{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...],
});
  • remove(obj)
SQLiteStorageHelper.remove({
    table: "MyTable",
    where: [{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...]
});
  • insert(obj)
SQLiteStorageHelper.insert({
    table: "MyTable",
    data: [{ col: "Col1", val: 1 }, { col: "Col2", val: 2 }, ...]
});
  • clearTable(table)
self.clearTable("myTable");
  • dropTable(obj)
self.dropTable("myTable");
  • clearDb()
 SQLiteStorageHelper.clearDb();
  • dropDb()
 SQLiteStorageHelper.dropDb();

cordova-sqlite-storage-helper's People

Contributors

lmorelato avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.