CASE with subquery clause
How can I return the column value from the subquery in a CASE? With this example, Kysely thinks the second condition is
{ name: string }
:
7 Replies
Hey 👋🏻
We probably allowed expressions, but didn't really handle select queries there at the type-level.
Ideally, we'd only allow selects with a single result column and use it's type as the subquery's result instead of an object.
But that would be tricky right
Would need a helper like $scalar
because probably there are use cases where the user expects a tuple
Yeah we already handle
SelectQueryBuilder<DB, TB, Record<string, T>>
specifically in some places for this very reason. We need to do it here as well.
In other places, we just do something like R[keyof R]
and assume only a single column is selected by the subquery. I don't think it's possible to make sure of that in the type level. At least without something crazy.
There's this helper for the job
maybe this is recipe worthy?
No I meant we should fix this internally
Could you create an issue?
Ok
This is now fixed in master