feat(core): add em.clone() and qb.insertFrom() for server-side row cloning#7365
Merged
feat(core): add em.clone() and qb.insertFrom() for server-side row cloning#7365
em.clone() and qb.insertFrom() for server-side row cloning#7365Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #7365 +/- ##
========================================
Coverage 99.64% 99.64%
========================================
Files 262 262
Lines 26080 26270 +190
Branches 7207 6806 -401
========================================
+ Hits 25987 26177 +190
Misses 88 88
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
em.clone() and qb.insertFrom() for server-side row cloning
630ea02 to
9f172a7
Compare
…w cloning Adds support for cloning database rows via INSERT...SELECT, avoiding data round-trips through the application. Two layers: - `qb.insertFrom(sourceQb)` — low-level QB method with 3-tier column derivation (metadata → select fields → explicit) - `em.clone(entity, where, overrides)` — high-level convenience that returns a hydrated entity Handles TPT inheritance (multi-table inserts), embedded properties, M:1 FK preservation, version property reset, and works across all SQL drivers. MongoDB uses find+insert fallback. Closes #5820 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add curly braces to single-line if statements (eslint curly rule) - Use AnyQueryBuilder<Entity> for insertFrom() parameter type - Fix MsSqlNativeQueryBuilder JSR return type issue Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use QueryBuilder<any> for insertFrom() param (avoids never/any variance) - Fix MongoDriver.nativeClone to handle PK value as where filter - Add MongoDB test suite for em.clone() coverage - Fix test entity definitions (Opt type, options typing) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… tests, refactor TPT filter - Add Product entity with persist:false and formula to test filter branches - Add Article/Company QB insertFrom tests for M:N and embedded filter branches - Refactor TPT filter to reuse getCloneableProps() - 72 tests total, 91.5% patch coverage Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…er checks - Remove unreachable generated/formula checks in getCloneableProps (caught by persist:false first) - Remove unreachable throw in resolveInsertFromColumns (meta always set) - Fix TPT version check to use tableMeta instead of leafMeta - Add MsSqlNativeQueryBuilder unit test for insertSubQuery delegation - Add DatabaseDriver.nativeClone throw test - Add MongoDriver "entity not found" test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove unreachable `inherited` checks from getCloneableProps (never true for non-TPT via meta.props, and TPT uses ownProps which skips the check) - Refactor tier 2 column resolver to filter instead of return [] - Fix TPT version check to use tableMeta.versionProperty - Remove STI test entities (not needed for coverage) Remaining 2 uncovered lines are TPT version property reset — requires TPT entity with version column which needs deeper schema support. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eaky abstraction - Extract `buildCloneFields()` and `mapCloneOverrides()` from duplicated loops in nativeCloneSimple/nativeCloneTPT - Use `for...of` instead of indexed loops for fieldNames iteration - Remove `options.select` dual-purpose in NativeQueryBuilder — store columns directly in `insertSubQuery.columns` - Remove empty `if` block in MySQL INSERT IGNORE handling - Strip narrating-the-obvious comments from EM, MongoDriver, SqlDriver - Fix `this.metadata` → `em.metadata` in em.clone() for consistency - Remove unnecessary spread copy of overrides (mapDataToFieldNames already copies internally) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9f172a7 to
cb16ab5
Compare
B4nan
added a commit
that referenced
this pull request
Apr 19, 2026
…w cloning (#7365) ## Summary - Adds `qb.insertFrom(sourceQb, options?)` — generates `INSERT INTO ... SELECT` with 3-tier column derivation: metadata-driven, select-field-driven, or explicit - Adds `em.clone(entity, where?, overrides?, options?)` — convenience method returning a hydrated entity, delegates to `driver.nativeClone()` - Handles TPT inheritance (multi-table inserts), embedded properties, M:1 FK preservation, version property reset - Works across all SQL drivers (SQLite, PostgreSQL, MySQL, MariaDB, MSSQL); MongoDB uses find+insert fallback Closes #5820 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
B4nan
added a commit
that referenced
this pull request
Apr 20, 2026
…w cloning (#7365) ## Summary - Adds `qb.insertFrom(sourceQb, options?)` — generates `INSERT INTO ... SELECT` with 3-tier column derivation: metadata-driven, select-field-driven, or explicit - Adds `em.clone(entity, where?, overrides?, options?)` — convenience method returning a hydrated entity, delegates to `driver.nativeClone()` - Handles TPT inheritance (multi-table inserts), embedded properties, M:1 FK preservation, version property reset - Works across all SQL drivers (SQLite, PostgreSQL, MySQL, MariaDB, MSSQL); MongoDB uses find+insert fallback Closes #5820 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
qb.insertFrom(sourceQb, options?)— generatesINSERT INTO ... SELECTwith 3-tier column derivation: metadata-driven, select-field-driven, or explicitem.clone(entity, where?, overrides?, options?)— convenience method returning a hydrated entity, delegates todriver.nativeClone()Closes #5820
🤖 Generated with Claude Code