How to use powersync in a Home Screen widget? #342
Replies: 2 comments 2 replies
-
Here's an example of what I was using to trigger intents
|
Beta Was this translation helpful? Give feedback.
-
First of all:
Congrats and thanks! We're glad to hear that.
That is expected, Android's SQLite APIs doesn't support loading extension and may reference an older SQLite version without support for strict tables. If you want to use a PowerSync database from Kotlin code, you can use our Kotlin SDK for that. You can share databases between the two SDKs by using the same path, but you should only call It's possible that a recent version of the core extension made this worse, but it was never really supposed to work.
Just to be clear, that isn't applicable to PowerSync databases (even if you're using drift). PowerSync has its own code to talk to SQLite, and
True - because that likely uses a separate Flutter engine, we can only pass primitive objects between isolates. That will break
PowerSync uses transactions for that, so this shouldn't cause any data corruption issues. We also configure the database to use WAL, which generally means that a writer and an arbitrary amount of readers can use the database concurrently. So if you only do reads on for the homescreen widget, the advice is pretty simple: Just open another database instance on the background callback and completely ignore the main app. So the TL;DR is:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my app, I have Home Screen widgets which retrieve data from the db, and can write to the db with intents, on both android and iOS.
I recently ran into an issue where reading directly from the app's DB using
android.database.sqlite.SQLiteDatabase
lead to errors that looked like this:E/SQLiteLog(28610): (1) near "STRICT": syntax error in "CREATE TABLE ps_buckets(
This corrupted the db on client devices. I think it was working before I switched to the rust client.
I just wanted to clear up my understanding of using powersync (+ drift) in separate processes.
I've seen this:
powersync on isolate - #178
drift on isolate - https://drift.simonbinder.eu/isolates/
In this package https://docs.page/abausg/home_widget/features/interactive-widgets , communication with the main app is done with a background worker, which appears to work a little differently to isolates.
So I just would like some guidance on best practice for reading/writing to the db from a home screen widget or other extensions e.g. AppIntents (iOS). I'm not sure about whether powersync syncing the db from separate processes could cause issues and how to avoid that, and not sure the safe way to read from the db to avoid the above error.
Other than that, I've just completed migration from firestore to postgres + powersync and it's amazing 🤩 I had built my own firestore -> sqlite sync engine before which was brittle, so I know it ain't easy. Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions