feat(alias-on-dup-update): use mysql 8.0.20+ VALUES(...) AS _new ON D… b635110 …UP KEY a=_new.#448
Merged
Merged
Conversation
…UP KEY a=_new.a...
…UP KEY a=_new.a...
|
🎉 This PR is included in version 0.99.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Dare’s MySQL INSERT ... ON DUPLICATE KEY UPDATE generation to use the MySQL 8.0.20+ “row alias” syntax (... VALUES (...) AS _new ...) instead of the deprecated VALUES(col) function, while preserving legacy behavior for older MySQL versions.
Changes:
- Add engine-version detection (MySQL >= 8.0.20) and switch
ON DUPLICATE KEY UPDATEassignments to_new.<col>. - Prefix the generated duplicate-key clause with
AS _newwhen using alias notation. - Adjust unit specs to account for version-dependent SQL output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/specs/post.spec.js | Pins engine to an older MySQL version for the legacy VALUES(col) assertion and updates expectations context. |
| test/specs/field_alias.spec.js | Updates duplicate-key-update expectations to _new.<col> for MySQL 8.0.20+. |
| src/index.js | Adds MySQL version gating and emits alias-based ON DUPLICATE KEY UPDATE SQL for MySQL 8.0.20+. |
Comments suppressed due to low confidence (1)
test/specs/post.spec.js:99
- This test pins the engine to
mysql:8.0.10to keep asserting the legacyVALUES(col)syntax, but there isn't a corresponding spec here that asserts the new MySQL 8.0.20+ alias form (... VALUES (...) AS _new ON DUPLICATE KEY UPDATE col=_new.col). Adding a new test case formysql:8.0.20+would prevent regressions in the new behavior.
dare.engine = 'mysql:8.0.10';
dare.execute = async ({sql, values}) => {
called = 1;
sqlEqual(
sql,
'INSERT INTO test (`id`, `name`, `age`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `age`=VALUES(`age`)'
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -310,8 +312,8 @@ describe('field alias', () => { | |||
| assert.ok(_sql.includes('(`email`,`country_id`)')); | |||
|
|
|||
Comment on lines
89
to
+93
| it('should accept option.update=[field1, field2, ...fieldn]', async () => { | ||
| let called; | ||
|
|
||
| dare.engine = 'mysql:8.0.10'; | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.