feat(saved-sql): run queries in the current database
This commit is contained in:
1 parent
4062f11a26
commit
e2ba75b102
22 files changed
+501
-51
No files matched your search
+35
-17
@@ -54,7 +54,7 @@ import { isMacOS, isWindows } from "@/lib/backend/platform";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { openQueryResultArchiveFile } from "@/lib/query/queryResultArchiveFile";
|
||||
import { externalSqlFileOpenErrorMessage, readBrowserSqlFile, sqlFileTitleFromPath } from "@/lib/sql/sqlFileOpen";
|
||||
import type { ConnectionConfig, ObjectSourceKind, QueryTab } from "@/types/database";
|
||||
import type { ConnectionConfig, ObjectSourceKind, QueryTab, SavedSqlFile } from "@/types/database";
|
||||
import { parseConnectionDeepLink, type ConnectionDeepLinkDraft } from "@/lib/connection/connectionDeepLink";
|
||||
import {
|
||||
isBrowserReloadShortcut,
|
||||
@@ -92,6 +92,7 @@ import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStor
|
||||
import { apiUrl, webPath } from "@/lib/common/webPath";
|
||||
import { APP_FONT_SANS_CSS_VAR, DATA_GRID_FONT_FAMILY_CSS_VAR, DEFAULT_DATA_GRID_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY } from "@/lib/app/appFonts";
|
||||
import { rankSavedSqlHistory } from "@/lib/savedSql/savedSqlHistory";
|
||||
import { savedSqlDefaultTargetForWrite } from "@/lib/savedSql/savedSqlExecutionTarget";
|
||||
import { countActiveUpdateBlockingTasks } from "@/lib/app/appUpdateTaskGuard";
|
||||
import { initSavedSqlEditorPositions } from "@/lib/app/savedSqlEditorPosition";
|
||||
import { isSchemaAware, isSingleDatabase, usesTreeSchemaMode } from "@/lib/database/databaseFeatureSupport";
|
||||
@@ -826,6 +827,18 @@ async function saveExternalSqlPath(tab: QueryTab, options: { closeAfterSave?: bo
|
||||
}
|
||||
}
|
||||
|
||||
function savedSqlTargetForSave(tab: QueryTab, existing?: SavedSqlFile) {
|
||||
return savedSqlDefaultTargetForWrite(
|
||||
{
|
||||
connectionId: tab.connectionId,
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
catalog: tab.catalog,
|
||||
},
|
||||
existing,
|
||||
);
|
||||
}
|
||||
|
||||
async function saveTabForCloseAll(tabId: string): Promise<boolean> {
|
||||
const tab = queryStore.tabs.find((t) => t.id === tabId);
|
||||
if (!tab) return true;
|
||||
@@ -842,14 +855,15 @@ async function saveTabForCloseAll(tabId: string): Promise<boolean> {
|
||||
if (await saveExternalSqlPath(tab)) return !queryStore.isTabDirty(tab);
|
||||
|
||||
const existing = tab.savedSqlId ? savedSqlStore.getFile(tab.savedSqlId) : undefined;
|
||||
const target = savedSqlTargetForSave(tab, existing);
|
||||
try {
|
||||
const saved = await savedSqlStore.saveFile({
|
||||
id: existing?.id,
|
||||
connectionId: tab.connectionId,
|
||||
connectionId: target.connectionId,
|
||||
folderId: existing?.folderId,
|
||||
name: existing?.name || defaultSavedSqlName(tab.title),
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
database: target.database,
|
||||
schema: target.schema,
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, saved.id, saved.name);
|
||||
@@ -908,13 +922,14 @@ async function handleSaveTab(tabId: string) {
|
||||
}
|
||||
const existing = tab.savedSqlId ? savedSqlStore.getFile(tab.savedSqlId) : undefined;
|
||||
if (existing) {
|
||||
const target = savedSqlTargetForSave(tab, existing);
|
||||
const updated = await savedSqlStore.saveFile({
|
||||
id: existing.id,
|
||||
connectionId: tab.connectionId,
|
||||
connectionId: target.connectionId,
|
||||
folderId: existing.folderId,
|
||||
name: existing.name,
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
database: target.database,
|
||||
schema: target.schema,
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, updated.id, updated.name);
|
||||
@@ -943,13 +958,14 @@ async function openSaveSqlDialog() {
|
||||
if (await saveExternalSqlPath(tab)) return;
|
||||
const existing = tab.savedSqlId ? savedSqlStore.getFile(tab.savedSqlId) : undefined;
|
||||
if (existing) {
|
||||
const target = savedSqlTargetForSave(tab, existing);
|
||||
const updated = await savedSqlStore.saveFile({
|
||||
id: existing.id,
|
||||
connectionId: tab.connectionId,
|
||||
connectionId: target.connectionId,
|
||||
folderId: existing.folderId,
|
||||
name: existing.name,
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
database: target.database,
|
||||
schema: target.schema,
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, updated.id, updated.name);
|
||||
@@ -1036,13 +1052,15 @@ async function confirmSaveSqlToLibrary() {
|
||||
const name = saveSqlName.value.trim();
|
||||
if (!tab || !tab.sql.trim() || !name) return;
|
||||
try {
|
||||
const existing = tab.savedSqlId ? savedSqlStore.getFile(tab.savedSqlId) : undefined;
|
||||
const target = savedSqlTargetForSave(tab, existing);
|
||||
const saved = await savedSqlStore.saveFile({
|
||||
id: tab.savedSqlId,
|
||||
connectionId: tab.connectionId,
|
||||
connectionId: target.connectionId,
|
||||
folderId: saveSqlFolderId.value === ROOT_SAVED_SQL_FOLDER ? undefined : saveSqlFolderId.value,
|
||||
name: defaultSavedSqlName(name),
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
database: target.database,
|
||||
schema: target.schema,
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, saved.id, saved.name);
|
||||
@@ -1384,8 +1402,8 @@ async function openConnectionQuery(connectionId: string) {
|
||||
async function openSavedSqlFromWelcome(fileId: string) {
|
||||
const file = await savedSqlStore.ensureFileContent(fileId);
|
||||
if (!file) return;
|
||||
queryStore.openSavedSql(file);
|
||||
connectionStore.activeConnectionId = file.connectionId;
|
||||
const tabId = queryStore.openSavedSql(file);
|
||||
connectionStore.activeConnectionId = queryStore.tabs.find((tab) => tab.id === tabId)?.connectionId ?? file.connectionId;
|
||||
void savedSqlStore.recordFileUsage(file.id);
|
||||
toast(t("welcome.fileOpened", { name: file.name }), 2000);
|
||||
}
|
||||
@@ -1685,8 +1703,8 @@ async function handleQuickOpenSelect(item: any) {
|
||||
if (item.type === "sql_library_file" && item.sqlFileId) {
|
||||
const file = await savedSqlStore.ensureFileContent(item.sqlFileId);
|
||||
if (!file) return;
|
||||
queryStore.openSavedSql(file);
|
||||
connectionStore.activeConnectionId = file.connectionId;
|
||||
const tabId = queryStore.openSavedSql(file);
|
||||
connectionStore.activeConnectionId = queryStore.tabs.find((tab) => tab.id === tabId)?.connectionId ?? file.connectionId;
|
||||
void savedSqlStore.recordFileUsage(file.id);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user