Replies: 2 comments 3 replies
-
Correct, if you want to interact with the instance from outside of JSI, you want to use the same version of sqlite
Is that possible? I'm not an Android expert, but my understanding was that Android-bundled SQLite is only available via the the Java interface, not from C++. That's one reason why I decided to bundle SQLite there, whereas on iOS I use bundled version. (The other reason being that Android devices are often very outdated and the variance in sqlite versions is large, which can cause practical problems). But maybe I didn't look deeply enough into it. It'd probably be easier for users if we used OS version by default and replacing it was an option for advanced users.
If you're looking for a quick sketchy hack, without properly engineering this feature (which could be very useful), you could pass pointer address to the JSI's sqlite instance through JS to wherever you need. |
Beta Was this translation helpful? Give feedback.
-
Follow up time!
While this seems simple on the surface, the challenge is that each step requires several setup changes, many of which you'll find are "not possible" according to various (answered) Stack Overflow answers. However, it is. Unfortunately, you will find that WMDB was not designed with a shared database in mind even after this. WMDB will fail to handle read errors, and it has not been set up to wait for locks, so it'll fail immediately instead of waiting for the lock. This is the default SQLite behavior, so it's not a huge surprise, but it'd be possible to fix in WMDB. Overall, I think it's fair to say that WMDB does not support native integrations. There are simply too many caveats, and it'd be better to use a different SQLite library or write your own, if you have plans to share data with any native code. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to write custom Kotlin code in an app such that it uses the bundled JSI version of SQLite (
sqlite/sqlite-amalgamation-3360000/sqlite3.c
) thatwatermelon-jsi
ships with?I do not have the option to use the non-JSI version, as I need the synchronous interface in RN.
Or alternatively change the
watermelon-jsi
package so it uses the Android-bundled version of SQLite instead?The issue is that WatermelonDB uses a SQLite version that's different than the OS's, thus they don't share database locks which can lead to corruption of the database:
https://ericsink.com/entries/multiple_sqlite_problem.html
Also happy to take any other suggestions on how to expose the shared SQLite instance so it's usable by the app and doesn't cause corruption? For example, will simply
#include ".../../../ ... sqlite.h
be sufficient, when it comes from a separate module?For context, I have come across DB corruption and was able to recreate the corruption by writing to the same DB file and table with the OS-bundled SQLite (
android.database.sqlite.SQLiteDatabase
) in Kotlin, while having the RN side also write to that same table. The issue happens with rapid writes.Beta Was this translation helpful? Give feedback.
All reactions