mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-24 07:45:09 +00:00
fix(redis): split multi-line commands before execution
This commit is contained in:
@@ -62,12 +62,18 @@ export function useSqlExecution(deps: {
|
||||
const tab = deps.activeTab.value;
|
||||
const sql = sqlOverride ?? (await resolvedExecutableSql());
|
||||
if (!tab || !sql.trim()) return;
|
||||
// Redis: block dangerous commands when toggle is on
|
||||
// Redis: block dangerous commands when toggle is on (check each line for multi-line input)
|
||||
if (deps.activeConnection.value?.db_type === "redis" && deps.blockDangerousRedisCommands?.value !== false) {
|
||||
const safety = classifyRedisCommandSafety(sql);
|
||||
if (safety === "blocked") {
|
||||
toast(t("redis.blockedCommand", { command: firstRedisCommandToken(sql) }), 5000);
|
||||
return;
|
||||
const commands = sql
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
for (const cmd of commands) {
|
||||
const safety = classifyRedisCommandSafety(cmd);
|
||||
if (safety === "blocked") {
|
||||
toast(t("redis.blockedCommand", { command: firstRedisCommandToken(cmd) }), 5000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isDangerousSql(sql) && settingsStore.editorSettings.confirmDangerousSqlExecution) {
|
||||
|
||||
@@ -1154,18 +1154,42 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const settingsStore = useSettingsStore();
|
||||
await previousResultSessionClose;
|
||||
|
||||
// Redis command execution
|
||||
// Redis command execution — split multi-line input into individual commands
|
||||
if (conn?.db_type === "redis") {
|
||||
await connStore.ensureConnected(tab.connectionId);
|
||||
const redisDb = Number(tab.database) || 0;
|
||||
console.info("[DBX][executeTabSql:redis:start]", { traceId, db: redisDb, sql });
|
||||
const result = await api.redisExecuteCommand(tab.connectionId, redisDb, sql, options?.skipRedisSafetyCheck);
|
||||
console.info("[DBX][executeTabSql:redis:done]", { traceId, elapsed: elapsed() });
|
||||
const commands = sql
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
if (commands.length === 0) return;
|
||||
console.info("[DBX][executeTabSql:redis:start]", { traceId, db: redisDb, commandCount: commands.length, sql });
|
||||
|
||||
const allResults: QueryResult[] = [];
|
||||
const skipSafety = options?.skipRedisSafetyCheck;
|
||||
for (const command of commands) {
|
||||
try {
|
||||
const result = await api.redisExecuteCommand(tab.connectionId, redisDb, command, skipSafety);
|
||||
allResults.push(markQueryResultRowsRaw(redisCommandResultToQueryResult(result.value, performance.now() - startedAt, result.command)));
|
||||
} catch (e: any) {
|
||||
allResults.push({ columns: ["Error"], rows: [[e?.message ?? String(e)]], affected_rows: 0, execution_time_ms: 0 });
|
||||
}
|
||||
}
|
||||
console.info("[DBX][executeTabSql:redis:done]", { traceId, commandCount: commands.length, elapsed: elapsed() });
|
||||
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current?.executionId === executionId) {
|
||||
current.results = undefined;
|
||||
current.activeResultIndex = undefined;
|
||||
current.result = markQueryResultRowsRaw(redisCommandResultToQueryResult(result.value, performance.now() - startedAt, result.command));
|
||||
if (allResults.length > 1) {
|
||||
const activeResultIndex = allResults.findIndex((r) => !r.columns.includes("Error"));
|
||||
const resultIndex = activeResultIndex >= 0 ? activeResultIndex : 0;
|
||||
current.results = allResults;
|
||||
current.activeResultIndex = resultIndex;
|
||||
current.result = allResults[resultIndex];
|
||||
} else {
|
||||
current.results = undefined;
|
||||
current.activeResultIndex = undefined;
|
||||
current.result = allResults[0];
|
||||
}
|
||||
touchResult(current);
|
||||
current.queryAnalysis = undefined;
|
||||
current.querySourceColumns = undefined;
|
||||
|
||||
Reference in New Issue
Block a user