Creating and opening databases
Creating and opening databases using Web SQL Database or the Cordova SQLite Storage plugin is easy, but there are a few differences between the two that you do need to be aware of. Before we cover these differences, let's go over the basics.
Note
The snippets in this section are located at snippets/08/ex1-create-database/
in the code package of this book. When using the interactive snippet playground, select 8: Web SQL Database
and Example 1.
While using Web SQL Database, you can open a database with the following:
let db = window.openDatabase(name, version, description, quota);
Let's go over the parameters:
name
: This is the filename of the database. It usually ends in a.db
extension. This parameter is required.version
: Web SQL Database supports versioned databases. This is technically a string parameter, so you could use 1.0 or even"one"
. My suggestion, however, is to always use 1 for a reason we're going to get to shortly.description
: This is a short description...