objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
1.04k stars 120 forks source link

reverse connection in native plugin #426

Closed DJafari closed 2 years ago

DJafari commented 2 years ago

imagine we are create a project with objectbox-dart in flutter

we want read all box of store in native plugin ( for example in android platform ), is possible this ?

if we define models in java / kotlin, are we can to read it ?

greenrobot-team commented 2 years ago

Theoretically yes, but we have not tested this. The model must match exactly (e.g. check that the model JSON files are identical) and the database must use the same directory. To avoid threading issues the code probably should create the store read-only (there can only be one write transaction at all times).

What's your use case here? Why can't the Dart code read/work with the database? Might using a platform channel be an option?

DJafari commented 2 years ago

because i have a foreground service and i want read / update my box in background, we must do it in native and can't done in dart

i think big problem is linking objectbox-model.json to the one file, is possilbe change default address of objectbox-model.json in java/kotlin ?

is possible make a sample for that?

thanks

greenrobot-team commented 2 years ago

Thanks for the details.

i think big problem is linking objectbox-model.json to the one file

It's fine to have two files. They are based on the annotated classes in each language anyhow. Maybe to clarify: you have to re-create the complete data model (all Dart classes annotated with @Entity) in Java/Kotlin for this to work.