Skip to content

feat(alias-on-dup-update): use mysql 8.0.20+ VALUES(...) AS _new ON D… b635110 …UP KEY a=_new.#448

Merged
MrSwitch merged 2 commits into
nextfrom
use-on-dup-key-alias
May 16, 2026
Merged

feat(alias-on-dup-update): use mysql 8.0.20+ VALUES(...) AS _new ON D… b635110 …UP KEY a=_new.#448
MrSwitch merged 2 commits into
nextfrom
use-on-dup-key-alias

Conversation

@MrSwitch
Copy link
Copy Markdown
Owner

@MrSwitch MrSwitch commented May 16, 2026

Update the ON DUPLICATE KEY to use the Alias notation as described in https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html when the version of MYSQL is 8.0.20 or more

@MrSwitch MrSwitch changed the title Use on dup key alias feat(alias-on-dup-update): use mysql 8.0.20+ VALUES(...) AS _new ON D… b635110 …UP KEY a=_new. May 16, 2026
@MrSwitch MrSwitch requested a review from Copilot May 16, 2026 21:51
@MrSwitch MrSwitch merged commit 456c0a5 into next May 16, 2026
17 checks passed
@MrSwitch MrSwitch deleted the use-on-dup-key-alias branch May 16, 2026 21:53
github-actions Bot pushed a commit that referenced this pull request May 16, 2026
# [0.99.0](v0.98.5...v0.99.0) (2026-05-16)

### Features

* **alias-on-dup-update:** use mysql 8.0.20+ VALUES(...) AS _new ON D…  b635110 …UP KEY a=_new. ([#448](#448)) ([456c0a5](456c0a5))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 0.99.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UPDATE assignments to _new.<col>.
  • Prefix the generated duplicate-key clause with AS _new when 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.10 to keep asserting the legacy VALUES(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 for mysql: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 thread test/specs/post.spec.js
Comment on lines 89 to +93
it('should accept option.update=[field1, field2, ...fieldn]', async () => {
let called;

dare.engine = 'mysql:8.0.10';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants