How to create a reusable query that can receive different select values?

I have a query with a lot of filters and ordering logic that I want to reuse but with different selects across a few endpoints, something like this:
getProjectQuery<T extends SelectedFields>(select: T, filters: ProjectFilters) {
db
.select(select)
.from(project)
.leftJoin(customer, eq(customer.id, project.customerId))
.where(...filters);
}
getProjectQuery<T extends SelectedFields>(select: T, filters: ProjectFilters) {
db
.select(select)
.from(project)
.leftJoin(customer, eq(customer.id, project.customerId))
.where(...filters);
}
But I don't know how to type the select correctly. When I do this anything after the left join becomes a type error:
No description
2 Replies
hamidreza4dev
hamidreza4dev3mo ago
The problem is that you are using spread operator. use and(filters)
MAST
MASTOP3mo ago
I've tried that and that's not the issue. The error is also saying that where property does not exist.
Want results from more Discord servers?
Add your server