From aa196b67a1744defa940fa7f69cd7e2206f9109e Mon Sep 17 00:00:00 2001 From: Dan Caddigan Date: Sun, 12 Sep 2021 02:13:41 -0400 Subject: [PATCH] fix(typeorm): use limit/offset instead of take/skip --- src/core/BaseService.ts | 4 +- .../__snapshots__/server.test.ts.snap | 119 ++++++++++++++++++ src/test/functional/server.test.ts | 16 ++- 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/src/core/BaseService.ts b/src/core/BaseService.ts index f858eb9b..470f66a2 100644 --- a/src/core/BaseService.ts +++ b/src/core/BaseService.ts @@ -243,10 +243,10 @@ export class BaseService { }; } - qb = qb.take(pageOptions.limit || DEFAULT_LIMIT); + qb = qb.limit(pageOptions.limit || DEFAULT_LIMIT); if (pageOptions.offset) { - qb = qb.skip(pageOptions.offset); + qb = qb.offset(pageOptions.offset); } if (fields) { diff --git a/src/test/functional/__snapshots__/server.test.ts.snap b/src/test/functional/__snapshots__/server.test.ts.snap index cedc7efa..69b6c6dd 100644 --- a/src/test/functional/__snapshots__/server.test.ts.snap +++ b/src/test/functional/__snapshots__/server.test.ts.snap @@ -2911,6 +2911,125 @@ Array [ ] `; +exports[`server find: string query: contains \`A\` (upper or lower) with offset 1`] = ` +Array [ + Object { + "stringField": "AMET QUI", + }, + Object { + "stringField": "maiores praesentium", + }, + Object { + "stringField": "KAELYN", + }, + Object { + "stringField": "alias sint", + }, + Object { + "stringField": "molestiae praesentium", + }, + Object { + "stringField": "Okuneva", + }, + Object { + "stringField": "hartmann", + }, + Object { + "stringField": "raquel", + }, + Object { + "stringField": "quas fugit", + }, + Object { + "stringField": "quia et", + }, + Object { + "stringField": "ut consequatur", + }, + Object { + "stringField": "iusto perspiciatis", + }, + Object { + "stringField": "HAMILL", + }, + Object { + "stringField": "LABORE CULPA", + }, + Object { + "stringField": "VERITATIS EIUS", + }, + Object { + "stringField": "HELGA", + }, + Object { + "stringField": "ipsum voluptas", + }, + Object { + "stringField": "linnea", + }, + Object { + "stringField": "madison", + }, + Object { + "stringField": "NUMQUAM ALIQUAM", + }, + Object { + "stringField": "macy", + }, + Object { + "stringField": "GERLACH", + }, + Object { + "stringField": "padberg", + }, + Object { + "stringField": "ENIM DICTA", + }, + Object { + "stringField": "amalia", + }, + Object { + "stringField": "QUAS PERSPICIATIS", + }, + Object { + "stringField": "Williamson", + }, + Object { + "stringField": "schamberger", + }, + Object { + "stringField": "Jared", + }, + Object { + "stringField": "QUIDEM FUGIAT", + }, + Object { + "stringField": "MAGNAM REICIENDIS", + }, + Object { + "stringField": "jaskolski", + }, + Object { + "stringField": "BAUCH", + }, + Object { + "stringField": "paucek", + }, + Object { + "stringField": "VOLUPTATE ATQUE", + }, + Object { + "stringField": "placeat voluptate", + }, + Object { + "stringField": "pagac", + }, + Object { + "stringField": "eius necessitatibus", + }, +] +`; + exports[`server find: string query: contains \`a\` (upper or lower) 1`] = ` Array [ Object { diff --git a/src/test/functional/server.test.ts b/src/test/functional/server.test.ts index 0d0f6d39..25b514f1 100644 --- a/src/test/functional/server.test.ts +++ b/src/test/functional/server.test.ts @@ -268,6 +268,18 @@ describe('server', () => { expect(result).toMatchSnapshot(); }); + test('find: string query: contains `A` (upper or lower) with offset', async () => { + expect.assertions(2); + + const result = await binding.query.kitchenSinks( + { where: { stringField_contains: 'A' }, limit: 100, offset: 20 }, + '{ stringField }' + ); + + expect(result.length).toEqual(38); + expect(result).toMatchSnapshot(); + }); + test('find: string query: starts with `b` (upper or lower)', async () => { expect.assertions(2); @@ -667,7 +679,9 @@ describe('server', () => { ) ); - expect(result.message).toBe('null value in column "name" violates not-null constraint'); + expect(result.message).toBe( + 'null value in column "name" of relation "dishs" violates not-null constraint' + ); let savedDishes: Dish[] = []; try {