typelevel / skunk

A data access library for Scala + Postgres.
https://typelevel.org/skunk/
MIT License
1.57k stars 157 forks source link

Support `select * from ...` where schema is not known at compile time #662

Closed fdietze closed 1 year ago

fdietze commented 2 years ago

(originally asked on discord: https://discord.com/channels/632277896739946517/839844929877704785/977322704363479050)

I need to query a table where the schema is not known at compile time. That means I'd like to do a select * from dynamicTable and get an Array[String | null] for every row, which I can further process according to the types I know at runtime.

Low-level types in the array would also be ok, since I can cast them accordingly. But I need to know if a field is null or not.

So far in ScalaJS, it seems like I'm stuck with with pg-node and use their rowmode: 'array' feature (https://node-postgres.com/features/queries)

tpolecat commented 2 years ago

The low-level protocol produces a List[Option[String]] which is what you want, but there's no way to get to it through the provided interfaces. It could be done by modifying Query to know that the result is dynamic in order to selectively bypass arity/type checking.

fdietze commented 2 years ago

That sounds sufficient, thank you!

How do we proceed? Is it something you can do quickly, or should I get my hands dirty?

fdietze commented 2 years ago

I think I'll approach this soon. What would be the rough steps to implement it?