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
When calling this function i have autocomplete for prisma options that are passed to a query. It's also able to infer the output. So when i pass { select: { id: true }} it returns { id: string } based on the query/model.
Is there anything similar in drizzle? I tried to build it myself but so far unsuccessfully due to the complexity of the RelationalQueryBuilder
PS: I asked claude and it.. Actually made it work, do you think it's a viable solution?
// First, let's define a utility type to extract the first type parameter of a functiontypeExtractFirstTypeParam<T>=Textends(config?: infer U)=>any ? U : never;// Now, let's create a type to extract the extends clause from a conditional typetypeExtractExtendsClause<T>=Textends infer Uextendsany ? U : never;// Putting it all togethertypeExtractConfigType<T>=ExtractExtendsClause<ExtractFirstTypeParam<T>>;typeExtractedType=ExtractConfigType<typeofdb.query.users.findFirst>functiona<TextendsExtractedType>(options: T): Promise<ReturnType<typeofdb.query.users.findFirst<T>>>{returndb.query.users.findFirst(options)asany}// Has the correct typeconstc=awaita({columns: {id: true,},with: {stores: true,}})
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
-
Hello,
I have this helper for prisma in my repo
When calling this function i have autocomplete for prisma options that are passed to a query. It's also able to infer the output. So when i pass
{ select: { id: true }}
it returns{ id: string }
based on the query/model.Is there anything similar in drizzle? I tried to build it myself but so far unsuccessfully due to the complexity of the
RelationalQueryBuilder
What i wanna be able to do is something like
And the output should match what i would expect.
PS: I asked claude and it.. Actually made it work, do you think it's a viable solution?
Beta Was this translation helpful? Give feedback.
All reactions