mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-30 00:19:35 +00:00
fix(oracle): 简化编辑器选择器并支持 schema 切换 (closes #205)
Oracle/Dameng 连接隐藏多余的 Database 选择器,只显示 Schema 选择器。 查询执行时通过 ALTER SESSION SET CURRENT_SCHEMA 切换 schema 上下文。
This commit is contained in:
@@ -24,6 +24,7 @@ import { useSchemaOptions } from "@/composables/useSchemaOptions";
|
||||
import { connectionIconType } from "@/lib/connectionPresentation";
|
||||
import { isDefaultDatabase } from "@/lib/defaultDatabase";
|
||||
import { connectionDisplayName } from "@/lib/tabPresentation";
|
||||
import { isSingleDatabase } from "@/lib/databaseCapabilities";
|
||||
import { hexToRgba } from "@/lib/color";
|
||||
import type { QueryTab, ConnectionConfig } from "@/types/database";
|
||||
|
||||
@@ -60,16 +61,18 @@ const activeDatabaseOptions = computed(() => {
|
||||
const activeDatabaseValue = computed(() => props.activeTab.database || "");
|
||||
const activeConnectionValue = computed(() => props.activeConnection?.id || "");
|
||||
const activeSchemaValue = computed(() => props.activeTab.schema || "");
|
||||
const isSingleDb = computed(() => isSingleDatabase(props.activeConnection?.db_type));
|
||||
const schemaDatabaseKey = computed(() => props.activeTab.database || (isSingleDb.value ? "_" : ""));
|
||||
|
||||
const showSchemaSelector = computed(() => {
|
||||
const connection = props.activeConnection;
|
||||
return connection && isSchemaAware(connection.id) && props.activeTab.database;
|
||||
return connection && isSchemaAware(connection.id) && (props.activeTab.database || isSingleDb.value);
|
||||
});
|
||||
|
||||
const activeSchemaOptions = computed(() => {
|
||||
const connection = props.activeConnection;
|
||||
if (!connection) return [];
|
||||
return getSchemaOptionsForDb(connection.id, props.activeTab.database);
|
||||
return getSchemaOptionsForDb(connection.id, schemaDatabaseKey.value);
|
||||
});
|
||||
|
||||
const isActiveDatabaseDefault = computed(() => isDefaultDatabase(props.activeConnection, activeDatabaseValue.value));
|
||||
@@ -212,7 +215,7 @@ function databaseDisplayName(database: string): string {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div v-if="activeConnection?.db_type !== 'elasticsearch'" class="flex items-center gap-1">
|
||||
<div v-if="activeConnection?.db_type !== 'elasticsearch' && !isSingleDb" class="flex items-center gap-1">
|
||||
<Database class="h-3.5 w-3.5 shrink-0" />
|
||||
<Select
|
||||
:model-value="activeDatabaseValue"
|
||||
@@ -259,14 +262,14 @@ function databaseDisplayName(database: string): string {
|
||||
@update:model-value="(v: any) => emit('changeSchema', v || undefined)"
|
||||
@update:open="
|
||||
(open: boolean) => {
|
||||
if (open && activeConnection) loadSchemaOptions(activeConnection.id, activeTab.database).catch(() => {});
|
||||
if (open && activeConnection) loadSchemaOptions(activeConnection.id, schemaDatabaseKey).catch(() => {});
|
||||
}
|
||||
"
|
||||
>
|
||||
<SelectTrigger class="h-6 w-auto max-w-56 border-0 bg-transparent px-1 text-xs shadow-none focus:ring-0">
|
||||
<SelectValue
|
||||
:placeholder="
|
||||
activeConnection && isLoadingSchemas(activeConnection.id, activeTab.database)
|
||||
activeConnection && isLoadingSchemas(activeConnection.id, schemaDatabaseKey)
|
||||
? t('common.loading')
|
||||
: t('editor.selectSchema')
|
||||
"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ref } from "vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { isSchemaAware as isSchemaAwareType } from "@/lib/databaseCapabilities";
|
||||
import { isSchemaAware as isSchemaAwareType, isSingleDatabase } from "@/lib/databaseCapabilities";
|
||||
import * as api from "@/lib/api";
|
||||
|
||||
export function useSchemaOptions() {
|
||||
@@ -18,7 +18,9 @@ export function useSchemaOptions() {
|
||||
}
|
||||
|
||||
async function loadSchemaOptions(connectionId: string, database: string) {
|
||||
if (!isSchemaAware(connectionId) || !database) return;
|
||||
if (!isSchemaAware(connectionId)) return;
|
||||
const dbType = connectionStore.getConfig(connectionId)?.db_type;
|
||||
if (!database && !isSingleDatabase(dbType)) return;
|
||||
const key = cacheKey(connectionId, database);
|
||||
if (loadingSchemaOptions.value[key]) return;
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ export const FIELD_LINEAGE_SUPPORTED_TYPES = new Set<DatabaseType>([
|
||||
"gaussdb",
|
||||
]);
|
||||
|
||||
export const SINGLE_DATABASE_TYPES = new Set<DatabaseType>(["oracle", "dameng"]);
|
||||
|
||||
export const FETCH_FIRST_TYPES = new Set<DatabaseType>(["oracle", "dameng"]);
|
||||
|
||||
export const TREE_SCHEMA_TYPES = new Set<DatabaseType>(["postgres", "redshift", "sqlserver", "gaussdb", "jdbc"]);
|
||||
@@ -110,6 +112,10 @@ export function isSchemaAware(dbType?: DatabaseType): boolean {
|
||||
return !!dbType && SCHEMA_AWARE_TYPES.has(dbType);
|
||||
}
|
||||
|
||||
export function isSingleDatabase(dbType?: DatabaseType): boolean {
|
||||
return !!dbType && SINGLE_DATABASE_TYPES.has(dbType);
|
||||
}
|
||||
|
||||
export function usesFetchFirst(dbType?: DatabaseType): boolean {
|
||||
return !!dbType && FETCH_FIRST_TYPES.has(dbType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user