You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to define a dynamic query to provide some shared logic, but one caveat is that the table/column that needs to be referenced in this shared logic is dynamic, so I need to allow passing in both the original query builder as well as any table that has the given column.
constwithSharedLogic=<TextendsPgSelect>(builder: T,dynamicTable: AnyTableWithColumns<{myValue: number;}>,// how to type this?){returnbuilder.where(eq(dyamicTable.myValue,123));// dummy query}
What's the best type to use here for AnyTableWithColumns? Is it even possible to achieve this with the desired API? I've seen old advice suggesting things like AnyTable & { myValue: number }, but that just throws type errors now. I found { myValue: SQLWrapper } works, but there's some loss of type information there. It's also possible to pass in a verbose definition for PgColumn, but that's cumbersome.
This discussion seems similar, but nothing there points me in the right direction: #442
Is there a way to achieve this with the current API?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to define a dynamic query to provide some shared logic, but one caveat is that the table/column that needs to be referenced in this shared logic is dynamic, so I need to allow passing in both the original query builder as well as any table that has the given column.
What's the best type to use here for
AnyTableWithColumns
? Is it even possible to achieve this with the desired API? I've seen old advice suggesting things likeAnyTable & { myValue: number }
, but that just throws type errors now. I found{ myValue: SQLWrapper }
works, but there's some loss of type information there. It's also possible to pass in a verbose definition forPgColumn
, but that's cumbersome.This discussion seems similar, but nothing there points me in the right direction: #442
Is there a way to achieve this with the current API?
Beta Was this translation helpful? Give feedback.
All reactions