Regression: Deprecation of .onConflict in InsertQueryBuilder
Issue Description
Since this commit https://github.com/typeorm/typeorm/commit/a1c6bb0092b63fa808d9f836936238a7977a8027 by @imnotjames the .onConflict-method of the InsertQueryBuilder is marked as deprecated and refers to .onUpdate as an alternative.
However .onUpdate does not provide the possibility to define an additional WHERE condition. In my current project we have an upsert function that will attempt an insert and fallback to an update. The data to be upserted is possibly outdated so we pass a WHERE condition in the .onConflict that checks a timestamp.
Example:
.onConflict(
`("${conflictingColumn}") DO UPDATE
SET (${columnName}) = (${value})
WHERE timestamp < ${eventTimestamp}`
)Possible remedies for the situation are:
- try insert, catch conflict, try update; but that would require a wrapping transaction and locks on the table, that I don't necessarily want
- let typeorm generate the insert and append the conflict handle by hand (which feels super hacky)
So for now I'm stuck with the deprecated .onConflict and I fear it will be removed without an alternative for this use case. So my questions is: Is this use case so special or did I miss something? Am I doing something completely wrong? If not, I would ask to no deprecate the .onConflict method without an alternative.
Relevant Database Driver(s)
| DB Type | Reproducible |
|---|---|
aurora-data-api |
no |
aurora-data-api-pg |
no |
better-sqlite3 |
no |
cockroachdb |
no |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
yes |
react-native |
no |
sap |
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.
Source: typeorm/typeorm