mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
postgres - readonly connection
This commit is contained in:
parent
8f1d76fd2a
commit
29591a613a
@ -6,9 +6,9 @@ const Analyser = require('./Analyser');
|
|||||||
const pg = require('pg');
|
const pg = require('pg');
|
||||||
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||||
|
|
||||||
pg.types.setTypeParser(1082, 'text', (val) => val); // date
|
pg.types.setTypeParser(1082, 'text', val => val); // date
|
||||||
pg.types.setTypeParser(1114, 'text', (val) => val); // timestamp without timezone
|
pg.types.setTypeParser(1114, 'text', val => val); // timestamp without timezone
|
||||||
pg.types.setTypeParser(1184, 'text', (val) => val); // timestamp
|
pg.types.setTypeParser(1184, 'text', val => val); // timestamp
|
||||||
|
|
||||||
function extractPostgresColumns(result) {
|
function extractPostgresColumns(result) {
|
||||||
if (!result || !result.fields) return [];
|
if (!result || !result.fields) return [];
|
||||||
@ -31,7 +31,7 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
...driverBase,
|
...driverBase,
|
||||||
analyserClass: Analyser,
|
analyserClass: Analyser,
|
||||||
|
|
||||||
async connect({ engine, server, port, user, password, database, databaseUrl, useDatabaseUrl, ssl }) {
|
async connect({ engine, server, port, user, password, database, databaseUrl, useDatabaseUrl, ssl, isReadOnly }) {
|
||||||
let options = null;
|
let options = null;
|
||||||
|
|
||||||
if (engine == 'redshift@dbgate-plugin-postgres') {
|
if (engine == 'redshift@dbgate-plugin-postgres') {
|
||||||
@ -67,6 +67,11 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
|
|
||||||
const client = new pg.Client(options);
|
const client = new pg.Client(options);
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
|
||||||
|
if (isReadOnly) {
|
||||||
|
await this.query(client, 'SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY');
|
||||||
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
},
|
},
|
||||||
async close(pool) {
|
async close(pool) {
|
||||||
|
@ -41,15 +41,16 @@ const postgresDriverBase = {
|
|||||||
// showConnectionField: (field, values) =>
|
// showConnectionField: (field, values) =>
|
||||||
// ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
|
// ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
|
||||||
getQuerySplitterOptions: () => postgreSplitterOptions,
|
getQuerySplitterOptions: () => postgreSplitterOptions,
|
||||||
|
readOnlySessions: true,
|
||||||
|
|
||||||
databaseUrlPlaceholder: 'e.g. postgresql://user:password@localhost:5432/default_database',
|
databaseUrlPlaceholder: 'e.g. postgresql://user:password@localhost:5432/default_database',
|
||||||
|
|
||||||
showConnectionField: (field, values) => {
|
showConnectionField: (field, values) => {
|
||||||
if (field == 'useDatabaseUrl') return true;
|
if (field == 'useDatabaseUrl') return true;
|
||||||
if (values.useDatabaseUrl) {
|
if (values.useDatabaseUrl) {
|
||||||
return ['databaseUrl'].includes(field);
|
return ['databaseUrl', 'isReadOnly'].includes(field);
|
||||||
}
|
}
|
||||||
return ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field);
|
return ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field);
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeConnectionSave: connection => {
|
beforeConnectionSave: connection => {
|
||||||
@ -153,7 +154,7 @@ const redshiftDriver = {
|
|||||||
title: 'Amazon Redshift',
|
title: 'Amazon Redshift',
|
||||||
defaultPort: 5439,
|
defaultPort: 5439,
|
||||||
databaseUrlPlaceholder: 'e.g. redshift-cluster-1.xxxx.redshift.amazonaws.com:5439/dev',
|
databaseUrlPlaceholder: 'e.g. redshift-cluster-1.xxxx.redshift.amazonaws.com:5439/dev',
|
||||||
showConnectionField: (field, values) => ['databaseUrl', 'user', 'password'].includes(field),
|
showConnectionField: (field, values) => ['databaseUrl', 'user', 'password', 'isReadOnly'].includes(field),
|
||||||
beforeConnectionSave: connection => {
|
beforeConnectionSave: connection => {
|
||||||
const { databaseUrl } = connection;
|
const { databaseUrl } = connection;
|
||||||
if (databaseUrl) {
|
if (databaseUrl) {
|
||||||
|
Loading…
Reference in New Issue
Block a user