From 574ff4587220def423ce96638863dfc640f3878c Mon Sep 17 00:00:00 2001 From: Hieuzest Date: Wed, 17 Apr 2024 14:51:08 +0800 Subject: [PATCH] fix(sqlite,mysql): avoid get bigint as string in `stats` --- packages/mysql/src/index.ts | 4 ++-- packages/sqlite/src/index.ts | 13 +++++++------ packages/tests/src/shape.ts | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/mysql/src/index.ts b/packages/mysql/src/index.ts index c07a1be7..d75ee70f 100644 --- a/packages/mysql/src/index.ts +++ b/packages/mysql/src/index.ts @@ -364,8 +364,8 @@ INSERT INTO mtt VALUES(json_extract(j, concat('$[', i, ']'))); SET i=i+1; END WH const data = await this._select('information_schema.tables', ['TABLE_NAME', 'TABLE_ROWS', 'DATA_LENGTH'], 'TABLE_SCHEMA = ?', [this.config.database]) const stats: Partial = { size: 0 } stats.tables = Object.fromEntries(data.map(({ TABLE_NAME: name, TABLE_ROWS: count, DATA_LENGTH: size }) => { - stats.size += size - return [name, { count, size }] + stats.size! += +size + return [name, { count: +count, size: +size }] })) return stats } diff --git a/packages/sqlite/src/index.ts b/packages/sqlite/src/index.ts index 7e10ed15..f61fee26 100644 --- a/packages/sqlite/src/index.ts +++ b/packages/sqlite/src/index.ts @@ -241,20 +241,21 @@ export class SQLiteDriver extends Driver { } } - _all(sql: string, params: any = []) { + _all(sql: string, params: any = [], config?: { useBigInt: boolean }) { return this._exec(sql, params, (stmt) => { stmt.bind(params) const result: any[] = [] while (stmt.step()) { // @ts-ignore - result.push(stmt.getAsObject(null, { useBigInt: true })) + result.push(stmt.getAsObject(null, config)) } return result }) } - _get(sql: string, params: any = []) { - return this._exec(sql, params, stmt => stmt.getAsObject(params)) + _get(sql: string, params: any = [], config?: { useBigInt: boolean }) { + // @ts-ignore + return this._exec(sql, params, stmt => stmt.getAsObject(params, config)) } _export() { @@ -303,7 +304,7 @@ export class SQLiteDriver extends Driver { const builder = new SQLiteBuilder(this, tables) const sql = builder.get(sel) if (!sql) return [] - const rows: any[] = this._all(sql) + const rows: any[] = this._all(sql, [], { useBigInt: true }) return rows.map(row => builder.load(row, model)) } @@ -311,7 +312,7 @@ export class SQLiteDriver extends Driver { const builder = new SQLiteBuilder(this, sel.tables) const inner = builder.get(sel.table as Selection, true, true) const output = builder.parseEval(expr, false) - const { value } = this._get(`SELECT ${output} AS value FROM ${inner}`) + const { value } = this._get(`SELECT ${output} AS value FROM ${inner}`, [], { useBigInt: true }) return builder.load(value, expr) } diff --git a/packages/tests/src/shape.ts b/packages/tests/src/shape.ts index e5ba9352..1a0651b9 100644 --- a/packages/tests/src/shape.ts +++ b/packages/tests/src/shape.ts @@ -38,7 +38,7 @@ function isSubsetOf(subset, superset, cmp, contains, ordered) { }); } -export = (({ Assertion }) => { +export default (({ Assertion }) => { function checkShape(expect, actual, path, ordered) { if (actual === expect || Number.isNaN(expect) && Number.isNaN(actual)) return