Skip to content

Commit

Permalink
fix(sql): allow no results in em.count()
Browse files Browse the repository at this point in the history
Closes #1135
  • Loading branch information
B4nan committed Dec 2, 2020
1 parent 2f9498f commit bc3cdf6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/knex/src/AbstractSqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export abstract class AbstractSqlDriver<C extends AbstractSqlConnection = Abstra
.where(where);
const res = await this.rethrow(qb.execute('get', false));

return +res.count;
return res ? +res.count : 0;
}

async nativeInsert<T extends AnyEntity<T>>(entityName: string, data: EntityData<T>, ctx?: Transaction<KnexTransaction>, convertCustomTypes = true): Promise<QueryResult> {
Expand Down
3 changes: 3 additions & 0 deletions tests/EntityManager.postgre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ describe('EntityManagerPostgre', () => {
const count = await authorRepository.count();
expect(count).toBe(authors.length);

const count2 = await authorRepository.count({ favouriteBook: '123' }, { groupBy: 'email' });
expect(count2).toBe(0);

// identity map test
authors.shift(); // shift the god away, as that entity is detached from IM
expect(jon).toBe(authors[0]);
Expand Down

0 comments on commit bc3cdf6

Please sign in to comment.