Saving and updating data to our SQLite database is just a matter of creating a function for each Create, Read, Update, and Delete (CRUD) operation that we need, and forming the SQL statement before we execute it against the local database (our db
object).
In this recipe, we'll edit the database.js
module file to return a
db
object that contains two new functions, one for inserting a record into our favorites
table and one for deleting a record. We'll also capture the click events on our table rows to allow the user to view the record in a detailed subwindow, and add a button for creating and deleting favorites.
Open the JavaScript file called database.js
, and replace its contents with the following:
//create an instance of a database module.exports = (function() { //create the database object var db = {}; db.database = Ti.Database.open('mydb'); db.database.execute('CREATE TABLE IF NOT EXISTS favorites (ID INTEGER PRIMARY...