mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 02:06:01 +00:00
32 lines
863 B
JavaScript
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,
|
|
};
|