connectors refactor

This commit is contained in:
Jan Prochazka
2020-01-04 21:59:53 +01:00
parent 235ef4764b
commit 948af4984b
12 changed files with 130 additions and 46 deletions

View File

@@ -0,0 +1,22 @@
const { Client } = require('pg');
module.exports = {
async connect({ server, port, user, password }) {
const client = new Client({ host: server, port, user, password, database: 'postgres' });
await client.connect();
return client;
},
async query(client, sql) {
const res = await client.query(sql);
return res.rows;
},
async getVersion(client) {
const rows = await this.query(client, 'SELECT version()');
const { version } = rows[0];
return { version };
},
async listDatabases(client) {
const res = await this.query(client, 'SELECT datname AS name FROM pg_database WHERE datistemplate = false');
return res;
},
};