Skip to content

Commit

Permalink
fix(sqlite,mysql): avoid get bigint as string in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieuzest committed Apr 17, 2024
1 parent 6a65bfc commit 574ff45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/mysql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Driver.Stats> = { 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
}
Expand Down
13 changes: 7 additions & 6 deletions packages/sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,21 @@ export class SQLiteDriver extends Driver<SQLiteDriver.Config> {
}
}

_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() {
Expand Down Expand Up @@ -303,15 +304,15 @@ export class SQLiteDriver extends Driver<SQLiteDriver.Config> {
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))
}

async eval(sel: Selection.Immutable, expr: Eval.Expr) {
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)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 574ff45

Please sign in to comment.