postgre analyser

This commit is contained in:
Jan Prochazka
2020-02-02 20:28:27 +01:00
parent c0b45a56d8
commit 8f34184818
5 changed files with 134 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
const { Client } = require('pg');
const PostgreAnalyser = require('./PostgreAnalyser');
const PostgreDumper = require('./PostgreDumper');
/** @type {import('dbgate').SqlDialect} */
const dialect = {
@@ -8,7 +10,8 @@ const dialect = {
},
};
module.exports = {
/** @type {import('dbgate').EngineDriver} */
const driver = {
async connect({ server, port, user, password, database }) {
const client = new Client({ host: server, port, user, password, database: database || 'postgres' });
await client.connect();
@@ -16,16 +19,26 @@ module.exports = {
},
async query(client, sql) {
const res = await client.query(sql);
return { rows: res.rows };
return { rows: res.rows, columns: res.fields };
},
async getVersion(client) {
const { rows } = await this.query(client, 'SELECT version()');
const { version } = rows[0];
return { version };
},
async analyseFull(pool) {
const analyser = new PostgreAnalyser(pool, this);
await analyser.runAnalysis();
return analyser.result;
},
createDumper() {
return new PostgreDumper(this);
},
async listDatabases(client) {
const { rows } = await this.query(client, 'SELECT datname AS name FROM pg_database WHERE datistemplate = false');
return rows;
},
dialect,
};
module.exports = driver;