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-websqldatabase-initializer

v0.0.1

Published

WebSqlDatabase initializer

Downloads

1

Readme

This is a Cordova 3 plugin (using the new plugin management system) that enables initialization for WebSqlDatabase.

If you want your PhoneGap application to start with a preloaded WebSqlDatabase, this plugin will simplify it for you.

This plugin is compatible with iOS, Android and WP (7 & 8).

Install

Using the Cordova 3 Command-line Interface:

cordova plugin add cordova-plugin-websqldatabase-initializer

If you are not using the Cordova Command-line Interface, follow Using Plugman to Manage Plugins.

Create the database containing initialization data

The database used for initialization (named "myDemoSQLiteDB" below) is an SQLite file with a ".db" extension compressed in a ".zip" file.

You can create the ".db" file with the initial content via Chrome/Chromium using the WebSqlDatabase API (and retrieve it from the "databases" diretory of the User Data Directory) or with an SQLite client (sqlite3, sqlitebrowser, ...).

Name the resulting database binary file with a ".db" extension and zip it.

Databases.db

For iOS and Android, a Databases.db file is required to "index" the available databases.

To create this file, use an SQLite client (sqlite3, sqlitebrowser, ...) and execute the following code (replacing "myDemoSQLiteDB.db" with the correct value):

BEGIN TRANSACTION;
CREATE TABLE Databases (id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT NOT NULL, name TEXT NOT NULL, description TEXT NOT NULL, estimated_size INTEGER NOT NULL, displayName TEXT, path TEXT, guid INTEGER);
INSERT INTO Databases VALUES(1,'file__0','myDemoSQLiteDB.db','Proto DB',0,'Proto DB','myDemoSQLiteDB.db',1);
CREATE TABLE Origins (origin TEXT UNIQUE ON CONFLICT REPLACE, quota INTEGER NOT NULL ON CONFLICT FAIL);
INSERT INTO Origins VALUES('file__0', 999999999);
CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR);
INSERT INTO meta VALUES('version',2);
INSERT INTO meta VALUES('last_compatible_version',1);
CREATE TABLE sqlite_sequence(name,seq);
INSERT INTO sqlite_sequence VALUES('Databases',1);
CREATE INDEX origin_index ON Databases (origin);
CREATE UNIQUE INDEX unique_index ON Databases (origin, name);
COMMIT;

Usage

Android

  • import "org.smile.websqldatabase.*" in your main class:
import org.smile.websqldatabase.*;
  • add "implements DatabaseInitializable" on your main class
  • implement the getDatabaseConfig method (with the correct database configuration):
@Override
public DatabaseConfig getDatabaseConfig() {
    return new DatabaseConfig("myDemoSQLiteDB.zip", "myDemoSQLiteDB.db");
}
  • implement the loadWebApp method (with the Cordova init code usually in the onCreate method)
@Override
public void loadWebApp() {
    super.loadUrl(Config.getStartUrl());
}
  • remove the Cordova init code in the onCreate method
  • load the database and run the app with "DatabaseInitializer.load(this);" in the onCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.init();
    DatabaseInitializer.load(this);
}
  • add the "Databases.db" file in your assets directory
  • add the zipped database ("myDemoSQLiteDB.zip") in your assets directory

iOS

  • import "LoadDatabase.h" and "DatabaseConfig.h" in your main class
#import "LoadDatabase.h"
#import "DatabaseConfig.h"
  • in the init method of your main class, call the "load" method on a "LoadDatabase" object with the correct DatabaseConfig in parameters:
[[LoadDatabase new] load:[[DatabaseConfig alloc] init:@"myDemoSQLiteDB.zip" secondValue:@"myDemoSQLiteDB.db"]];
  • add the "Databases.db" file in your Resources directory
  • add the zipped database ("myDemoSQLiteDB.zip") in your Resources directory

Windows Phone (7 & 8)

  • check that the http://smile-sa.github.io/cordova-plugin-websqldatabase/ plugin (enabling WebSqlDatabase feature on Windows Phone) has been correctly installed (check that the "plugins/org.smile.websqldatabase.wpdb" directory exists)
  • import "org.smile.websqldatabase" in your main class:
using org.smile.websqldatabase;
  • in the init method of your main class, call the "LoadDatabase" method on a "DatabaseLoader" object with the correct DatabaseConfig in parameters:
new DatabaseLoader().LoadDatabase(new DatabaseConfig(@"myDemoSQLiteDB.zip", @"myDemoSQLiteDB.db"));
  • add the zipped database ("myDemoSQLiteDB.zip") in the root directory of your solution
  • no need of a "Databases.db" file

Usage in JavaScript

Load the database with the following code:

window.openDatabase("myDemoSQLiteDB.db", "1.0", "Proto DB", 1000000);

Example

A prototype including this plugin is available at https://github.com/Smile-SA/cordova-plugin-websqldatabase-initializer-proto

External library

This plugin uses the following libraries: