diff --git a/package-lock.json b/package-lock.json index d40f88f..831a20a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "workers-qb", - "version": "1.6.2", + "version": "1.6.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "workers-qb", - "version": "1.6.2", + "version": "1.6.3", "license": "MIT", "devDependencies": { "@cloudflare/workers-types": "^4.20240815.0", diff --git a/package.json b/package.json index eb0d327..7b226de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "workers-qb", - "version": "1.6.2", + "version": "1.6.3", "description": "Zero dependencies Query Builder for Cloudflare Workers", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/builder.ts b/src/builder.ts index e26e6e5..1c0f8cb 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -111,6 +111,7 @@ export class QueryBuilder ...params, fields: 'count(*) as total', offset: undefined, + groupBy: undefined, limit: 1, }), typeof params.where === 'object' && !Array.isArray(params.where) && params.where?.params @@ -134,6 +135,7 @@ export class QueryBuilder ...params, fields: 'count(*) as total', offset: undefined, + groupBy: undefined, limit: 1, }), typeof params.where === 'object' && !Array.isArray(params.where) && params.where?.params diff --git a/tests/builder/select.test.ts b/tests/builder/select.test.ts index 00e5fc9..771c20d 100644 --- a/tests/builder/select.test.ts +++ b/tests/builder/select.test.ts @@ -160,6 +160,22 @@ describe('Select Builder', () => { } }) + test('count should remove group by', async () => { + for (const result of [ + await new QuerybuilderTest() + .fetchAll({ + tableName: 'testTable', + offset: 4, + groupBy: ['field'], + }) + .count(), + ]) { + expect((result.results as any).query).toEqual('SELECT count(*) as total FROM testTable LIMIT 1') + expect((result.results as any).arguments).toEqual(undefined) + expect((result.results as any).fetchType).toEqual('ONE') + } + }) + test('select with simplified where list', async () => { for (const result of [ new QuerybuilderTest().fetchOne({