How to create a typed array of columns for select?

Hello, I am trying to create some helpers that contain the list of columns used by multiple queries, and I want to have them typed to the table they belong to to have it suggest errors if a table changes or someone uses a non-valid column. How is this achievable with the kysely helper types? The array may also include expression builder or the jsonObjectFrom helpers since they are valid Select options
1 Reply
bombillazo
bombillazoOP11mo ago
ok that was quick, I found the solution:
const columns: ReadonlyArray<SelectExpression<DB, 'table_name'>> = [
...
] as const;
const columns: ReadonlyArray<SelectExpression<DB, 'table_name'>> = [
...
] as const;
Want results from more Discord servers?
Add your server