feat(query): set schema context (search_path) before query execution (#113)
Add schema selector to the editor toolbar for schema-aware databases (PostgreSQL, SQL Server, Oracle). When a schema is selected, the backend sets the appropriate search_path before executing queries so users no longer need to write schema-qualified table names.
This commit is contained in:
1 parent
0d1b99e3ee
commit
b6a39c1fa0
15 files changed
+279
-32
No files matched your search
@@ -0,0 +1,50 @@
|
||||
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";
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user