Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

6.9 KB
Raw Blame
import type { ConnectionConfig, ObjectBrowserFilter, ObjectBrowserViewport, QueryTab, TabOutputView, TableInfoTab } from "@/types/database";
import type { NavigationTarget } from "@/composables/useNavigationTargets";
import type { DataGridReloadIntent } from "@/lib/dataGrid/dataGridToolbar";
import type { DataGridSortMode } from "@/lib/dataGrid/dataGridSort";
import type { SqlObjectNavigationTarget } from "@/lib/sql/sqlNavigation";
import type { SqlExecutionOverride, SqlExecutionSnapshot } from "@/lib/sql/sqlExecutionTarget";
import type { AiConversationBinding } from "@/lib/ai/aiConversationBinding";
import type { ObjectDependencyTarget } from "@/lib/database/objectDependencyDetails";

export interface StatementRange {
  from: number;
  to: number;
}

export interface QueryEditorSurfaceHandle {
  focusSearch(target?: Element | null): boolean;
  focusWhere(): boolean;
  openGoToColumn(): boolean;
  openTableStructureEditor?(initialTab?: TableInfoTab): boolean;
  refreshData(target?: Element | null): boolean;
  toggleResultsPane(): boolean;
  refreshQueryEditorCompletionCache(): boolean;
  handleModRTarget(target: Element): boolean;
  requestQueryEditorExecute(): boolean;
  requestQueryEditorExecuteAll(): boolean;
  captureQueryEditorExecutionSnapshot(): SqlExecutionSnapshot | undefined;
  requestQueryEditorExecuteInNewResultTab(): boolean;
  requestQueryEditorPreviewChanges(stackSql?: string): Promise<boolean>;
  shouldBlockQueryEditorExecutionShortcut(event: KeyboardEvent): boolean;
  cancelQueryEditorExecutionViewport(requestId: number): boolean;
  acceptQueryEditorExecutionViewport(requestId: number): boolean;
  pasteClipboardAsSqlInCondition(): Promise<boolean>;
  applyTableStructureChanges(): Promise<boolean>;
  /** A Redis logical database is part of the execution target. */
  insertRedisCommand(command: string, target: AiConversationBinding): Promise<boolean>;
  executeRedisCommand(command: string, target: AiConversationBinding): Promise<boolean>;
  /**
   * Whether this surface's Redis console is mounted, on screen, and pointed at
   * `target`. Side-effect free — the AI panel polls it before routing a
   * command, because the console is a lazily-loaded component rendered only for
   * the active tab, and retrying the *command* to detect readiness could run it
   * twice.
   */
  isRedisConsoleReady(target: AiConversationBinding): boolean;
  previewStatementRange(range: StatementRange | null): boolean;
  focusStatementRange(range: StatementRange | null): boolean;
  focusErrorPosition(offset: number): boolean;
  foldAll?(): boolean;
  unfoldAll?(): boolean;
}

export interface QueryResultSurfaceHandle {
  focusSearch(target?: Element | null): boolean;
  refreshData(target?: Element | null): boolean;
  toggleResultsPane(): boolean;
  handleModRTarget(target: Element): boolean;
  previewStatementRange(range: StatementRange | null): boolean;
  focusStatementRange(range: StatementRange | null): boolean;
  focusErrorPosition(offset: number): boolean;
}

export interface ContentAreaSurfaceProps {
  activeTab: QueryTab;
  activeConnection?: ConnectionConfig;
  executableSql: string;
  activeOutputView: TabOutputView;
  formatSqlRequest: { id: number; tabId: string } | null;
  compressSqlRequest: { id: number; tabId: string } | null;
  /** Toolbar `a`/`A`: re-case keywords in the acting tab's editor (issue #11828). */
  keywordCaseRequest: { id: number; tabId: string; mode: "upper" | "lower" } | null;
  selectedSql: string;
  cursorPos: number;
  blockDangerousRedisCommands: boolean;
  zenMode?: boolean;
}

/**
 * Event contract between content surfaces and the workspace/App layer.
 * Every operation that can outlive a focus change — execution, cancellation,
 * result paging, AI hand-off, formatting, view switches — carries the tabId
 * of the tab that originated it, so consumers never have to re-read the
 * global active tab after an await (see redevelopment guide §6.1).
 */
export interface ContentAreaSurfaceEmits {
  closeTab: [tabId: string];
  "locate-tab": [tab: QueryTab];
  "locate-sql-file": [tab: QueryTab];
  "locate-sql-library-file": [tab: QueryTab];
  "update:activeOutputView": [tabId: string, value: TabOutputView];
  fixWithAi: [tabId: string, errorMessage: string];
  sendSelectionToAi: [tabId: string, sql: string];
  previewChangesAvailable: [tabId: string, value: boolean];
  execute: [tabId: string, sqlOverride?: SqlExecutionOverride];
  executeInNewResultTab: [tabId: string, sqlOverride?: SqlExecutionOverride];
  saveSql: [tabId: string];
  cancel: [tabId: string];
  explain: [tabId: string];
  editorUpdate: [tabId: string, value: string];
  editorSelectionChange: [tabId: string, value: string];
  editorCursorChange: [tabId: string, pos: number];
  editorViewportChange: [tabId: string, viewport: { scrollTop: number; scrollLeft: number }];
  editorSelectionStateChange: [tabId: string, selection: { anchor: number; head: number }];
  editorStateFlushed: [tabId: string];
  formatError: [tabId: string];
  reload: [tabId: string, sql?: string, searchText?: string, whereInput?: string, orderBy?: string, limit?: number, offset?: number, intent?: DataGridReloadIntent];
  paginate: [tabId: string, offset: number, limit: number, whereInput?: string, orderBy?: string, appendResult?: boolean];
  sort: [tabId: string, column: string, columnIndex: number, direction: "asc" | "desc" | null, whereInput?: string, mode?: DataGridSortMode, effectiveOrderBy?: string];
  executeSql: [tabId: string, sql: string];
  clickTable: [tabId: string, target: SqlObjectNavigationTarget];
  viewTableData: [tabId: string, target: SqlObjectNavigationTarget];
  viewTableDdl: [tabId: string, target: SqlObjectNavigationTarget];
  editTableStructure: [tabId: string, target: SqlObjectNavigationTarget];
  openObjectSource: [tabId: string, target: SqlObjectNavigationTarget, initialEditing: boolean];
  openDependencyObject: [context: ObjectDependencyTarget, target: SqlObjectNavigationTarget];
  openObjectTable: [tabId: string, target: { tableName: string; schema?: string; tableType?: string; catalog?: string; comment?: string | null }];
  openDatabaseSearchTarget: [tabId: string, target: NavigationTarget];
  objectSchemaChange: [tabId: string, schema: string | undefined];
  objectBrowserViewportChange: [tabId: string, viewport: ObjectBrowserViewport];
  objectBrowserSearchChange: [tabId: string, query: string];
  objectBrowserFilterChange: [tabId: string, filter: ObjectBrowserFilter];
  addObjectTableToAi: [tabId: string, tables: Array<{ name: string; schema?: string }>];
  structureEditorSaved: [tabId: string, commentChanged: boolean, createdTableName?: string];
  structureEditorClose: [tabId: string];
  previewStatement: [tabId: string, range: StatementRange | null];
  focusStatement: [tabId: string, range: StatementRange | null];
  focusErrorOffset: [tabId: string, offset: number];
  openSettings: [initialTab?: string, initialSection?: string];
  openConnectionSettings: [connectionId: string, initialTab: "advanced"];
  toggleZenMode: [];
  toggleResultsPane: [];
}