-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Description
Feature Description
Should add support for CockroachDB's UPSERT query which has better performance, and works better with Composite Primary keys.
The Problem
Cockroach has a dedicated UPSERT method. Currently TypeORM's .upsert() method calls an INSERT ON CONFLICT query instead, which has worse performance and causes some bugs in our case.
The Solution
- Add a
upsertoption toUpsertType(src/driver/types/UpsertType.ts). - Rename
supportedUpsertTypetosupportedUpsertTypesand make it an array (since technically cockroachdb supports both approaches) - Add an optional
UpsertTypetoInsertOrUpdateOptionsthat let's the user define a custom Upsert for a given.upsert()query - The first
UpsertTypevalue in the driver will be the defaultUpsertTypeif none was provided in the query. For backwards compatibility, to have.upsert()work the same as it does currently. - Tweak
InsertQueryBuilder.tsto outputUPSERTinstead ofINSERTifUpsertTypeis equal toupsert. Also omit theON CONFLICTpart that is not supported in anUPSERTquery
Considered Alternatives
Writing an raw query, but that kinda defeats the purpose
Relevant Database Driver(s)
| DB Type | Relevant |
|---|---|
aurora-mysql |
no |
aurora-postgres |
no |
better-sqlite3 |
no |
cockroachdb |
yes |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
no |
react-native |
no |
sap |
no |
spanner |
no |
sqlite |
no |
sqlite-abstract |
no |
sqljs |
no |
sqlserver |
no |
Are you willing to resolve this issue by submitting a Pull Request?
- ✅ Yes, I have the time, and I know how to start.
- ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.