drizzle-team / drizzle-team/drizzle-orm
1.0 beta: How to type select filters `where`?
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Enhancement hasn't been filed before.
- [x] I have verified this enhancement I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
With the new API, how can a variable be typed to what `where` expects?
```ts
const filters = { age: 21 }; // <-- How to type this?
if (search) {
// Error: Property OR does not exist on type
filters.OR = [
{
familyName: {
ilike: `%${search}%`,
},
},
{
givenName: {
ilike: `%${search}%`,
},
},
];
}
const users = await db.query.users.findMany({
where: filters,
limit: 10, // paginated
});
const totalItems = await useDb().$count(users, and(...filters));
```
Background: Sometimes the select filters need to be defined to be reused for multiple queries, e.g. do a findMany and then do a count with the same filters.
BTW: Does $count() not make use of new api?
Contributor guide
Assessment
This issue has not been assessed yet.