drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Add support for MERGE
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
The SQL standard supports [MERGE](https://modern-sql.com/caniuse/merge), and Postgres 15+ supports it under the hood.
Syntax:
```
MERGE
INTO [[AS] ]
USING [[AS] ]
ON
```
While one can raw-dog it, I think it would be really nice to see it in Drizzle. Something like this:
```ts
await db.mergeInto(tableName)
.usingValues(...upsertRecords) // of inferred insert type
.updateOnMatched(
($new) => ({
column: $new.value
})
)
.insertOnNotMatched(
($new) => ({
column: $new.value
other_column: $new.other_value
})
)
.returning()
```
Rough idea of course, but you get the point. A clean API to use the MERGE statement that will hopefully, one day, be available in all dialects.
Even though Drizzle aims to have a simple builder API, is this something that can be considered?
Contributor guide
Assessment
This issue has not been assessed yet.