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。

977 B
Raw Blame
import type { QueryTab } from "@/types/database";

/** Tab fields that decide whether its SQL can be persisted. */
export type SqlTabSaveTarget = Pick<QueryTab, "externalSqlPath" | "savedSqlId" | "sql" | "objectSource">;

/**
 * Whether the tab's SQL can be saved at all.
 *
 * A tab that already has a persistence target — an external `.sql` file or a
 * saved-SQL library entry — stays saveable after its content is emptied.
 * Deleting everything is a legitimate edit that must reach the target, and the
 * emptied state is also the only state in which the user can observe the guard.
 *
 * A brand-new tab has nothing to persist, and an emptied object-source tab would
 * push a body-less `CREATE` for a routine or view to the server, so both keep the
 * content requirement.
 */
export function canSaveSqlTab(tab: SqlTabSaveTarget): boolean {
  if (tab.externalSqlPath || tab.sql.trim()) return true;
  if (tab.objectSource) return false;
  return !!tab.savedSqlId;
}