Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db Transactions only execute in browser #15

Open
Turv opened this issue Nov 30, 2016 · 2 comments
Open

Db Transactions only execute in browser #15

Turv opened this issue Nov 30, 2016 · 2 comments

Comments

@Turv
Copy link

Turv commented Nov 30, 2016

Hi,

I've been using your starter template (It's great, thanks). I noticed when deployed to a device (Android) the "preload" database transactions specified do not execute unless it is in the browser.

This appears to be because we only execute the pre-defined transactions if
if (window.sqlitePlugin === undefined) {

Line 75: https://github.com/jdnichollsc/Ionic-Starter-Template/blob/master/app/js/services/sqlite.js

In the self.db method we already handle getting a database based on it being in app (and window.sqlitePlugin` being available or running in the browser. I don't think there is a need to check that the plugin is undefined before executing the preloading statements, without it, it appears to work fine.

I changed your version of the SQL Lite service to get an instance of the database, create (if not exists) a version history table, and then migrate from the current version to the new version if it is behind, this enables me to deploy SQL Updates to future versions of the app instead of running into problems later.

Cheers
Lee

@jdnichollsc
Copy link
Owner

Hi Lee,
Thanks for your comments! 💯
In the browser is required to execute the queries to preload the database, but in the mobile you can use the pre.db file (A pre-populated database that you can edit using DB Browser for SQLite)

I have an implementation about migrations, I need to include that in this template.
Let me check your example! 👍

Best regards, Nicholls

@Turv
Copy link
Author

Turv commented Dec 2, 2016

Hi Nicholls,

You are indeed correct, I don't think that would be suitable for my specific application though as I foresee many migrations and the pre-populated Db wouldn't necessarily let me do this, or apply future ALTER TABLE / INSERT / UPDATE statements as the app progresses.

My initial thought on migrations was that I wanted a .NET Entity Framework type migration system but I decided it was too much effort.

Instead, I opted for a simple means of knowing the current version number and applying any missing updates upon the launch of the app. I found a solution by Alin Pandichi that met my requirements so I didn't have to write my own so credits to him.

I've forked the repo and committed this so you can see my approach. I've not used this in production yet but having tested in the browser and on multiple devices it seems to work great so far.

Turv@e888356

Cheers
Lee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants