feat(sql): add support for @set variables in scripts and copy button

This commit is contained in:
miracle authored and GitHub committed 2026-07-09 00:34:51 +08:00
1 parent 3bc208dbf9
commit 135d4e15db
4 files changed
+414 -5

No files matched your search

@@ -12,6 +12,7 @@ import { sqlMetadataRefreshTarget } from "@/lib/sql/sqlMetadataRefresh";
import { classifyRedisCommandSafety, firstRedisCommandToken } from "@/lib/redis/redisCommandSafety";
import { isSqlExecutionSnapshot, resolveExecutableSql, type SqlExecutionOverride, type SqlExecutionSnapshot } from "@/lib/sql/sqlExecutionTarget";
import { extractSqlParameterDescriptors, type SqlParameterDescriptor } from "@/lib/sql/sqlParameters";
import { expandSqlVariables } from "@/lib/sql/sqlVariables";
import type { ConnectionConfig, DatabaseType, QueryTab } from "@/types/database";
const DANGER_RE = /^\s*(DROP|DELETE|TRUNCATE|ALTER|UPDATE|MERGE|REPLACE)\b/i;
@@ -64,10 +65,10 @@ export function useSqlExecution(deps: {
const sqlParameterDatabaseType = ref<DatabaseType | undefined>();
async function resolvedExecutableSql(source?: SqlExecutionOverride): Promise<string> {
if (typeof source === "string") return source;
if (deps.resolveExecutableSql) return await deps.resolveExecutableSql(source);
if (isSqlExecutionSnapshot(source)) return resolveExecutableSql(source.fullSql, source.selectedSql, { cursorPos: source.cursorPos });
return deps.executableSql.value;
if (typeof source === "string") return expandSqlVariables(source).sql;
if (deps.resolveExecutableSql) return expandSqlVariables(await deps.resolveExecutableSql(source)).sql;
if (isSqlExecutionSnapshot(source)) return expandSqlVariables(resolveExecutableSql(source.fullSql, source.selectedSql, { cursorPos: source.cursorPos })).sql;
return expandSqlVariables(deps.executableSql.value).sql;
}
async function tryExecute(sqlOverride?: SqlExecutionOverride) {