npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-websql

v0.0.10

Published

Cordova Websql Plugin

Downloads

99

Readme

WebSQL plugin for Apache Cordova

Adds WebSQL functionality as Apache Cordova Plugin implemented on top of Csharp-Sqlite library. Support of Windows 8.0, Windows 8.1, Windows Phone 8.0 and Windows Phone 8.1.

Sample usage

Plugin follows WebDatabase specification, no special changes are required. The following sample code creates todo table (if not exist) and adds new record. Complete example is available here.

var dbSize = 5 * 1024 * 1024; // 5MB

var db = openDatabase("Todo", "", "Todo manager", dbSize, function() {
    console.log('db successfully opened or created');
});

db.transaction(function (tx) {
    tx.executeSql("CREATE TABLE IF NOT EXISTS todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on TEXT)",
        [], onSuccess, onError);
    tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)", ['my todo item', new Date().toUTCString()], onSuccess, onError);
});

function onSuccess(transaction, resultSet) {
    console.log('Query completed: ' + JSON.stringify(resultSet));
}

function onError(transaction, error) {
    console.log('Query failed: ' + error.message);
}

Installation Instructions

Plugin is Apache Cordova CLI 3.x compliant.

  1. Make sure an up-to-date version of Node.js is installed, then type the following command to install the Cordova CLI:

     npm install -g cordova
  2. Create a project and add the platforms you want to support:

     cordova create sampleApp
     cd sampleApp
     cordova platform add windows <- support of Windows 8.0, Windows 8.1 and Windows Phone 8.1
     cordova platform add wp8 <- support of Windows Phone 8.0
  3. Add WebSql plugin to your project:

     cordova plugin add cordova-plugin-websql
  4. Build and run, for example:

     cordova build wp8
     cordova emulate wp8

To learn more, read Apache Cordova CLI Usage Guide.

Pre-populated DBs support

You can copy a prepared DB file to the App' LocalFolder on the first run, for example (in terms of the sample app):

initialize: function () {
    WinJS.Application.local.exists('Todo').done(
        function (found) {
            if (!found) {
                return copyStartData('Todo');
            }
        }
    );

    function copyStartData(copyfile) {
        return Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync('www')
        .then(function (www) {
            return www.getFolderAsync('data')
            .then(function (data) {
                    return data.getFileAsync(copyfile).then(
                        function (file) {
                            if (file) {
                                return file.copyAsync(WinJS.Application.local.folder);
                            }
                        });
            });
        });
    }

    ...
},

The snippet copies www/data/Todo pre-populated DB to the App' local folder if it did not exist.

Based on this StackOverflow question.

Quirks

  • The display name, and size parameter values are not supported and will be ignored.

  • Due to SQLite limitations db version parameter to openDatabase and changeVersion methods should be an integer value or integer's string representation.

  • openDatabase on WP8 bypass version check by default. The reason of this is async nature of cordova calls to native APIs. To force version check and enable full versioning functionality set up the following variable:

    window.__webSqlUseSyncConstructor = true;
  • To use nested transactions you will need to pass parent transaction like this:

    var db = openDatabase('test1.db', '1.0', 'testLongTransaction', 2 * 1024);
    db.transaction(function (tx1) {
        tx1.executeSql('DROP TABLE IF EXISTS foo');
        tx1.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');
        ...
        db.transaction(function (tx2) {
            tx2.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")');
        }, null, null, null, null, false, tx1);
        ...
    }, null, null);

    tx1 passed as the last argument in the nested db.transaction refers to the parent transaction.

    Other arguments (null, null, null, null, false, tx1) are:

    • the db.transaction error callback,
    • the db.transaction success callback,
    • preflight operation callback,
    • postflight operation callback,
    • readOnly flag,
    • parent transaction - respectively.
  • To enable logging use:

    window.__webSqlDebugModeOn = true;

Copyrights

Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.