mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 01:25:59 +00:00
readonly support for mysql
This commit is contained in:
@@ -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}`);
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -158,7 +162,7 @@ module.exports = {
|
|||||||
return res.result;
|
return res.result;
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadDataCore(msgtype, {conid, database, ...args}) {
|
async loadDataCore(msgtype, { conid, database, ...args }) {
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
const res = await this.sendRequest(opened, { msgtype, ...args });
|
const res = await this.sendRequest(opened, { msgtype, ...args });
|
||||||
if (res.errorMessage) {
|
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,
|
disconnect_meta: true,
|
||||||
async disconnect({ conid, database }) {
|
async disconnect({ conid, database }) {
|
||||||
await this.close(conid, database, true);
|
await this.close(conid, database, true);
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user