Migrate library to a Nitro module (`react-native-nitro-modules`)
This PR migrates this library to a Nitro module using the new react-native-nitro-modules.
This PR includes changes from the following Sub-PRs that were needed to make this work:
- https://github.com/margelo/react-native-quick-sqlite/pull/59
🚀🚀
Both iOS and Android are now fully working! 🚀
This is how i got the ReactApplicationContext to work on Android. It's a bit of a hack, but i'm not sure there's going to be a different approach to get it, since we have to use the React Native TurboModule API:
Sorry, but what are nitro modules and why is this package being migrated to it? How is it different form the turbo modules that react-native the project is rolling out?
We're using this library in our application, and given the history if this library, seeing this PR makes me quite nervous. There are quite a few other issues to fix in this library than the underlying DX experience w.r.t. old native modules / turbo modules / nitro modules (like the performance, possible race conditions or the fact that some of the API will happily ignore everything except the first sql statement it receives).
Hey @vhakulinen, first of all thanks for using this library!
Nitro Modules is a new library created by @mrousavy that enables a way more performant and easier to use API to build native modules in React Native.
You can read more about the core differences between Nitro vs. Turbo vs. Expo Modules in the Nitro docs linked above.
We decided to migrate react-native-quick-slite to Nitro Modules, because it will improve not only performance for both sync and async operations, but also immensely improves code simplicity, because a lot of previously necessary code to work with JSI is now handled (more efficiently) by Nitro.
Most of the migration is already completed, i'm currently working testing this thoroughly and creating a reliant benchmark app to compare this implementation with the old JSI implementation and other SQLite libraries like op-sqlite.
The new Nitro implementation will technically work on RN old arch, but we have to see how much effort it takes to make it backwards-compatible, since we are only a few maintainers working on this project (mostly me 😃). Old version of this library will still work in Old Arch, but moving forward we will focus on maintaining this library as "new-arch-only". I will still give my best to apply future fixes and patches to a all versions of this library.
If you can give me a list with the specific issues you talked about, i can try to fix this soon. It might also be the case, that some issues have been fixed by using Nitro, since the code got way simpler and straight-forward, which means less space for mistakes and errors.
Besides migrating to NItro, we're also currently working on optimizing the library to be more performant in general, and provide an even simpler API for developers.
Thanks for the brief intro. I commented my (general) suggestions in #62.
I'm happy to see development work going on on this library! Its been stale for quite some time. I hope that the changes introduced in this PR won't be too much of a hassle when it comes to upgrading our app.
I hope that the changes introduced in this PR won't be too much of a hassle when it comes to upgrading our app.
If we make the library backwards-compatible, there will be no changes needed except for adding react-native-nitro-modules dependency in your app and optionally adding generic types for things like the QueryResult received from db.execute().
This is because the developer-facing API didn't really change. If we further improve the API in the future, this will be part of an extra (breaking) release.
If not, the new implementation will only be available through a "new arch"-enabled app.
Is this ready for review?
Is this ready for review?
not quite yet! Still fixing some issues while working on the benchmarks
After many months of migrating, testing and benchmarking, i am finally confident to merge this PR! 🚀
Both building the library as well as performance has been thoroughly tested and works both on old and new arch, both in bridgeless and non-bridgeless mode.
The migration to react-native-modules will be a great improvement in code readability, DX, maintenance and hopefully also performance! âš¡
cc @mrousavy
@vhakulinen also thanks for your input! I will hopefully address your concerns and issues in future PRs in react-native-nitro-sqlite