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('connection-list-changed');
socket.emitChanged('used-apps-changed'); socket.emitChanged('used-apps-changed');
if (this._closeAll) {
this._closeAll(connection._id);
}
// for (const db of connection.databases || []) { // for (const db of connection.databases || []) {
// socket.emitChanged(`db-apps-changed-${connection._id}-${db.name}`); // socket.emitChanged(`db-apps-changed-${connection._id}-${db.name}`);
// } // }

View File

@@ -33,6 +33,10 @@ module.exports = {
closed: {}, closed: {},
requests: {}, requests: {},
async _init() {
connections._closeAll = conid => this.closeAll(conid);
},
handle_structure(conid, database, { structure }) { handle_structure(conid, database, { structure }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database); const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return; if (!existing) return;
@@ -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, disconnect_meta: true,
async disconnect({ conid, database }) { async disconnect({ conid, database }) {
await this.close(conid, database, true); await this.close(conid, database, true);

View File

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

View File

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

View File

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