Ad hoc custom column type
Hello, we have a table that on the database level, the column is a string type, but on the typescript level, the type is a Type literal union.
Is there any way we can ad hoc type a column to a type we know during select queries and insert statements?
6 Replies
Hey 👋
Can you provide an example of what you mean?
Lest say I have this:
At the DB level,
b
is a string, but I want to type is as type X, how can I do that in my select query?Solution
Just give that type for the column in the table interface.
We aare using kysely-codegen, so there is no way to do this like one could do with a helper function like
selectFrom('my_table').select<MyType>(['b'])...
?Look for overrides in kysely-codegen, if its not supported, submit an issue if one doesn't exist.
If you're on postgres, try kanel-kysely