Hi everyone
I am new to doobie and this is probably an obvious question, but I'm struggling with some basic SELECT query where I wan't to retrieve nested case classes.
Say we have this very simplistic example (ids, fkeys and stuff ommited for simplicity):
case class Container(name: String, blocks: List[Block])
case class Block(name: String, zone: String)
What's the recommended (read: simple but efficient, as I will have loads of records) way to retrieve all Container
s?
I have seen some propositions using PG arrays through array_agg() + custom Get implem (see https://gitter.im/tpolecat/doobie?at=5d78c4dcb9abfa4bd38b1e28) but this seems very unintuitive.
Can you point me on the recommended way of doing this and associated documentation, if any?
Thanks in advance!
containers
and blocks
tables. That's why I mention array_agg().
SELECT c.name, b.name, b.zone FROM containers c JOIN blocks b...
then you select it as (String, String, String)
and groupBy(_._1)
or so
Block(containerName, name, zone)
The general advice is to fetch the rows as-is and group them scala side
Correct me if I misunderstand, but that means either:
all of this seems a bit weird in a world where JOIN is an option.
groupBy
s. For very simple joins like your example I'd just use groupBy to start :)
Or if you don't want the duplicated parent values in memory you can use a stream and do it on the fly.
Do you know where I can find an example of that? I'm asking existing ressource, don't write it up.
Yeah, sorry. It's not great.
Don't be! The journey is the reward, plus existing documentation is very clear. Required background is not your responsibility.
I will have to dig a little further to understand how it works, the doobie book is fine but a bit opaque for those who doesn't already masters FP.
@LeRiton if you have specific things you'd like to see improved, please please feel free to open a github issue/discussion about it. The docs are all in github as well if you have an idea to PR in