mirror of https://github.com/Fabio286/antares.git
Merge pull request #143 from Fabio286/feat/read-only-mode-on-connections
feat: read-only mode
This commit is contained in:
commit
fe8435531e
|
@ -62,5 +62,6 @@ module.exports = {
|
|||
functionDeterministic: true,
|
||||
functionDataAccess: true,
|
||||
functionSql: 'BEGIN\r\n\r\nEND',
|
||||
parametersLength: true
|
||||
parametersLength: true,
|
||||
readOnlyMode: true
|
||||
};
|
||||
|
|
|
@ -54,5 +54,6 @@ module.exports = {
|
|||
triggerTableInName: true,
|
||||
triggerOnlyRename: false,
|
||||
triggerEnableDisable: true,
|
||||
languages: ['sql', 'plpgsql', 'c', 'internal']
|
||||
languages: ['sql', 'plpgsql', 'c', 'internal'],
|
||||
readOnlyMode: true
|
||||
};
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue