simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.64k stars 370 forks source link

Accessing DB from native app. #204

Open CodingAleCR opened 5 years ago

CodingAleCR commented 5 years ago

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?

simolus3 commented 5 years ago

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.

CodingAleCR commented 5 years ago

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!

nevi-me commented 4 years ago

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

CodingAleCR commented 4 years ago

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.

Drkstr commented 3 years ago

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

How did you guys go with your projects?

CodingAleCR commented 3 years ago

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.

Harishwarrior commented 1 year ago

@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?

CodingAleCR commented 1 year ago

@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.