This is the basic structure I'm using in an app.
getDatabasePath
will handle any detail on unzip, copy, etc,
index
will do all the usual dirty work, including withDatabase
that won't explode if the database
is missing
WatermelonProvider
to cover original one til the DB is ready
@devnrj07 Yeah, I cannot believe that this such a pain in the ... to work with pre-populated databases... I included expo-sqlite to my project, no luck. Then I tried it with watermelonDB, no luck. I wasted so much time of my life on this.
The way I am doing it right now is with https://github.com/andpor/react-native-sqlite-storage (make sure you follow the installation instructions closely).
For iOS I put the database into
ios/APP_NAME/www/some_database.db
, for Android I put it into this folderandroid/app/src/main/assets/www/some_database.db
. Make sure you add the DB file to the project in iOS as stated in the instructions of the Library https://github.com/andpor/react-native-sqlite-storage#setting-up-your-project-to-import-a-pre-populated-sqlite-database-from-application-for-ios.And then its this open database call, using the name of my databasefile (
some_database.db
): https://github.com/andpor/react-native-sqlite-storage#setting-up-your-project-to-import-a-pre-populated-sqlite-database-from-application-for-iosHowever, I'd prefer to do this with watermelonDB since this comes with a few advantages. But, no change that I get this working. I think what is happening when I use watermelonDB: I try to open the pre-populated database, but its overwriting my content of the database by creating a database/table with the exact same name... And I do not know how to get around this.