simolus3 / drift

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

[Question] Multi entity insert (Insert object and contained object in different tables in one query) #827

Open Kobreizhyashi opened 3 years ago

Kobreizhyashi commented 3 years ago

Hi !

I'm currently discovering Moor for a professionnal project and I appreciate it. I've a question about the data insertion. Actually, I'm working with tabs which contains fieldsets, which contains fields etc..etc.. Should I insert tabs, fieldsets etc.. separatly or is there any way, with Foreign keys to just call a TabDao.insert and then insert all the structure with all datas in their own tables (created from .moor files) ?

Thanks ! KBZH

simolus3 commented 3 years ago

No, moor does not provide apis to insert multiple entities at once. There have been similar issues requesting moor to behave more like an ORM (https://github.com/simolus3/moor/issues/114 for instance). In general I view moor as a convenient yet thin wrapper around sqlite though, not as an ORM. Given the additional complexity that would be required to support those features well, I'm rather reluctant to work on them.

So long story short, you'll have to write that code manually. In practice its not that bad since you can essentially write an upsert for each table and then call those methods inside a transaction.