mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 08:11:06 +00:00
- Add GaussDB/openGauss support via ODBC (resolves #106) - Use pg_catalog queries instead of information_schema for compatibility - Share ODBC environment across drivers with auto ODBCSYSINI detection - Fix ODBC error message false positive on "Driver" keyword match - Merge connection dialog categories into a single flat list - Remove duplicate DDL button from data grid footer
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { ref } from "vue";
|
|
import { useConnectionStore } from "@/stores/connectionStore";
|
|
import * as api from "@/lib/api";
|
|
|
|
export function useSchemaOptions() {
|
|
const connectionStore = useConnectionStore();
|
|
|
|
const schemaOptions = ref<Record<string, string[]>>({});
|
|
const loadingSchemaOptions = ref<Record<string, boolean>>({});
|
|
|
|
function cacheKey(connectionId: string, database: string) {
|
|
return `${connectionId}:${database}`;
|
|
}
|
|
|
|
function isSchemaAware(connectionId: string): boolean {
|
|
const dbType = connectionStore.getConfig(connectionId)?.db_type;
|
|
return (
|
|
dbType === "postgres" ||
|
|
dbType === "sqlserver" ||
|
|
dbType === "oracle" ||
|
|
dbType === "dameng" ||
|
|
dbType === "gaussdb"
|
|
);
|
|
}
|
|
|
|
async function loadSchemaOptions(connectionId: string, database: string) {
|
|
if (!isSchemaAware(connectionId) || !database) return;
|
|
const key = cacheKey(connectionId, database);
|
|
if (loadingSchemaOptions.value[key]) return;
|
|
|
|
loadingSchemaOptions.value[key] = true;
|
|
try {
|
|
await connectionStore.ensureConnected(connectionId);
|
|
schemaOptions.value[key] = await api.listSchemas(connectionId, database);
|
|
} finally {
|
|
loadingSchemaOptions.value[key] = false;
|
|
}
|
|
}
|
|
|
|
function getSchemaOptionsForDb(connectionId: string, database: string): string[] {
|
|
return schemaOptions.value[cacheKey(connectionId, database)] ?? [];
|
|
}
|
|
|
|
function isLoadingSchemas(connectionId: string, database: string): boolean {
|
|
return !!loadingSchemaOptions.value[cacheKey(connectionId, database)];
|
|
}
|
|
|
|
return {
|
|
schemaOptions,
|
|
loadingSchemaOptions,
|
|
loadSchemaOptions,
|
|
getSchemaOptionsForDb,
|
|
isLoadingSchemas,
|
|
isSchemaAware,
|
|
};
|
|
}
|