feat: query-builder: Upsert in InsertQueryBuilder (next)#7076
Closed
nebkat wants to merge 37 commits intotypeorm:masterfrom
Closed
feat: query-builder: Upsert in InsertQueryBuilder (next)#7076nebkat wants to merge 37 commits intotypeorm:masterfrom
nebkat wants to merge 37 commits intotypeorm:masterfrom
Conversation
058ab5b to
1972b85
Compare
7 tasks
7f7e1dd to
e96fdaa
Compare
Moves QueryBuilder and its subclasses to their own directory.
…oftDelete * DeleteQueryBuilder, UpdateQueryBuilder and SoftDeleteQueryBuilder abstracted to ModificationQueryBuilder * SoftDeleteQueryBuilder extends UpdateQueryBuilder
…er events * All transaction code abstracted back to QueryBuilder.execute(), new abstract method executeInsideTransaction() added * All before/after events abstracted back to QueryBuilder.execute(), new abstract methods execute[Before/After]QueryBroadcast()
…pression() Drivers must explicitly return "NULL" string because Array.join() ignores null values unlike string concatenation that was used previously.
More efficient method of finding the columns that are contained in a given entity object. Previously the object was recursively scanned for keys and all were converted to property paths, then for every property path the columns were searched to find a matching one. Now the columns are selected as the object is scanned, and since ownColumns is searched instead of all columns it is more efficient.
…dering For certain drivers where the native parameters are not indexed (e.g. MySQL, "?") the parameters which are found at the start of a query - specifically in UPDATE SET param = ? - must be placed at the start of the native parameters objects. For drivers where the parameters are indexed, the order must match the order of param variable creation (e.g. Postgres, ":1"). This allows each driver to specify whether it cares about parameter order, allowing UpdateQueryBuilder to reorder params if necessary.
…ryRunners While SELECT queries tend to result in objects containing columns and their values, DELETE/INSERT/UPDATE queries all have different outputs depending on the driver. This moves the processing of those outputs and their mapping to the [Delete/Insert/Update]Result objects to the driver QueryRunners so that it can be altered without changing the QueryBuilders.
Greatly simplifies getEntityValue, setEntityValue and related functions. Previously embedded objects were explored using recursive functions and array shifting, which is now replaced with simple for of loops. Improves readability and possibly performance.
* New QueryBuilder.createColumnValuePersistExpression() that converts (column, value) to expression string
* Previously mostly duplicated between InsertQueryBuilder and UpdateQueryBuilder
* SoftDeleteQueryBuilder now even closer to UpdateQueryBuilder
* Entity column and raw object key based expression generation also combined
* Previously some duplicated code, e.g. function values always treated as raw SQL
* InsertQueryBuilder.getInsertedColumnsOrKeys() now returns string[] if using raw objects
* Now supports extracting columns from multiple raw objects, without predefined insert columns
* Static ReturningResultsEntityUpdator.generateUUIDParameterName() for extracting generated UUID
* Ensures that InsertQueryBuilder uses correct parameter name
Replaces string concatenation with joins in all query builders. No longer need to keep track of whether a particular element of an expression should have a space before or after it.
Does not seem to do anything differently to Object.assign(). Introduce Mutable util to access readonly properties of classes when initializing.
…vers Some drivers require functions such as ST_AsGeoJSON when persisting or selecting columns, this moves the wrapping of the persist/select expressions from the query builder to the driver.
SAP HANA doesn't support null values as parameters so they are converted to the raw NULL value. This moves that conversion from query builder to SapDriver.
Makes Driver.parametrizeValue() an optional function, currently implemented only by SqlServer. Other drivers can now also add additional information to their parameters if necessary.
…yBuilder Moves all functionality from SoftDeleteQueryBuilder to UpdateQueryBuilder except the "from()" function used to specific "soft delete FROM table", because a similar method does not currently exist for UpdateQueryBuilder.
…aryGeneratedColumn
In preparation for "virtual"/computed columns, call internally generated columns "internal" rather than "virtual" to avoid confusion.
* Introduces new type to describe the fields parameter of an @Index or @unique. * Allows (type) => [type.column] syntax inside embedded
…yMetadatas() * Removes unnecessary array pushing/slicing * Matches buildMigrations()/buildSubscribers() more closely
…elete
* Rename ModificationQueryBuilder to AbstractModifyQueryBuilder (UPDATE/DELETE)
* New AbstractPersistQueryBuilder for INSERT/UPDATE/DELETE
* Common code for RETURNING expressions
* Common code for INSERT/UPDATE value expressions
* Move UpdateDateColumn, VersionDateColumn, etc to value expression calculation
* Matches InsertQueryBuilder behavior
refactor: driver: Move database specific EntityManagers to driver Accidentally ammended during rebase
…lags and generators Introduces `DriverConfig` and `DriverQueryGenerators` interfaces that include various flags that drivers can use to customize behavior of the built in functionality. This decouples these built in features from the drivers themselves, moving towards the possibility of having each driver in a separate package.
* InsertQueryBuilder.orUpdate() now takes 3 parameters, overwrite columns, column values and conflict condition
* Overwrite either specific property paths in array or `true` to overwrite all
* Values same as UPDATE query values, replaces overwritten columns
* Conflict see onConflict()
* InsertQueryBuilder.orIgnore() now takes 2 parameters, ignore and conflict condition
* Ignore boolean whether to add IGNORE / DO NOTHING, no longer accepts statement
* Conflict see onConflict()
* InsertQueryBuilder.onConflict() now accepts either raw expression or property paths array
* For Postgres/Sqlite ON CONFLICT ...
* EntityManager.upsert(), Repository.upsert(), BaseEntity.upsert()
Fixes: typeorm#1090
|
Why this PR was closed? |
Contributor
Author
|
@Pablo1107 Maintainers have stated that they do not intend on merging the refactoring (#7058) necessary for this change and will instead focus on a new version of TypeORM (https://github.com/typeorm/typeorm/tree/typed-repository). Change otherwise works perfectly but will now require refactoring. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #7058 (refactor: Query builders and entity/column/relation metadata)
Necessary due to large amount of duplicate code before refactor.
Only last commit is relevant to this PR! See #7058 for rest.
Description of change
Breaks existing API so has to be released in next. Much easier to use than before, but more importantly provides efficient upsert in
EntityManagerthat doesn't usesave.Example 1
Example 2
Improvement of #7029.
Fixes #1090.
Pull-Request Checklist
masterbranchnpm run lintpasses with this changenpm run testpasses with this changeFixes #0000