mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
Redis - ability to skip SETNAME #1077
This commit is contained in:
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -305,6 +305,7 @@ export interface EngineDriver<TClient = any> extends FilterBehaviourProvider {
|
||||
command: 'backup' | 'restore'
|
||||
): { message: string; severity: 'info' | 'error' | 'debug' } | null;
|
||||
getNativeOperationFormArgs(operation: 'backup' | 'restore'): any[];
|
||||
getAdvancedConnectionFields(): any[];
|
||||
|
||||
analyserClass?: any;
|
||||
dumperClass?: any;
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
<script lang="ts">
|
||||
import FormTextField from '../forms/FormTextField.svelte';
|
||||
import { openedConnections, openedSingleDatabaseConnections } from '../stores';
|
||||
import { extensions, openedConnections, openedSingleDatabaseConnections } from '../stores';
|
||||
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
||||
import FormTextAreaField from '../forms/FormTextAreaField.svelte';
|
||||
import FormArgumentList from '../forms/FormArgumentList.svelte';
|
||||
|
||||
const { values } = getFormContext();
|
||||
|
||||
$: engine = $values.engine;
|
||||
|
||||
$: driver = $extensions.drivers.find(x => x.engine == engine);
|
||||
|
||||
$: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
|
||||
|
||||
$: advancedFields = driver?.getAdvancedConnectionFields ? driver?.getAdvancedConnectionFields() : null;
|
||||
</script>
|
||||
|
||||
<FormTextAreaField label="Allowed databases, one per line" name="allowedDatabases" disabled={isConnected} rows={8} />
|
||||
<FormTextField label="Allowed databases regular expression" name="allowedDatabasesRegex" disabled={isConnected} />
|
||||
|
||||
{#if advancedFields}
|
||||
<FormArgumentList args={advancedFields} />
|
||||
{/if}
|
||||
|
||||
@@ -81,12 +81,25 @@ function splitCommandLine(str) {
|
||||
const driver = {
|
||||
...driverBase,
|
||||
analyserClass: Analyser,
|
||||
async connect({ server, port, user, password, database, useDatabaseUrl, databaseUrl, treeKeySeparator, ssl }) {
|
||||
async connect({
|
||||
server,
|
||||
port,
|
||||
user,
|
||||
password,
|
||||
database,
|
||||
useDatabaseUrl,
|
||||
databaseUrl,
|
||||
treeKeySeparator,
|
||||
ssl,
|
||||
skipSetName,
|
||||
}) {
|
||||
let db = 0;
|
||||
let client;
|
||||
if (useDatabaseUrl) {
|
||||
client = new Redis(databaseUrl);
|
||||
await client.client('SETNAME', 'dbgate');
|
||||
if (!skipSetName) {
|
||||
await client.client('SETNAME', 'dbgate');
|
||||
}
|
||||
} else {
|
||||
if (_.isString(database) && database.startsWith('db')) db = parseInt(database.substring(2));
|
||||
if (_.isNumber(database)) db = database;
|
||||
@@ -96,15 +109,18 @@ const driver = {
|
||||
passphrase: ssl.password,
|
||||
};
|
||||
}
|
||||
client = new Redis({
|
||||
const connectionOptions = {
|
||||
host: server,
|
||||
port,
|
||||
username: user,
|
||||
password,
|
||||
db,
|
||||
connectionName: 'dbgate',
|
||||
tls: ssl,
|
||||
});
|
||||
};
|
||||
if (!skipSetName) {
|
||||
connectionOptions.connectionName = 'dbgate';
|
||||
}
|
||||
client = new Redis(connectionOptions);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -82,6 +82,16 @@ const driver = {
|
||||
}
|
||||
return ['server', 'port', 'user', 'password', 'isReadOnly', 'treeKeySeparator'].includes(field);
|
||||
},
|
||||
|
||||
getAdvancedConnectionFields() {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'skipSetName',
|
||||
label: 'Skip SETNAME instruction',
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
|
||||
Reference in New Issue
Block a user