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

Accessing database from a background Isolate & main Isolate #1118

Open
amugofjava opened this issue Jul 19, 2024 · 1 comment
Open

Accessing database from a background Isolate & main Isolate #1118

amugofjava opened this issue Jul 19, 2024 · 1 comment

Comments

@amugofjava
Copy link

amugofjava commented Jul 19, 2024

Hi,

Firstly, thank you for your great packages. I've been using your Sembast for years and it has been rock solid and it's so easy to use. I am now looking to Sqlflite, as I thought you could use it to access a Sqlite database in the background, but I am unsure.

On the usage recommendation page and within some issues, it says that access should only occur in the main Isolate; however, on the changelog, v2.2.0+3 says initial support of cross Isolate safe.

Please could you clarify if accessing a database from both the main Isolate, and a background Isolate (e.g. for writing records during a scheduled task) is possible and/or recommended.

Apologies if I this is mentioned in a change or readme and I've missed it.

@amugofjava amugofjava changed the title Accessing database from a background Isolate rather than main Isolate Accessing database from a background Isolate & main Isolate Jul 19, 2024
alextekartik added a commit that referenced this issue Jul 20, 2024
@alextekartik
Copy link
Contributor

Indeed many people have asked about access from another isolate and unfortunately I don't have a good answer for that and the documentation is unclear about that, sorry.
It should work although I have not tested it much and I have avoided it (for example by saving the temporary data read
in a file that I handle later in the main isolate). One common usage
on Android and iOS is to have access from a push notification isolate or scheduled task.

  • Good if you can avoid it and only limit to this case (background notification / scheduled task)
  • In both isolates
    • Use singleInstance: false in openDatabase
    • Don't close the database
  • Since hot reload might fail when using singleInstance: false (if done while a transaction is in progress), you
    can try singleInstance: true in the main isolate only.

alextekartik added a commit that referenced this issue Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants