Ad-Hoc select from table not in Kysely types

Hey, we are dynamically generating our KyselyDB types using the kysely-codgen cli, and want to know how one can ad-hoc use the selectFrom statement from a table not included in the generated types by typing it ourselves as we build the query?
4 Replies
koskimas
koskimas16mo ago
Do you mean a completely dynamic query at runtime or adding specific known table types for certain queries? For completely dynamic queries, you can just cast the Kysely instance to Kysely<any> For temporary types you can use the withTables method https://kysely-org.github.io/kysely-apidoc/classes/Transaction.html#withTables Having type-safety for know tables and allowing dynamic unknown tables and columns at the same time is unfortunately impossible.
bombillazo
bombillazoOP16mo ago
hey, the query is not dynamic, its a known table name so it would be for known table types that we can type on the spot does withTables work on real tables as well, like those not specified in the DB types?
koskimas
koskimas16mo ago
What do you mean by real tables? It works with any table. Types are erased during compilation. There can't be any connection between anything real or imaginary during runtime and the types. Types are just types.
bombillazo
bombillazoOP16mo ago
ok gotcha, thanks
Want results from more Discord servers?
Add your server