nativescript-sqlite icon indicating copy to clipboard operation
nativescript-sqlite copied to clipboard

database version number

Open terhoraj opened this issue 10 years ago • 4 comments

Hey, If I ship new database within the app, how can I increment it's version so if it already exists, current get deleted and new comes in?

terhoraj avatar Aug 26 '16 04:08 terhoraj

We are also facing the same concern.

sarvagayatri avatar Sep 12 '16 11:09 sarvagayatri

The easiest way to do this; would be to open the existing database; get its version number; check to see if it is older; then if it is older; close the db; copy the new db over...

NathanaelA avatar Sep 13 '16 01:09 NathanaelA

do you have any sample for incremental updates implementation?

sivamamidi-REISys avatar Sep 19 '16 06:09 sivamamidi-REISys

Thanks Nathan. Should have realized that without asking.

Anyone seeking this do it like this:

After instantiating new database connection like documentation says: new sqliteModule(databaseName, function (err, dbConnection) {.... /* Check current version / database.version(function (error, version) { if (version < CONSTANTNEWVERSIONNUMBER) { / Delete old database */ sqliteModule.deleteDatabase(databaseName); if (!sqliteModule.exists(databaseName)) { sqliteModule.copyDatabase(databaseName); this.afterDBUpdate (); // to handle version incrementation and new connection. } ...

SqliteViewModel.prototype.afterDBUpdate = function () { new sqliteModule(databaseName, function (err, dbConnection) { database = dbConnection; database.version(CONSTANTNEWVERSIONNUMBER); // Sets new version number }); };

terhoraj avatar Dec 05 '16 09:12 terhoraj