refs #5977 First commit
This commit is contained in:
commit
a7dd647da4
|
@ -0,0 +1,2 @@
|
||||||
|
/node_modules
|
||||||
|
sqlite.db
|
|
@ -0,0 +1,33 @@
|
||||||
|
# sqlite-analyzer
|
||||||
|
This code is a simple SQLite database analyzer that retrieves the names of all tables in a SQLite database file. It then iterates over each table and retrieves the count of columns for each table. If a table has more than 50000 columns, it logs the table name along with the column count to the console.
|
||||||
|
|
||||||
|
## Requeriments
|
||||||
|
|
||||||
|
* Git
|
||||||
|
* Nodejs
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Pull from repository.
|
||||||
|
```
|
||||||
|
$ git clone https://gitea.verdnatura.es/guillermo/sqlite-analyzer.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Run this commands on project root directory to install Node dependencies.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy your database (example.db) into project folder with the name sqlite.db
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
Execute this command in project path.
|
||||||
|
```
|
||||||
|
$ node main
|
||||||
|
```
|
||||||
|
|
||||||
|
## Built With
|
||||||
|
|
||||||
|
* [Git](https://git-scm.com/)
|
||||||
|
* [Nodejs](https://nodejs.org/)
|
|
@ -0,0 +1,49 @@
|
||||||
|
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();
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"sqlite3": "^5.1.6"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue