Skip to content

Commit

Permalink
fix(sqlite): fix stats() no returns (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifrvn authored Apr 15, 2023
1 parent fbb2248 commit 9d94c78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@minatojs/sql-utils": "^4.0.3",
"@minatojs/sql.js": "^2.0.0",
"@minatojs/sql.js": "^2.0.1",
"cosmokit": "^1.4.1",
"reggol": "^1.3.5"
}
Expand Down
9 changes: 8 additions & 1 deletion packages/sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,14 @@ export class SQLiteDriver extends Driver {
async stats() {
const data = this.db.export()
this.init(data)
return { size: data.byteLength }
const stats: Driver.Stats = { size: data.byteLength, tables: {} }
const tableNames: Array<{ name: string }> = this.#all('SELECT name FROM sqlite_master WHERE type="table" ORDER BY name;')
const dbstats: Array<{ name: string, size: number }> = this.#all('SELECT name, pgsize as size FROM "dbstat" WHERE aggregate=TRUE;')
tableNames.forEach(tbl => {
stats.tables[tbl.name] = this.#get(`SELECT COUNT(*) as count FROM ${escapeId(tbl.name)};`)
stats.tables[tbl.name].size = dbstats.find(o => o.name === tbl.name)!.size
})
return stats
}

async remove(sel: Selection.Mutable) {
Expand Down

0 comments on commit 9d94c78

Please sign in to comment.