feat(PostgreSQL): read-only mode

This commit is contained in:
Fabio Di Stasio 2021-11-24 14:24:52 +01:00
parent 4437d44486
commit 5d48fe08c7
2 changed files with 11 additions and 1 deletions

View File

@ -54,5 +54,6 @@ module.exports = {
triggerTableInName: true,
triggerOnlyRename: false,
triggerEnableDisable: true,
languages: ['sql', 'plpgsql', 'c', 'internal']
languages: ['sql', 'plpgsql', 'c', 'internal'],
readOnlyMode: true
};

View File

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