brodybits / cordova-sqlite-ext

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)
Other
71 stars 55 forks source link

Using the plugin with Ionic v4/v5 #89

Open sachithd opened 4 years ago

sachithd commented 4 years ago

Hi

We have a requirement to use a pre-populated sqlite database in an Ionic app but I have noticed that its not possible to include a db in the www directory any more as the files in www get deleted with every build.

The options are either you can have a custom config for your build or you can copy the db file into /src/assets folder which will then get copied into www/assets on build.

If you go with the 2nd option, this plugin will not create the database as it only tries to find the db inside the www directory not in the sub folders.

Below are the options I have used. {name: 'sqlite.db', location: 'default', createFromLocation: 1}

With the option createFromLocation: 1, this can be fixed by appending "assets" to the "www" string inside createFromResource function. on Android SQLitePlugin.Java ("www/assets/") on iOS and SQLitePlugin.m ("www/assets")

With the above changes we can get the plugin to work correctly.

Are there any better solutions to this? would it be better to update the plugin so that it can accept a path too rather than createFromLocation (or add a sub folder option)

Thanks