Reputation: 3630
Very simply: What is the "correct" location to create SQLite database tables in a Firefox addon.
(If possible, I would like to create tables on installation of the addon).
Upvotes: 0
Views: 298
Reputation: 57651
It is best to create tables right before you start using the database. You cannot assume that doing it once (when the extension is installed) is sufficient - the user might remove your database later for one reason or another. So you would do something like this:
var dbConn = Services.storage.openDatabase(file);
if (!dbConn.tableExists("foo"))
{
// Database isn't initialized, do it now
dbConn.createTable("foo", "...");
}
This is also how I would update the database structure on extension updates - if after opening the database you see that the database structure is outdated then you update it. This way you will correctly handle the scenario that your extension was updated but the database was downgraded later at some point because of a backup being restored.
Upvotes: 1