Skip to content
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

postgres: return whole result on updates and deletes #2944

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/driver/postgres/PostgresQueryRunner.ts
Expand Up @@ -174,7 +174,8 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
this.driver.connection.logger.logQueryError(err, query, parameters, this);
fail(new QueryFailedError(query, parameters, err));
} else {
ok(result.rows);
const wholeResult = result.command === "DELETE" || result.command === "UPDATE";
ok(wholeResult ? result : result.rows);
}
});

Expand Down
9 changes: 8 additions & 1 deletion src/query-builder/ReturningResultsEntityUpdator.ts
Expand Up @@ -40,7 +40,14 @@ export class ReturningResultsEntityUpdator {
return newRaw;
}, {} as ObjectLiteral);
}
const result = updateResult.raw instanceof Array ? updateResult.raw[entityIndex] : updateResult.raw;
let result;
if (updateResult.raw instanceof Array) {
result = updateResult.raw[entityIndex];
} else if (updateResult.raw.rows) {
result = updateResult.raw.rows[entityIndex];
} else {
result = updateResult.raw;
}
const returningColumns = this.queryRunner.connection.driver.createGeneratedMap(metadata, result);
if (returningColumns) {
this.queryRunner.manager.merge(metadata.target, entity, returningColumns);
Expand Down