Skip to content

Commit

Permalink
refactor: Don't use reserved keyword as alias
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaumgartl committed Nov 14, 2024
1 parent 72b8ef7 commit 0cedc13
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Context {
* @param {?string} [alias=new]
* @return {Promise}
*/
upsert(table, data, update, alias = 'new') {
upsert(table, data, update, alias = 'new_values') {
const sql = upsertStmt(table, data, update, alias);
return this.exec(sql);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Transaction {
* @param {?string} [alias=new]
* @return {Promise}
*/
upsert(table, data, update, alias = 'new') {
upsert(table, data, update, alias = 'new_values') {
const sql = upsertStmt(table, data, update, alias);
return this.exec(sql).then(({ affectedRows, changedRows }) => ({ affectedRows, changedRows }));
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('transaction', () => {
await trx.upsert(
table,
{ id: 1, col1: 'bar' },
{ col1: ctx.raw(`CONCAT(${table}.col1, \`new\`.col1)`) }
{ col1: ctx.raw(`CONCAT(${table}.col1, \`new_values\`.col1)`) }
);
});

Expand Down
6 changes: 3 additions & 3 deletions test/unit/context.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe('context', () => {

const [call] = ctx.exec.mock.calls;
assert.deepEqual(call.arguments, [
`INSERT INTO \`t\` (\`col1\`, \`col2\`, \`col3\`) VALUES ('val1', 1, NOW()) AS \`new\` ON DUPLICATE KEY UPDATE \`col1\` = \`new\`.\`col1\`, \`col2\` = \`new\`.\`col2\``
`INSERT INTO \`t\` (\`col1\`, \`col2\`, \`col3\`) VALUES ('val1', 1, NOW()) AS \`new_values\` ON DUPLICATE KEY UPDATE \`col1\` = \`new_values\`.\`col1\`, \`col2\` = \`new_values\`.\`col2\``
]);
});

Expand All @@ -343,7 +343,7 @@ describe('context', () => {

const [call] = ctx.exec.mock.calls;
assert.deepEqual(call.arguments, [
`INSERT INTO \`t\` (\`col1\`, \`col2\`, \`col3\`) VALUES ('val1', 1, NOW()) AS \`new\` ON DUPLICATE KEY UPDATE \`col1\` = 'foo'`
`INSERT INTO \`t\` (\`col1\`, \`col2\`, \`col3\`) VALUES ('val1', 1, NOW()) AS \`new_values\` ON DUPLICATE KEY UPDATE \`col1\` = 'foo'`
]);
});

Expand All @@ -352,7 +352,7 @@ describe('context', () => {

const [call] = ctx.exec.mock.calls;
assert.deepEqual(call.arguments, [
`INSERT INTO \`t\` (\`id\`, \`ts\`) VALUES (1, '2000-01-01 00:00:00') AS \`new\` ON DUPLICATE KEY UPDATE \`ts\` = NOW()`
`INSERT INTO \`t\` (\`id\`, \`ts\`) VALUES (1, '2000-01-01 00:00:00') AS \`new_values\` ON DUPLICATE KEY UPDATE \`ts\` = NOW()`
]);
});

Expand Down

0 comments on commit 0cedc13

Please sign in to comment.