kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.68k stars 271 forks source link

How to dynamically build list of keys to use in a select query in `.select(keys)`? #501

Closed lancejpollard closed 1 year ago

lancejpollard commented 1 year ago

Not sure where to post this, I tried discord but it seems dead, and I was the first person to tag kysely on stackoverflow, so not sure I will get any bites there. Any help would be appreciated (and note on where I should ask future questions, I have a few for kysely).

https://stackoverflow.com/questions/76277708/how-to-properly-build-an-array-of-keys-which-match-a-types-keys-in-typescript

Thanks!

koskimas commented 1 year ago

If the discord seems dead you were in the wrong discord. Please have a little bit of patience. The people that mostly answer questions there live in a completely different timezone from you. Have you heard that crazy rumour that the US is actually not the only country in the world 😄

You can use the DynamicModule or the $if method to make dynamic selections, but please consider using something other than Kysely if you need to do a lot of dynamic stuff. The whole point of Kysely is to do things in a type-safe way.

You can also always just use Kysely<any> to get a dynamic type-unsafe query builder.

koskimas commented 1 year ago

Here's one option https://kyse.link/?p=s&i=EJSmk5oumyP09batdYZl

koskimas commented 1 year ago

You were actually answered 11 minutes after your question in Discord. Jesus christ 😄 That's enough for you to consider it dead? Entitled much?