feat(MySQL): read-only mode

This commit is contained in:
Fabio Di Stasio 2021-11-24 13:04:14 +01:00
parent 9fe3680bbb
commit 4437d44486
2 changed files with 13 additions and 2 deletions

View File

@ -62,5 +62,6 @@ module.exports = {
functionDeterministic: true,
functionDataAccess: true,
functionSql: 'BEGIN\r\n\r\nEND',
parametersLength: true
parametersLength: true,
readOnlyMode: true
};

View File

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