feat: add-create-update-record in workflow (#14654)
## Description - this PR focuses on issue https://github.com/twentyhq/core-team-issues/issues/1476 - Added upsert action ## Visual Appearance <img width="1792" height="1041" alt="Screenshot 2025-10-03 at 12 57 58 PM" src="https://github.com/user-attachments/assets/57afb96c-d4b3-4a87-95f0-11ac4bd61dd8" /> <img width="1792" height="1031" alt="Screenshot 2025-10-03 at 12 57 48 PM" src="https://github.com/user-attachments/assets/9032d4c2-f0d2-46f1-8682-a7e5c280a303" /> --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Thomas Trompette <thomas.trompette@sfr.fr>
This commit is contained in:
+18
-16
@@ -266,7 +266,20 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
),
|
||||
);
|
||||
|
||||
return this.createQueryBuilder(
|
||||
const overwrites = [...conflictColumns, ...overwriteColumns].map(
|
||||
(col) => col.databaseName,
|
||||
);
|
||||
|
||||
const conflictTargets = conflictColumns.map((col) => col.databaseName);
|
||||
|
||||
const upsertOptions = {
|
||||
skipUpdateIfNoValuesChanged: options.skipUpdateIfNoValuesChanged,
|
||||
indexPredicate: options.indexPredicate,
|
||||
upsertType:
|
||||
options.upsertType || this.connection.driver.supportedUpsertTypes[0],
|
||||
};
|
||||
|
||||
const queryBuilder = this.createQueryBuilder(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -275,21 +288,10 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
.insert()
|
||||
.into(target)
|
||||
.values(entities)
|
||||
.orUpdate(
|
||||
[...conflictColumns, ...overwriteColumns].map(
|
||||
(col) => col.databaseName,
|
||||
),
|
||||
conflictColumns.map((col) => col.databaseName),
|
||||
{
|
||||
skipUpdateIfNoValuesChanged: options.skipUpdateIfNoValuesChanged,
|
||||
indexPredicate: options.indexPredicate,
|
||||
upsertType:
|
||||
options.upsertType ||
|
||||
this.connection.driver.supportedUpsertTypes[0],
|
||||
},
|
||||
)
|
||||
.returning(selectedColumns)
|
||||
.execute();
|
||||
.orUpdate(overwrites, conflictTargets, upsertOptions)
|
||||
.returning(selectedColumns);
|
||||
|
||||
return queryBuilder.execute();
|
||||
}
|
||||
|
||||
override update<Entity extends ObjectLiteral>(
|
||||
|
||||
Reference in New Issue
Block a user