diff --git a/src/common/customizations/mysql.js b/src/common/customizations/mysql.js index 7496eb62..ff471b34 100644 --- a/src/common/customizations/mysql.js +++ b/src/common/customizations/mysql.js @@ -62,5 +62,6 @@ module.exports = { functionDeterministic: true, functionDataAccess: true, functionSql: 'BEGIN\r\n\r\nEND', - parametersLength: true + parametersLength: true, + readOnlyMode: true }; diff --git a/src/common/customizations/postgresql.js b/src/common/customizations/postgresql.js index 078ce79e..ff67b892 100644 --- a/src/common/customizations/postgresql.js +++ b/src/common/customizations/postgresql.js @@ -54,5 +54,6 @@ module.exports = { triggerTableInName: true, triggerOnlyRename: false, triggerEnableDisable: true, - languages: ['sql', 'plpgsql', 'c', 'internal'] + languages: ['sql', 'plpgsql', 'c', 'internal'], + readOnlyMode: true }; diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index 7d10ce3e..11714301 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -133,8 +133,12 @@ export class MySQLClient extends AntaresCore { } } - if (!this._poolSize) + if (!this._poolSize) { this._connection = await mysql.createConnection(dbConfig); + + if (this._params.readonly) + await this.raw('SET SESSION TRANSACTION READ ONLY'); + } else { this._connection = mysql.createPool({ ...dbConfig, @@ -146,6 +150,12 @@ export class MySQLClient extends AntaresCore { return next(); } }); + + if (this._params.readonly) { + this._connection.on('connection', connection => { + connection.query('SET SESSION TRANSACTION READ ONLY'); + }); + } } } diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 6a68948f..7c2e65fc 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -105,10 +105,19 @@ export class PostgreSQLClient extends AntaresCore { const client = new Client(dbConfig); await client.connect(); this._connection = client; + + if (this._params.readonly) + await this.raw('SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY'); } else { const pool = new Pool({ ...dbConfig, max: this._poolSize }); this._connection = pool; + + if (this._params.readonly) { + this._connection.on('connect', connection => { + connection.query('SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY'); + }); + } } }