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,
|
functionDeterministic: true,
|
||||||
functionDataAccess: true,
|
functionDataAccess: true,
|
||||||
functionSql: 'BEGIN\r\n\r\nEND',
|
functionSql: 'BEGIN\r\n\r\nEND',
|
||||||
parametersLength: true
|
parametersLength: true,
|
||||||
|
readOnlyMode: true
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,5 +54,6 @@ module.exports = {
|
||||||
triggerTableInName: true,
|
triggerTableInName: true,
|
||||||
triggerOnlyRename: false,
|
triggerOnlyRename: false,
|
||||||
triggerEnableDisable: true,
|
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);
|
this._connection = await mysql.createConnection(dbConfig);
|
||||||
|
|
||||||
|
if (this._params.readonly)
|
||||||
|
await this.raw('SET SESSION TRANSACTION READ ONLY');
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this._connection = mysql.createPool({
|
this._connection = mysql.createPool({
|
||||||
...dbConfig,
|
...dbConfig,
|
||||||
|
@ -146,6 +150,12 @@ export class MySQLClient extends AntaresCore {
|
||||||
return next();
|
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);
|
const client = new Client(dbConfig);
|
||||||
await client.connect();
|
await client.connect();
|
||||||
this._connection = client;
|
this._connection = client;
|
||||||
|
|
||||||
|
if (this._params.readonly)
|
||||||
|
await this.raw('SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const pool = new Pool({ ...dbConfig, max: this._poolSize });
|
const pool = new Pool({ ...dbConfig, max: this._poolSize });
|
||||||
this._connection = pool;
|
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