readonly support for mysql

This commit is contained in:
Jan Prochazka 2022-03-17 11:26:38 +01:00
parent 4efcef192a
commit 34658e134f
5 changed files with 23 additions and 3 deletions

View File

@ -199,6 +199,9 @@ module.exports = {
}
socket.emitChanged('connection-list-changed');
socket.emitChanged('used-apps-changed');
if (this._closeAll) {
this._closeAll(connection._id);
}
// for (const db of connection.databases || []) {
// socket.emitChanged(`db-apps-changed-${connection._id}-${db.name}`);
// }

View File

@ -33,6 +33,10 @@ module.exports = {
closed: {},
requests: {},
async _init() {
connections._closeAll = conid => this.closeAll(conid);
},
handle_structure(conid, database, { structure }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return;
@ -158,7 +162,7 @@ module.exports = {
return res.result;
},
async loadDataCore(msgtype, {conid, database, ...args}) {
async loadDataCore(msgtype, { conid, database, ...args }) {
const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype, ...args });
if (res.errorMessage) {
@ -274,6 +278,12 @@ module.exports = {
}
},
closeAll(conid, kill = true) {
for (const existing of this.opened.filter(x => x.conid == conid)) {
this.close(conid, existing.database, kill);
}
},
disconnect_meta: true,
async disconnect({ conid, database }) {
await this.close(conid, database, true);

View File

@ -147,6 +147,10 @@
/>
{/if}
{#if driver.showConnectionField('isReadOnly', $values)}
<FormCheckboxField label="Is read only" name="isReadOnly" />
{/if}
{#if !driver?.showConnectionField || driver.showConnectionField('defaultDatabase', $values)}
<FormTextField label="Default database" name="defaultDatabase" />
{/if}

View File

@ -28,7 +28,7 @@ const drivers = driverBases.map(driverBase => ({
...driverBase,
analyserClass: Analyser,
async connect({ server, port, user, password, database, ssl }) {
async connect({ server, port, user, password, database, ssl, isReadOnly }) {
const connection = mysql2.createConnection({
host: server,
port,
@ -44,6 +44,9 @@ const drivers = driverBases.map(driverBase => ({
// multipleStatements: true,
});
connection._database_name = database;
if (isReadOnly) {
await this.query(connection, 'SET SESSION TRANSACTION READ ONLY');
}
return connection;
},
async close(pool) {

View File

@ -41,7 +41,7 @@ const dialect = {
const mysqlDriverBase = {
...driverBase,
showConnectionField: (field, values) =>
['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field),
dumperClass: Dumper,
dialect,
defaultPort: 3306,