Tycholiz
Tycholiz

Reputation: 1200

React Native iOS unable to locate sqlite database

I am running WatermelonDB (which uses SQLite) on React Native. I am using the iOS simulator, and I am trying to locate the database file so I can query on it directly. It seems that I am able to successfully save to the database, since I can query data from within the app and it gets persisted.

Using htop, I have been able to find the running process of my application running on the simulator. However, when I cd into that directory, I see no .db file. I can even go to the root of all simulators ~/Library/Developer/CoreSimulator/Devices/ and ack for all db files, and still nothing shows up.

Next, I have tried launching the app in Xcode, as I have come across other posts that suggest checking the logs of Xcode, which is supposed to reveal the db location. Alas, this has shown me no information.

I am first interested to know how it is possible that anything at all is getting persisted, given that I cannot find a db file.

Second, should I be building my app from Xcode, or is it fine to use command line react-native run-ios? I can see that running this command uses Xcode under the hood, but I'm not sure if there are benefits to using Xcode. Nonetheless, using Xcode does not provide me with the answer I am looking for.

note: this is not a duplicate of this nor this, as I have followed all suggestions but have been unable to reach the conclusion

Upvotes: 1

Views: 1792

Answers (1)

Sators
Sators

Reputation: 3126

You can locate the watermelon.db files on your machine created by the iOS simulator by:

cd /Users/<your username>/Library/Developer/CoreSimulator/Devices
find . -name "watermelon.db"

This will show you the instances of watermelon.db files created by simulators. You can then take the output to an SQLite inspector and open /Users/<your username>/Library/Developer/CoreSimulator/Devices + {file path from find}.

If you have multiple results, then you may need to deduce which simulator is which by matching the ID to the simulator using xcrun instruments -s devices

Upvotes: 6

Related Questions