drift icon indicating copy to clipboard operation
drift copied to clipboard

Accessing DB from native app.

Open CodingAleCR opened this issue 6 years ago • 8 comments

I have an app written natively that uses Flutter for some features and stores information using Moor. Now I want to access the "Moor" database from my native code (probably using Room library from Android), is it posible?

CodingAleCR avatar Oct 21 '19 21:10 CodingAleCR

It should work in theory, but you might run into synchronization problems if you open the database from Moor & Room simultaneously.

If you open the database via FlutterQueryExecutor.inDatabasePath, the location of the database file will be in Context.getDatabasePath() on Android. If you model the same table structure in Room, the interop should work. I've never tried it though.

simolus3 avatar Oct 22 '19 09:10 simolus3

I wonder if it would affect the synchronization. The idea is to make a native homescreen widget for android, and I don't know if the connection would work. I'll try to set it up and see how it goes. Thanks for the quick response!

CodingAleCR avatar Oct 22 '19 13:10 CodingAleCR

Hey @CodingAleCR, I want to try something similar. Did you succeed in accessing the same database from both Flutter and native with Room?

nevi-me avatar Feb 28 '20 17:02 nevi-me

Hi, I've had to put my side project on hold due to some personal issues, but I'm hoping to retake it soon. In case you were wondering, my idea was to use Moor to do the modeling and then copy that into the Room Database model. It's theoretically possible but haven't got around to making it a thing.

CodingAleCR avatar Feb 28 '20 18:02 CodingAleCR

@nevi-me @CodingAleCR am about to give this a try.

How did you guys go with your projects?

Drkstr avatar Feb 16 '21 20:02 Drkstr

Have kept it on hold since it took a different direction. Still think that it's theoretically possible though. I'm curious to see how it goes for you.

CodingAleCR avatar Feb 16 '21 20:02 CodingAleCR

@nevi-me @CodingAleCR am about to give this a try.

How did you guys go with your projects?

If you don't mind, Can you post your results/findings here?

Harishwarrior avatar Apr 05 '23 07:04 Harishwarrior

@nevi-me @CodingAleCR am about to give this a try. How did you guys go with your projects?

If you don't mind, Can you post your results/findings here?

I was able to access the DB from the native side on Android but my DB implementation on the Flutter side is using sqlite instead of Moor.

I get errors from time to time, mostly because I'm accessing the DB from the native Android side for a Home Screen widget. My widget implementation is not the best and was lazily done, so it might be the cause for the errors too.

CodingAleCR avatar Apr 05 '23 16:04 CodingAleCR