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。

1.3 KB
Raw Blame
/**
 * Xugu object kinds that support an explicit recompilation statement.
 * Keep this list intentionally narrow: the caller must still gate the action
 * to Xugu connections so other database dialects are not affected.
 */
const XUGU_COMPILE_KEYWORDS: Record<string, string> = {
  procedure: "PROCEDURE",
  function: "FUNCTION",
  trigger: "TRIGGER",
  package: "PACKAGE",
  "package-body": "PACKAGE",
  type: "TYPE",
  "type-body": "TYPE",
  PROCEDURE: "PROCEDURE",
  FUNCTION: "FUNCTION",
  TRIGGER: "TRIGGER",
  PACKAGE: "PACKAGE",
  PACKAGE_BODY: "PACKAGE",
  TYPE: "TYPE",
  TYPE_BODY: "TYPE",
};

export interface XuguCompileSqlInput {
  objectType: string;
  name: string;
  schema?: string;
}

export function xuguCompileKeyword(objectType: string): string | null {
  return XUGU_COMPILE_KEYWORDS[objectType] ?? null;
}

export function buildXuguCompileSql(input: XuguCompileSqlInput): string | null {
  const keyword = xuguCompileKeyword(input.objectType);
  const name = input.name.trim();
  if (!keyword || !name) return null;
  const qualifiedName = input.schema?.trim() ? `${quoteXuguIdentifier(input.schema.trim())}.${quoteXuguIdentifier(name)}` : quoteXuguIdentifier(name);
  return `ALTER ${keyword} ${qualifiedName} RECOMPILE;`;
}

function quoteXuguIdentifier(name: string): string {
  return `"${name.replaceAll('"', '""')}"`;
}