Querying two different tables with subset of common columns

Oohmi5/23/2023
I have two tables that have an intersection of common columns that I'm looking to query. For each of the tables, I have identical conditional logic (.wheres) that I'd like to apply for both queries, and it's quite extensive so I'd prefer not to copy and paste. My query would only .select the common columns.

Is there any Kysely-ic way of doing this?
IIgal5/23/2023
Hey 👋🏻

Extract to helpers that receive builder as argument and invoke stuff on it.
Then use helpers with .$call to invoke helpers.
Oohmi5/23/2023
how would type-safety work here? how would the builder argument know that the common columns exist on it?
IIgal5/23/2023
Short answer: generics.

Medium answer:
Each builder has 2 main generics, DB - the accumulated database object (+ aliased tables, CTE), and TB - the accumulated table and CTE names. This is the query context all things are bound to. Helper's generics/args need to make sure certain tables or columns are in the builder's query context to accept it as argument.

Long answer: Tomorrow, I need to sleep 🙂
Oohmi5/23/2023
generics are my weakness :devastated:
would be super helpful if you have a minimal example to point to, no rush or anything, and goodnight
Oohmi5/23/2023
this is the final hurdle before completing my migration
IIgal5/23/2023
I'll come up with a playground link tomorrow
Oohmi5/23/2023
much appreciated
IIgal5/25/2023
the as any spam inside helpers is unavoidable, typescript can't narrow the generic values there 😦
IIgal5/25/2023
the important part is that you're strongly typed for the consumer
Oohmi5/25/2023
you are a wizard
Oohmi5/25/2023
huge thanks :D