mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +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 { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||
|
||||
pg.types.setTypeParser(1082, 'text', (val) => val); // date
|
||||
pg.types.setTypeParser(1114, 'text', (val) => val); // timestamp without timezone
|
||||
pg.types.setTypeParser(1184, 'text', (val) => val); // timestamp
|
||||
pg.types.setTypeParser(1082, 'text', val => val); // date
|
||||
pg.types.setTypeParser(1114, 'text', val => val); // timestamp without timezone
|
||||
pg.types.setTypeParser(1184, 'text', val => val); // timestamp
|
||||
|
||||
function extractPostgresColumns(result) {
|
||||
if (!result || !result.fields) return [];
|
||||
@ -31,7 +31,7 @@ const drivers = driverBases.map(driverBase => ({
|
||||
...driverBase,
|
||||
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;
|
||||
|
||||
if (engine == 'redshift@dbgate-plugin-postgres') {
|
||||
@ -67,6 +67,11 @@ const drivers = driverBases.map(driverBase => ({
|
||||
|
||||
const client = new pg.Client(options);
|
||||
await client.connect();
|
||||
|
||||
if (isReadOnly) {
|
||||
await this.query(client, 'SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY');
|
||||
}
|
||||
|
||||
return client;
|
||||
},
|
||||
async close(pool) {
|
||||
|
@ -41,15 +41,16 @@ const postgresDriverBase = {
|
||||
// showConnectionField: (field, values) =>
|
||||
// ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
|
||||
getQuerySplitterOptions: () => postgreSplitterOptions,
|
||||
readOnlySessions: true,
|
||||
|
||||
databaseUrlPlaceholder: 'e.g. postgresql://user:password@localhost:5432/default_database',
|
||||
|
||||
showConnectionField: (field, values) => {
|
||||
if (field == 'useDatabaseUrl') return true;
|
||||
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 => {
|
||||
@ -153,7 +154,7 @@ const redshiftDriver = {
|
||||
title: 'Amazon Redshift',
|
||||
defaultPort: 5439,
|
||||
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 => {
|
||||
const { databaseUrl } = connection;
|
||||
if (databaseUrl) {
|
||||
|
Loading…
Reference in New Issue
Block a user