Book Image

PhoneGap for Enterprise

By : Kerri Shotts
Book Image

PhoneGap for Enterprise

By: Kerri Shotts

Overview of this book

Table of Contents (16 chapters)
PhoneGap for Enterprise
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Storing local data using SQLite


Most apps can get by with storing data using local storage or the File API. However, sometimes data needs to be stored locally in a relational method, and SQLite allows you to do just that. There was a standard for HTML5 that used SQLite behind the scenes, but this is now deprecated. This was also limited to five megabytes of data. The SQLite plugin, on the other hand, is not limited by size constraints other than the space available on the device. If you are familiar with the HTML5's Web SQL API, the SQLite API is very similar.

The SQLite plugin we're using doesn't live in the Cordova plugin registry, so it must be added via URL. When adding the plugin, use https://github.com/brodysoft/Cordova-SQLitePlugin instead of the following plugin ID:

cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin

To open or create a database, you can use the following at any time after deviceready has been fired:

var db = window.sqlitePlugin.openDatabase ( {name...