Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite Session Extension #3321

Open
rodydavis opened this issue Oct 31, 2024 · 1 comment
Open

SQLite Session Extension #3321

rodydavis opened this issue Oct 31, 2024 · 1 comment
Labels
question Further information is requested

Comments

@rodydavis
Copy link
Contributor

What would be the best way to explore using the official SQLite Session Extension with Drift?

https://sqlite.org/sessionintro.html

From my research the API is in C, and would need some compile flags passed to the custom sqlite build.

I did find an interesting example for iOS/MacOS:
https://github.com/gerdemb/SQLiteChangesetSync

@rodydavis rodydavis added the enhancement New feature or request label Oct 31, 2024
@simolus3
Copy link
Owner

At the moment (I hope this gets a lot easier with the native assets SDK feature), you can't pass custom compiler flags to the buildscripts in sqlite3_flutter_libs. So the first step is to fork that package and add the relevant definitions for the platforms you need unfortunately.

Once you have the functions available, you can write bindings to them using dart:ffi. You'll need the sqlite3* pointer to the database connection drift uses. You get access to the underlying database in the setup method on NativeDatabase constructors and you can use .handle to get the native pointer to use when calling other sqlite3 functions (it might be easier to start with a local database instead of using background isolates to have everything available in the same isolate).

With the database pointer, it should be possible to create changesets and apply them. How to best integrate that functionality into drift is another question. You could call the methods to create sessions synchronously, then use drift methods to run statements and once that's done, use another C call to obtain a changeset.

@simolus3 simolus3 added question Further information is requested and removed enhancement New feature or request labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants