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/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'); + }); + } } }