-
Hi, I have an issue where I have two apps writing to the same sqlite database. The issue is that there is two seperate singletons being created and when they both write to the database it locks the database because sqlite can have multiple reads but only single writes. Is there a way I can create a IsolateNameServer where I can share the database connection between two applications so that this does not happen? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
So I assume this is for a desktop machines (since applications are sandboxed on mobile and won't access the same database file in an unrestricted manner)? If there are indeed two different processes, you can't use an |
Beta Was this translation helpful? Give feedback.
-
I tried to simulate the above scenario using two basic Flutter applications to see if the isolate instances can be shared between them. Here's the shared database class to be used by both applications running on the same device:
For Application 1 I call the initialization method:
Then, on the dart side I run a query on the database:
I replicated the above logic for Application 2. |
Beta Was this translation helpful? Give feedback.
So I assume this is for a desktop machines (since applications are sandboxed on mobile and won't access the same database file in an unrestricted manner)?
If there are indeed two different processes, you can't use an
IsolateNameServer
for communication between them. Drift provides the general-purpose remote library, which you can use to implementDriftIsolate
-like services over all kinds of communication channels. So depending on the OS you could use unix sockets or something to let the processes coordinate access to the database.