Skip to content

Commit

Permalink
test: Add test for custom alias in upsert method
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaumgartl committed Nov 14, 2024
1 parent 8409960 commit 4471e91
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/integration/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ describe('transaction', () => {
const result = await ctx.queryOne(`SELECT col1 FROM ${table} WHERE id = 1`);
assert.equal(result, 'bar');
});

it('should use alias parameter', async () => {
const table = 'trx_upsert_update_object_custom_alias';

await ctx.exec(`CREATE TABLE ${table} (id INT PRIMARY KEY, col1 VARCHAR(32))`);
await ctx.transaction(async (trx) => {
await trx.insert(table, { id: 1, col1: 'foo' });
await trx.upsert(
table,
{ id: 1, col1: 'bar' },
{ col1: ctx.raw(`CONCAT(${table}.col1, \`customAlias\`.col1)`) },
'customAlias'
);
});

const value = await ctx.queryOne(`SELECT col1 FROM ${table} WHERE id = 1`);
assert.equal(value, 'foobar');
});
});

describe('#query', () => {
Expand Down

0 comments on commit 4471e91

Please sign in to comment.