Setup:
Detailed instructions can be found on the Free Nights and Weekends Blog.
- Install SQLite Firefox extension. This extension provides an easy, GUI-based, editor to create and manage your SQLite database.
- Create a new database.
- Add a table
- Save the file in the Resource folder in your project.
- In your project, right click on the Resource folder and click Add > Existing Files…
- Choose your saved database. Make sure Relative to Enclosing Group is selected under the Path Type
Script
Now we are ready to edit our database.
//Add ready listener
lg.bind('lg_init', init);
function init() {
//Open database
lg.database.open({type:'file', name:'database'});
//Insert new row
lg.database.execute('INSERT INTO Test ("itemName") VALUES ("added2")');
//Add listener
lg.bind('lg_database', gotResults);
//Select rows
lg.database.query('SELECT * FROM Test');
}
//Once the results are retrieved, the following listener is called.
function gotResults() {
//Remove listener
lg.unbind('lg_database', gotResults);
//Get results
console.log(lg.database.results[0].itemName);
}
