Skip to content

Commit

Permalink
fix(core): do not ignore qb.onConflict(...).merge() without params
Browse files Browse the repository at this point in the history
Closes #1774
  • Loading branch information
B4nan committed May 12, 2021
1 parent 61bc7cf commit 68b570e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/knex/src/query/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
Utils.runIfNotEmpty(() => {
const sub2 = sub.merge(item.merge);
Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(this.type, item.where, sub2), item.where);
}, item.merge);
}, 'merge' in item);
});
}, this._onConflict);

Expand Down
13 changes: 13 additions & 0 deletions tests/QueryBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,19 @@ describe('QueryBuilder', () => {

expect(qb1.getQuery()).toEqual('insert into `author2` (`created_at`, `email`, `name`, `updated_at`) values (?, ?, ?, ?) on duplicate key update `name` = ?,`updatedAt` = ?');
expect(qb1.getParams()).toEqual([timestamp, '[email protected]', 'John Doe', timestamp, 'John Doe', timestamp]);

const qb2 = orm.em.createQueryBuilder(Author2)
.insert({
createdAt: timestamp,
email: '[email protected]',
name: 'John Doe',
updatedAt: timestamp,
})
.onConflict('email')
.merge();

expect(qb2.getQuery()).toEqual('insert into `author2` (`created_at`, `email`, `name`, `updated_at`) values (?, ?, ?, ?) on duplicate key update `created_at` = values(`created_at`), `email` = values(`email`), `name` = values(`name`), `updated_at` = values(`updated_at`)');
expect(qb2.getParams()).toEqual([timestamp, '[email protected]', 'John Doe', timestamp]);
});

test('insert many query', async () => {
Expand Down

0 comments on commit 68b570e

Please sign in to comment.