mirror of https://github.com/Fabio286/antares.git
feat(MySQL): read-only mode
This commit is contained in:
parent
9fe3680bbb
commit
4437d44486
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue