mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 05:36:00 +00:00
connectors refactor
This commit is contained in:
22
api/src/engines/postgres/index.js
Normal file
22
api/src/engines/postgres/index.js
Normal 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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user