feat(editor): filter schema selector options

This commit is contained in:
t8y2 committed 2026-06-24 22:12:32 +08:00
1 parent 35af7ac721
commit 15546387db
2 files changed
+32 -2

No files matched your search

@@ -1,12 +1,18 @@
import { ref } from "vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities";
import { filterDatabaseNamesForConnection } from "@/lib/visibleDatabases";
import type { ConnectionConfig } from "@/types/database";
import * as api from "@/lib/api";
export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, key: string): boolean {
return Object.prototype.hasOwnProperty.call(options, key);
}
export function schemaOptionsForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "driver_profile" | "visible_databases"> | undefined): string[] {
return filterDatabaseNamesForConnection(schemaNames, connection);
}
export function useSchemaOptions() {
const connectionStore = useConnectionStore();
@@ -23,7 +29,8 @@ export function useSchemaOptions() {
async function loadSchemaOptions(connectionId: string, database: string) {
if (!isSchemaAware(connectionId)) return;
const dbType = connectionStore.getConfig(connectionId)?.db_type;
const connection = connectionStore.getConfig(connectionId);
const dbType = connection?.db_type;
if (!database && !isSingleDatabase(dbType) && !usesTreeSchemaMode(dbType)) return;
const key = cacheKey(connectionId, database);
if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return;
@@ -32,7 +39,7 @@ export function useSchemaOptions() {
loadingSchemaOptions.value[key] = true;
try {
await connectionStore.ensureConnected(connectionId);
schemaOptions.value[key] = await api.listSchemas(connectionId, database);
schemaOptions.value[key] = schemaOptionsForConnection(await api.listSchemas(connectionId, database), connection);
} catch (e) {
schemaOptions.value[key] = [];
throw e;