From af060ade648d7d8be63d6684486f613e51d68e2c Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Mon, 11 May 2026 14:08:33 -0300 Subject: [PATCH] feat: clear select on aggregates --- package-lock.json | 4 +- package.json | 2 +- src/database/builders/QueryBuilder.ts | 12 +-- src/database/drivers/BaseKnexDriver.ts | 40 ++++---- src/database/drivers/Driver.ts | 12 +-- src/database/drivers/FakeDriver.ts | 24 ++--- src/database/drivers/MongoDriver.ts | 24 ++--- src/models/builders/ModelQueryBuilder.ts | 12 +-- tests/unit/drivers/MySqlDriverTest.ts | 96 +++++++++++++++++++ tests/unit/drivers/PostgresDriverTest.ts | 96 +++++++++++++++++++ tests/unit/drivers/SqliteDriverTest.ts | 96 +++++++++++++++++++ .../models/builders/ModelQueryBuilderTest.ts | 24 ++--- 12 files changed, 365 insertions(+), 77 deletions(-) diff --git a/package-lock.json b/package-lock.json index 486362f..a283e3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/database", - "version": "5.51.0", + "version": "5.52.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/database", - "version": "5.51.0", + "version": "5.52.0", "license": "MIT", "dependencies": { "@faker-js/faker": "^8.4.1" diff --git a/package.json b/package.json index 45db16a..3998ae6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/database", - "version": "5.51.0", + "version": "5.52.0", "description": "The Athenna database handler for SQL/NoSQL.", "license": "MIT", "author": "João Lenon ", diff --git a/src/database/builders/QueryBuilder.ts b/src/database/builders/QueryBuilder.ts index e797cd1..161d639 100644 --- a/src/database/builders/QueryBuilder.ts +++ b/src/database/builders/QueryBuilder.ts @@ -94,42 +94,42 @@ export class QueryBuilder< /** * Calculate the average of a given column. */ - public async avg(column: string | ModelColumns): Promise { + public async avg(column: string | ModelColumns): Promise { return this.driver.avg(column as string) } /** * Calculate the average of a given column. */ - public async avgDistinct(column: string | ModelColumns): Promise { + public async avgDistinct(column: string | ModelColumns): Promise { return this.driver.avgDistinct(column as string) } /** * Get the max number of a given column. */ - public async max(column: string | ModelColumns): Promise { + public async max(column: string | ModelColumns): Promise { return this.driver.max(column as string) } /** * Get the min number of a given column. */ - public async min(column: string | ModelColumns): Promise { + public async min(column: string | ModelColumns): Promise { return this.driver.min(column as string) } /** * Sum all numbers of a given column. */ - public async sum(column: string | ModelColumns): Promise { + public async sum(column: string | ModelColumns): Promise { return this.driver.sum(column as string) } /** * Sum all numbers of a given column. */ - public async sumDistinct(column: string | ModelColumns): Promise { + public async sumDistinct(column: string | ModelColumns): Promise { return this.driver.sumDistinct(column as string) } diff --git a/src/database/drivers/BaseKnexDriver.ts b/src/database/drivers/BaseKnexDriver.ts index 37e0f97..7bbadc5 100644 --- a/src/database/drivers/BaseKnexDriver.ts +++ b/src/database/drivers/BaseKnexDriver.ts @@ -302,55 +302,55 @@ export class BaseKnexDriver extends Driver { /** * Calculate the average of a given column. */ - public async avg(column: string): Promise { - const [{ avg }] = await this.qb.avg({ avg: column }) + public async avg(column: string): Promise { + const [{ avg }] = await this.qb.clearSelect().avg({ avg: column }) - return avg + return avg == null ? null : Number(avg) } /** * Calculate the average of a given column using distinct. */ - public async avgDistinct(column: string): Promise { - const [{ avg }] = await this.qb.avgDistinct({ avg: column }) + public async avgDistinct(column: string): Promise { + const [{ avg }] = await this.qb.clearSelect().avgDistinct({ avg: column }) - return avg + return avg == null ? null : Number(avg) } /** * Get the max number of a given column. */ - public async max(column: string): Promise { - const [{ max }] = await this.qb.max({ max: column }) + public async max(column: string): Promise { + const [{ max }] = await this.qb.clearSelect().max({ max: column }) - return max + return max == null ? null : Number(max) } /** * Get the min number of a given column. */ - public async min(column: string): Promise { - const [{ min }] = await this.qb.min({ min: column }) + public async min(column: string): Promise { + const [{ min }] = await this.qb.clearSelect().min({ min: column }) - return min + return min == null ? null : Number(min) } /** * Sum all numbers of a given column. */ - public async sum(column: string): Promise { - const [{ sum }] = await this.qb.sum({ sum: column }) + public async sum(column: string): Promise { + const [{ sum }] = await this.qb.clearSelect().sum({ sum: column }) - return sum + return sum == null ? null : Number(sum) } /** * Sum all numbers of a given column in distinct mode. */ - public async sumDistinct(column: string): Promise { - const [{ sum }] = await this.qb.sumDistinct({ sum: column }) + public async sumDistinct(column: string): Promise { + const [{ sum }] = await this.qb.clearSelect().sumDistinct({ sum: column }) - return sum + return sum == null ? null : Number(sum) } /** @@ -371,7 +371,7 @@ export class BaseKnexDriver extends Driver { * Calculate the average of a given column using distinct. */ public async count(column: string = '*'): Promise { - const [{ count }] = await this.qb.count({ count: column }) + const [{ count }] = await this.qb.clearSelect().count({ count: column }) return Number(count) } @@ -380,7 +380,7 @@ export class BaseKnexDriver extends Driver { * Calculate the average of a given column using distinct. */ public async countDistinct(column: string): Promise { - const [{ count }] = await this.qb.countDistinct({ count: column }) + const [{ count }] = await this.qb.clearSelect().countDistinct({ count: column }) return Number(count) } diff --git a/src/database/drivers/Driver.ts b/src/database/drivers/Driver.ts index edc9991..dd451a9 100644 --- a/src/database/drivers/Driver.ts +++ b/src/database/drivers/Driver.ts @@ -365,32 +365,32 @@ export abstract class Driver { /** * Calculate the average of a given column. */ - public abstract avg(column: string): Promise + public abstract avg(column: string): Promise /** * Calculate the average of a given column using distinct. */ - public abstract avgDistinct(column: string): Promise + public abstract avgDistinct(column: string): Promise /** * Get the max number of a given column. */ - public abstract max(column: string): Promise + public abstract max(column: string): Promise /** * Get the min number of a given column. */ - public abstract min(column: string): Promise + public abstract min(column: string): Promise /** * Sum all numbers of a given column. */ - public abstract sum(column: string): Promise + public abstract sum(column: string): Promise /** * Sum all numbers of a given column in distinct mode. */ - public abstract sumDistinct(column: string): Promise + public abstract sumDistinct(column: string): Promise /** * Increment a value of a given column. diff --git a/src/database/drivers/FakeDriver.ts b/src/database/drivers/FakeDriver.ts index 9fdb54c..6db49e3 100644 --- a/src/database/drivers/FakeDriver.ts +++ b/src/database/drivers/FakeDriver.ts @@ -265,43 +265,43 @@ export class FakeDriver { /** * Calculate the average of a given column. */ - public static async avg() { - return '1' + public static async avg(): Promise { + return 1 } /** * Calculate the average of a given column using distinct. */ - public static async avgDistinct() { - return '1' + public static async avgDistinct(): Promise { + return 1 } /** * Get the max number of a given column. */ - public static async max() { - return '1' + public static async max(): Promise { + return 1 } /** * Get the min number of a given column. */ - public static async min(): Promise { - return '1' + public static async min(): Promise { + return 1 } /** * Sum all numbers of a given column. */ - public static async sum(): Promise { - return '1' + public static async sum(): Promise { + return 1 } /** * Sum all numbers of a given column in distinct mode. */ - public static async sumDistinct(): Promise { - return '1' + public static async sumDistinct(): Promise { + return 1 } /** diff --git a/src/database/drivers/MongoDriver.ts b/src/database/drivers/MongoDriver.ts index cbb5d85..8d3b68e 100644 --- a/src/database/drivers/MongoDriver.ts +++ b/src/database/drivers/MongoDriver.ts @@ -377,7 +377,7 @@ export class MongoDriver extends Driver { /** * Calculate the average of a given column. */ - public async avg(column: string): Promise { + public async avg(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -395,13 +395,13 @@ export class MongoDriver extends Driver { return null } - return `${result[0].avg}` + return Number(result[0].avg) } /** * Calculate the average of a given column using distinct. */ - public async avgDistinct(column: string): Promise { + public async avgDistinct(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -419,13 +419,13 @@ export class MongoDriver extends Driver { return null } - return `${result[0].avg}` + return Number(result[0].avg) } /** * Get the max number of a given column. */ - public async max(column: string): Promise { + public async max(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -443,13 +443,13 @@ export class MongoDriver extends Driver { return null } - return `${result[0].max}` + return Number(result[0].max) } /** * Get the min number of a given column. */ - public async min(column: string): Promise { + public async min(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -467,13 +467,13 @@ export class MongoDriver extends Driver { return null } - return `${result[0].min}` + return Number(result[0].min) } /** * Sum all numbers of a given column. */ - public async sum(column: string): Promise { + public async sum(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -491,13 +491,13 @@ export class MongoDriver extends Driver { return null } - return `${result[0].sum}` + return Number(result[0].sum) } /** * Sum all numbers of a given column in distinct mode. */ - public async sumDistinct(column: string): Promise { + public async sumDistinct(column: string): Promise { await this.client.asPromise() const pipeline = this.createPipeline() @@ -515,7 +515,7 @@ export class MongoDriver extends Driver { return null } - return `${result[0].sum}` + return Number(result[0].sum) } /** diff --git a/src/models/builders/ModelQueryBuilder.ts b/src/models/builders/ModelQueryBuilder.ts index 19fc344..06e049b 100644 --- a/src/models/builders/ModelQueryBuilder.ts +++ b/src/models/builders/ModelQueryBuilder.ts @@ -93,7 +93,7 @@ export class ModelQueryBuilder< /** * Calculate the average of a given column. */ - public async avg(column: ModelColumns): Promise { + public async avg(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) @@ -104,7 +104,7 @@ export class ModelQueryBuilder< /** * Calculate the average of a given column. */ - public async avgDistinct(column: ModelColumns): Promise { + public async avgDistinct(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) @@ -115,7 +115,7 @@ export class ModelQueryBuilder< /** * Get the max number of a given column. */ - public async max(column: ModelColumns): Promise { + public async max(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) @@ -126,7 +126,7 @@ export class ModelQueryBuilder< /** * Get the min number of a given column. */ - public async min(column: ModelColumns): Promise { + public async min(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) @@ -137,7 +137,7 @@ export class ModelQueryBuilder< /** * Sum all numbers of a given column. */ - public async sum(column: ModelColumns): Promise { + public async sum(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) @@ -148,7 +148,7 @@ export class ModelQueryBuilder< /** * Sum all numbers of a given column. */ - public async sumDistinct(column: ModelColumns): Promise { + public async sumDistinct(column: ModelColumns): Promise { this.setInternalQueries() const name = this.schema.getColumnNameByProperty(column) diff --git a/tests/unit/drivers/MySqlDriverTest.ts b/tests/unit/drivers/MySqlDriverTest.ts index 07f5667..01b6c6f 100644 --- a/tests/unit/drivers/MySqlDriverTest.ts +++ b/tests/unit/drivers/MySqlDriverTest.ts @@ -615,6 +615,102 @@ export default class MySqlDriverTest { assert.equal(result, 1) } + @Test() + public async shouldBeAbleToGetAvgWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avg('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetAvgDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avgDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetMaxWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').max('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetMinWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').min('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetSumWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sum('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetSumDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sumDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToCountWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').count() + + assert.equal(result, 2) + } + + @Test() + public async shouldBeAbleToCountDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').countDistinct('quantity') + + assert.equal(result, 1) + } + @Test() public async shouldBeAbleToFindDataUsingFindOrFail({ assert }: Context) { const data = { id: '1', name: 'John Doe' } diff --git a/tests/unit/drivers/PostgresDriverTest.ts b/tests/unit/drivers/PostgresDriverTest.ts index 1ba4f4e..c4b580e 100644 --- a/tests/unit/drivers/PostgresDriverTest.ts +++ b/tests/unit/drivers/PostgresDriverTest.ts @@ -614,6 +614,102 @@ export default class PostgresDriverTest { assert.equal(result, 1) } + @Test() + public async shouldBeAbleToGetAvgWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avg('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetAvgDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avgDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetMaxWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').max('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetMinWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').min('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetSumWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sum('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetSumDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sumDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToCountWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').count() + + assert.equal(result, 2) + } + + @Test() + public async shouldBeAbleToCountDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').countDistinct('quantity') + + assert.equal(result, 1) + } + @Test() public async shouldBeAbleToFindDataUsingFindOrFail({ assert }: Context) { const data = { id: '1', name: 'John Doe' } diff --git a/tests/unit/drivers/SqliteDriverTest.ts b/tests/unit/drivers/SqliteDriverTest.ts index ddfe1cd..7da26e0 100644 --- a/tests/unit/drivers/SqliteDriverTest.ts +++ b/tests/unit/drivers/SqliteDriverTest.ts @@ -616,6 +616,102 @@ export default class SqliteDriverTest { assert.equal(result, 1) } + @Test() + public async shouldBeAbleToGetAvgWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avg('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetAvgDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').avgDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetMaxWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').max('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetMinWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 20 } + ]) + + const result = await this.driver.table('products').select('*').min('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToGetSumWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sum('quantity') + + assert.equal(result, 20) + } + + @Test() + public async shouldBeAbleToGetSumDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').sumDistinct('quantity') + + assert.equal(result, 10) + } + + @Test() + public async shouldBeAbleToCountWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').count() + + assert.equal(result, 2) + } + + @Test() + public async shouldBeAbleToCountDistinctWithPreSelectedColumns({ assert }: Context) { + await this.driver.table('products').createMany([ + { id: '1', quantity: 10 }, + { id: '2', quantity: 10 } + ]) + + const result = await this.driver.table('products').select('*').countDistinct('quantity') + + assert.equal(result, 1) + } + @Test() public async shouldBeAbleToFindDataUsingFindOrFail({ assert }: Context) { const data = { id: '1', name: 'John Doe' } diff --git a/tests/unit/models/builders/ModelQueryBuilderTest.ts b/tests/unit/models/builders/ModelQueryBuilderTest.ts index bc6def7..4e3469f 100644 --- a/tests/unit/models/builders/ModelQueryBuilderTest.ts +++ b/tests/unit/models/builders/ModelQueryBuilderTest.ts @@ -50,7 +50,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheAvgOfAGivenColumn({ assert }: Context) { - const fakeAvg = '200' + const fakeAvg = 200 Mock.when(Database.driver, 'avg').resolve(fakeAvg) const result = await User.query().avg('score') @@ -61,7 +61,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheAvgDistinctOfAGivenColumn({ assert }: Context) { - const fakeAvg = '200' + const fakeAvg = 200 Mock.when(Database.driver, 'avgDistinct').resolve(fakeAvg) const result = await User.query().avgDistinct('score') @@ -72,7 +72,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheAvgOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeAvg = '200' + const fakeAvg = 200 Mock.when(Database.driver, 'avg').resolve(fakeAvg) const result = await User.query().avg('rate') @@ -83,7 +83,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheAvgDistinctOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeAvg = '200' + const fakeAvg = 200 Mock.when(Database.driver, 'avgDistinct').resolve(fakeAvg) const result = await User.query().avgDistinct('rate') @@ -94,7 +94,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheMaxNumberOfAGivenColumn({ assert }: Context) { - const fakeMax = '200' + const fakeMax = 200 Mock.when(Database.driver, 'max').resolve(fakeMax) const result = await User.query().max('score') @@ -105,7 +105,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheMinNumberOfAGivenColumn({ assert }: Context) { - const fakeMin = '10' + const fakeMin = 10 Mock.when(Database.driver, 'min').resolve(fakeMin) const result = await User.query().min('score') @@ -116,7 +116,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheMaxNumberOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeMax = '200' + const fakeMax = 200 Mock.when(Database.driver, 'max').resolve(fakeMax) const result = await User.query().max('rate') @@ -127,7 +127,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToGetTheMinNumberOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeMin = '10' + const fakeMin = 10 Mock.when(Database.driver, 'min').resolve(fakeMin) const result = await User.query().min('rate') @@ -138,7 +138,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToSumAllNumbersOfAGivenColumn({ assert }: Context) { - const fakeSum = '1000' + const fakeSum = 1000 Mock.when(Database.driver, 'sum').resolve(fakeSum) const result = await User.query().sum('score') @@ -149,7 +149,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToSumDistinctValuesOfAGivenColumn({ assert }: Context) { - const fakeSumDistinct = '900' + const fakeSumDistinct = 900 Mock.when(Database.driver, 'sumDistinct').resolve(fakeSumDistinct) const result = await User.query().sumDistinct('score') @@ -160,7 +160,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToSumAllNumbersOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeSum = '1000' + const fakeSum = 1000 Mock.when(Database.driver, 'sum').resolve(fakeSum) const result = await User.query().sum('rate') @@ -171,7 +171,7 @@ export default class ModelQueryBuilderTest { @Test() public async shouldBeAbleToSumDistinctValuesOfAGivenColumnParsingColumnName({ assert }: Context) { - const fakeSumDistinct = '900' + const fakeSumDistinct = 900 Mock.when(Database.driver, 'sumDistinct').resolve(fakeSumDistinct) const result = await User.query().sumDistinct('rate')