How to add local files/databases to Ionic build? (also using cordovaSQLite)


#1

Hello!

I’m working on a project currently which needs an extra (already created) database to be included in the build. I tried putting the database in /www/databases/myDB.db but I’m having trouble opening it.

I have another database being opened and handled correctly, so I wonder if this $cordovaSQLite plugin only handles one specific location.

Maybe someone knows more than me with including files, I can show off a few things that I tried. This isn’t going to be on one phone, but multiple (so I can’t just manually put the file on the phone)

var dbDirectory = cordova.file.applicationDirectory + "www/databases/myDB.db";

// Will not open
mapDB = $cordovaSQLite.openDB(dbDirectory);

// Will open, but will create a 'new' DB.sql in the databases folder (can show below)
mapDB = $cordovaSQLite.openDB({name: "myDB.db", location: dbDirectory});

// I believe it's just opening (creating if doesn't exist) at the database directory*
//   .. meaning location isn't being used

*The directory that the DB.sql ends up lying in (which $cordovaSQLite places by default):
file:///data/data/com.prominentedge.vida/databases/myDB.db

What I want to do in the end is to have a database be included in the APK installation. The directories can change, as long as it comes and works correctly.

If anyone has any ideas or helpful tips, it would be very appreciated.
Thank you very much!
Sam

quick edit: accidentally had previously named datamember


#2

I’d still like to try and figure out an answer, if anyone is willing to help!