mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 00:25:38 +00:00
feat(connection): 支持设置默认数据库
统一新建查询的默认数据库选择逻辑,减少重复手动选择。
This commit is contained in:
@@ -264,6 +264,28 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
invalidateCompletionCache(config.id);
|
||||
}
|
||||
|
||||
async function setDefaultDatabase(connectionId: string, database: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config || config.database === database) return;
|
||||
await updateConnection({
|
||||
...config,
|
||||
database,
|
||||
});
|
||||
}
|
||||
|
||||
async function clearDefaultDatabase(connectionId: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config || !config.database) return;
|
||||
await updateConnection({
|
||||
...config,
|
||||
database: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
function isDefaultDatabase(connectionId: string, database: string): boolean {
|
||||
return getConfig(connectionId)?.database === database && database !== "";
|
||||
}
|
||||
|
||||
async function connect(config: ConnectionConfig) {
|
||||
config = normalizeConnection(config);
|
||||
const pendingNode = findNode(treeNodes.value, config.id);
|
||||
@@ -934,6 +956,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
addConnection,
|
||||
addEphemeralConnection,
|
||||
updateConnection,
|
||||
setDefaultDatabase,
|
||||
clearDefaultDatabase,
|
||||
isDefaultDatabase,
|
||||
removeConnection,
|
||||
editingConnectionId,
|
||||
startEditing,
|
||||
|
||||
Reference in New Issue
Block a user