Files
dbgate/api/src/engines/postgres/index.js
Jan Prochazka 6188e90340 dialect, dumper
2020-02-02 19:27:25 +01:00

32 lines
863 B
JavaScript

const { Client } = require('pg');
/** @type {import('dbgate').SqlDialect} */
const dialect = {
rangeSelect: true,
quoteIdentifier(s) {
return '"' + s + '"';
},
};
module.exports = {
async connect({ server, port, user, password, database }) {
const client = new Client({ host: server, port, user, password, database: database || 'postgres' });
await client.connect();
return client;
},
async query(client, sql) {
const res = await client.query(sql);
return { rows: res.rows };
},
async getVersion(client) {
const { rows } = await this.query(client, 'SELECT version()');
const { version } = rows[0];
return { version };
},
async listDatabases(client) {
const { rows } = await this.query(client, 'SELECT datname AS name FROM pg_database WHERE datistemplate = false');
return rows;
},
dialect,
};