drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Allow updates with empty set

Open
#4,576 2 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe the enhancement you want to request

Basically the equivalent of the quite desirable and dev-friendly #1828 but for db.update().

Example code that is currently problematic but IMO should work just fine:

```typescript
function updateFooBar(id: string, alpha?: string, bravo?: string, charlie?: string, delta?: string) {
db.update(fooTable).set({alpha, bravo}).where(eq(fooTable.id, id));
db.update(barTable).set({charlie, delta}).where(eq(barTable.id, id));
}
```

The above will silently work as long as either alpha or bravo is set and charlie or delta is set, but if you ever omit both alpha and bravo or charlie and delta you will start getting exceptions. Instead you need the much less ergonomic and easy to forget to do:

```typescript
function updateFooBar(id: string, alpha?: string, bravo?: string, charlie?: string, delta?: string) {
if (alpha !== undefined || bravo !== undefined) {
db.update(fooTable).set({alpha, bravo}).where(eq(fooTable.id, id));
}
if (charlie !== undefined || delta !== undefined) {
db.update(barTable).set({charlie, delta}).where(eq(barTable.id, id));
}
}
```

In general making sure the concept of the number zero makes its way into as much of the library as possible would be great for DX.

I also think that beyond ergonomics, the risk of genuine production bugs from the above is pretty significant. If you split up a table into two like in the example code but forget to add the or-guarding, suddenly any part of your product that updates it has a high chance of being completely bricked.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.