react-native-nitro-sqlite icon indicating copy to clipboard operation
react-native-nitro-sqlite copied to clipboard

Migrate library to a Nitro module (`react-native-nitro-modules`)

Open chrispader opened this issue 1 year ago • 7 comments

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

chrispader avatar Sep 11 '24 14:09 chrispader

🚀🚀

mrousavy avatar Sep 15 '24 13:09 mrousavy

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:

aedae78 (#60)

chrispader avatar Oct 02 '24 14:10 chrispader

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).

vhakulinen avatar Oct 02 '24 15:10 vhakulinen

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.

chrispader avatar Oct 03 '24 12:10 chrispader

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.

chrispader avatar Oct 03 '24 12:10 chrispader

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.

vhakulinen avatar Oct 03 '24 16:10 vhakulinen

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.

chrispader avatar Oct 04 '24 11:10 chrispader

Is this ready for review?

mrousavy avatar Oct 14 '24 09:10 mrousavy

Is this ready for review?

not quite yet! Still fixing some issues while working on the benchmarks

chrispader avatar Oct 16 '24 09:10 chrispader

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

chrispader avatar Nov 13 '24 11:11 chrispader

@vhakulinen also thanks for your input! I will hopefully address your concerns and issues in future PRs in react-native-nitro-sqlite

chrispader avatar Nov 13 '24 11:11 chrispader