sqlite-analyzer/main.js

50 lines
1020 B
JavaScript
Raw Permalink Normal View History

2023-07-10 05:53:34 +00:00
const sqlite3 = require('sqlite3').verbose();
const sqliteFile = 'sqlite.db';
function getTables() {
return new Promise((resolve, reject) => {
const db = new sqlite3.Database(sqliteFile);
db.all("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC", (err, tables) => {
if (err)
reject(err);
else
resolve(tables.map(r => r.name).sort((a, b) => a.localeCompare(b)));
});
db.close();
});
};
function getColumns(tableName) {
return new Promise((resolve, reject) => {
const db = new sqlite3.Database(sqliteFile);
db.all(`SELECT COUNT(*) NUM FROM ${tableName}`, (err, columns) => {
if (err)
reject(err);
else
resolve(columns[0].num);
});
db.close();
});
}
async function run() {
try {
const tables = await getTables();
for (const table of tables) {
const columns = await getColumns(table);
if (columns > 50000)
console.log(table + '.' + columns);
}
} catch (err) {
console.error(err);
}
}
run();