drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Support object-style `where` conditions in `update()` and `delete()`
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
## Feature Request: Support object-style `where` conditions in `update()` and `delete()`
My request only has the `where` condition, not the entire query API
I'm not against SQL-like syntax; it's only the complexity of the WHERE clause that affects my efficiency.
Drizzle already supports object-style `where` conditions in relational queries, for example:
```ts
await db.query.users.findMany({
where: {
id: userId,
status: 'active',
deletedAt: null,
},
});
```
It would be very useful if `update()` and `delete()` could support the same style of `where` conditions.
For example, instead of:
```ts
await db
.update(users)
.set({ status: 'active' })
.where(
and(
eq(users.id, userId),
eq(users.status, 'pending'),
isNull(users.deletedAt),
),
);
```
it could allow:
```ts
await db
.update(users)
.set({ status: 'active' })
.where({
id: userId,
status: 'pending',
deletedAt: null,
});
```
Similarly for `delete()`:
```ts
await db
.delete(users)
.where({
id: userId,
status: 'pending',
deletedAt: null,
});
```
### Motivation
I am **not** asking for a Prisma-style mutation API such as `db.query.users.update()` or `db.query.users.delete()`.
The existing SQL-like `update()` and `delete()` APIs are perfectly fine. The main issue is that writing multiple simple `AND` conditions becomes quite verbose:
```ts
.where(
and(
eq(users.id, userId),
eq(users.status, 'pending'),
isNull(users.deletedAt),
eq(users.type, 'normal'),
),
)
```
For simple equality/null conditions, an object-style syntax would be much easier to read and write:
```ts
.where({
id: userId,
status: 'pending',
deletedAt: null,
type: 'normal',
})
```
The existing expression-based syntax could still remain available for more complex conditions involving `or()`, `gt()`, `lt()`, `like()`, etc.
### Proposed API
Support both forms:
```ts
// Simple conditions
.where({
id: userId,
status: 'pending',
deletedAt: null,
})
// Complex conditions
.where(
and(
eq(users.id, userId),
or(
eq(users.type, 'normal'),
eq(users.type, 'admin'),
),
),
)
```
This would provide a convenient shorthand for the common case while preserving the full flexibility of Drizzle's existing SQL-like API.
I think this would make `update()` and `delete()` significantly more ergonomic without changing Drizzle's overall SQL-first design.
Contributor guide
Research direction
Start by comparing the existing relational-query object-style where handling with the update() and delete() entry points. Trace how object conditions should correspond to the requested equality and null conditions, while preserving expression-based where support. Done means both mutation APIs accept the object form shown in the issue and complex conditions remain available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100