Trouble with dynamically allocating table name via string
Hello!
I am having some trouble trying to allocate a table name dynamically via a string. I used the sql.table command in my SelectFrom statement but no such luck. Passing in a direct string also does not work as hoped.
I have read a few posts which indicate this is not possible, if not I can work around it, if it is however how might I achieve this?
// Ben
2 Replies
You can't do that while having strict types. The types depend on the runtime value of
tableName
. You can do anything if you downcast your kysely instance to Kysely<any>
.
But then of course, the result types are just any
I thought not. We might try with Kysely<any> in later experiments. Ideally we would be able to make a generic select, upate or delete statement that we can use on multiple tables.
For now we will live with the same statement for two tables. Will report back when we have tested with your suggestion