New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to use current values in insert Mysql/Postgres #3056
Conversation
I think there is atomic update case like |
@jsnick I think we can use
INSERT INTO foo (id, counter) VALUES (1, 10) ON DUPLICATE KEY UPDATE counter = counter + 1
Using
INSERT INTO foo (id, counter) VALUES (1, 10) ON DUPLICATE KEY UPDATE counter = VALUES(counter)
|
It would be nice if a high-level |
@marshall007 Sure, to me this sounds like another PR i would like to merge this one first. |
QueryBuilder is a complex task since we replace property names in database names and use property names in queries in most of places. In this case looks like we have to use database names, and its confusing. Lets merge it for now, but someday we'll need to figure out what to do with this confusion. Thank you for the contribution! |
ooups looks like a conflict, can you please resolve it? |
e3721d9
to
a457da5
Compare
@pleerock Sorry for the delay, resolved :) |
@@ -532,7 +532,7 @@ export class ColumnMetadata { | |||
* If column is in embedded (or recursive embedded) it extracts its value from there. | |||
*/ | |||
getEntityValue(entity: ObjectLiteral, transform: boolean = false): any|undefined { | |||
// if (entity === undefined || entity === null) return undefined; // uncomment if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, why its needed?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in some cases when you actually insert multiple rows which cause a conflict entity
is not defined, so therefore line 595 will break value = entity[this.propertyName];
Database with columns c1, c2, c3 with a unique index on c1 and the following data
| A (c1) | Foo (c2) | Bar (c3) |
If i try to insert the following
| A | Foo2 | Bar2 |
| A | Foo3 | Bar3 |
I just want the database to be | A | Foo3 | Bar3 |
i guess this has something to do with the fact that you are actually trying to insert N rows but returning N-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm not sure I got it, but okay, lets merge it
Thank you! |
In Mysql / Postgres add support to update record during INSERT on conflict / duplicate key using current values, implements, fixes #3047