mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
readonly support for mysql
This commit is contained in:
parent
4efcef192a
commit
34658e134f
@ -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}`);
|
||||
// }
|
||||
|
@ -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);
|
||||
|
@ -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}
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user