drift icon indicating copy to clipboard operation
drift copied to clipboard

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

Open Kobreizhyashi opened this issue 5 years ago • 1 comments

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

Kobreizhyashi avatar Sep 17 '20 09:09 Kobreizhyashi

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.

simolus3 avatar Sep 17 '20 15:09 simolus3