You can use a plugin for this.
To install use the command: Cordova plugin add https://github.com/lite4cordova/Cordova-SQLitePlugin
In order to be able to use the Database anywhere in my code, I created a variable called DB at the beginning of the index.js page, which is more or less the beginning of the page:
var db;
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
db = window.sqlitePlugin.openDatabase({name: "DB"});
db.transaction(function(tx) {
// Cria a Tabela "tabela_testes"
tx.executeSql('CREATE TABLE IF NOT EXISTS tabela_teste (id integer primary key, titulo text)');
// Adiciona um elemento a tabela
tx.executeSql("INSERT INTO tabela_teste (titulo) VALUES (?)", ["Meu primeiro post."]);
// Faz uma busca na tabela
tx.executeSql("SELECT * FROM tabela_teste;", [], function(tx, res) {
alert("Quantidade Resultados: " + res.rows.length);
for (var i = 0;i<res.rows.length;i++){
alert("Linha "+i+": "+res.rows.item(i).titulo);
}
});
});
To Query any part of the Application even outside the index.js page, just use the DB variable and the query you want as in the above code.
Source: https://diariodoprogramadortda.wordpress.com/2014/03/04/trabalhando-com-sqlite-no-cordovaphonegap/
A parallel question here. Through Phonegap we were able to create an application using HTML5, jQuery. But a question, maybe no-sense... after finishing the application has how to compile it in .apk to work on Android ? or when speaking app is only to use in the browser ?
– Diego Souza
You have to understand that phonegap creates a "browser" compiled with its source code. Technically (roughly speaking) if you pick up your site today and play within the phonegap, you will be able to "install" it on the mobile... of course it is not so simple, but in theory it is this.
– LeandroLuk