Repository navigation
feat: add returning option to update/upsert operations - #11782
Conversation
Deploying typeorm with
|
| Latest commit: |
dcb5d51
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f56da34c.typeorm.pages.dev |
| Branch Preview URL: | https://feature-returning-selection.typeorm.pages.dev |
commit: |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
returning option to update/upsert operations
PR Code Suggestions ✨Latest suggestions up to dcb5d51
Previous suggestionsSuggestions up to commit 028c519
Suggestions up to commit eec0d37
Suggestions up to commit 7d33e73
Suggestions up to commit d03f7f3
Suggestions up to commit 0359a7b
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR adds support for configurable RETURNING/OUTPUT clauses on repository update, updateAll, and upsert methods. Previously, these clauses could only be specified when using the query builder directly. Now developers can request returned values through a new returning option parameter when calling these higher-level repository methods.
Key changes:
- New
UpdateOptionsinterface with optionalreturningfield forupdateandupdateAllmethods - Extended
UpsertOptionsinterface to include optionalreturningfield - Updated method signatures across Repository, BaseEntity, and EntityManager to accept these options
- Driver interface updated to accept
ReturningTypeparameter for better type safety
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/repository/UpdateOptions.ts |
New interface defining options for update methods, including returning clause |
src/repository/UpsertOptions.ts |
Extended to include returning option for upsert operations |
src/query-builder/ReturningOption.ts |
New type definition for RETURNING clause (string or string array) |
src/repository/Repository.ts |
Updated update and updateAll signatures to accept optional UpdateOptions parameter |
src/repository/BaseEntity.ts |
Updated static update method signature to accept optional UpdateOptions |
src/entity-manager/EntityManager.ts |
Implementation changes to wire returning option through query builder for update, updateAll, and upsert |
src/driver/sqlserver/SqlServerDriver.ts |
Updated isReturningSqlSupported to accept ReturningType parameter |
src/driver/spanner/SpannerDriver.ts |
Updated isReturningSqlSupported to accept ReturningType parameter |
src/driver/postgres/PostgresDriver.ts |
Updated isReturningSqlSupported to accept ReturningType parameter |
src/driver/oracle/OracleDriver.ts |
Updated isReturningSqlSupported to accept ReturningType parameter |
src/driver/cockroachdb/CockroachDriver.ts |
Updated isReturningSqlSupported to accept ReturningType parameter |
src/index.ts |
Exports UpdateOptions as RepositoryUpdateOptions (to avoid MongoDB type conflict) and ReturningOption |
docs/docs/working-with-entity-manager/6-repository-api.md |
Added documentation examples showing how to use returning option with update, updateAll, and upsert |
test/functional/repository/returning/repository-returning.ts |
New test file covering update and upsert with returning options |
test/functional/repository/returning/entity/User.ts |
Simple test entity for returning tests |
| const result = await repository.update( | ||
| 1, | ||
| { firstName: "Rizzrak" }, | ||
| { returning: ["id", "firstName"] }, | ||
| ) | ||
| console.log(result.raw) // [{ id: 1, firstName: "Rizzrak" }] |
There was a problem hiding this comment.
As a stretch goal in the future, any idea how could we make this type-safe? i.e. result.id & result.firstName become defined on result.... somehow.
| @@ -0,0 +1,99 @@ | |||
| import { expect } from "chai" | |||
There was a problem hiding this comment.
The test is not ending with .test.ts 🙈 so it's not running
## Summary - allow repository/entity manager delete APIs to accept returning options when supported - wire returning option through delete/deleteAll and expose typings - add coverage and docs for the new feature This follows the same pattern established in PR typeorm#11782 for update/upsert operations. Co-authored-by: Cursor <[email protected]>
## Summary - allow repository/entity manager delete APIs to accept returning options when supported - wire returning option through delete/deleteAll and expose typings - add coverage and docs for the new feature This follows the same pattern established in PR typeorm#11782 for update/upsert operations. Co-authored-by: Cursor <[email protected]>
Summary