alexb
alexb
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
Thanks for your help! I'll update the thread if I ever find a better solution
16 replies
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
That'll do, I feel like this is a pretty standard use case though, surprised there's no clean way to do it :/
16 replies
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
Nice thanks! yeah this is exactly the workaround I used
async function select<T extends SelectedFields>(selectFields: T) {
const drizzle = await getClient()
const query = drizzle.select(selectFields).from(users)
const queryWithWhere = query.where(eq(users.id, '123456')) as unknown as typeof query
const res = await queryWithWhere
return res
}
async function select<T extends SelectedFields>(selectFields: T) {
const drizzle = await getClient()
const query = drizzle.select(selectFields).from(users)
const queryWithWhere = query.where(eq(users.id, '123456')) as unknown as typeof query
const res = await queryWithWhere
return res
}
16 replies
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
No description
16 replies
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
from import type { SelectedFields } from 'drizzle-orm/pg-core'
16 replies
DTDrizzle Team
Created by alexb on 9/18/2024 in #help
How to type a generic selection function
@Mario564 thanks SelectedFields really help but I'm still having issues It works unless I add a where condition ie: return db.select(selectFields).from(users) // works return db.select(selectFields).from(users).where(eq(users.id, '1111')) // returns "any"
16 replies