Files
dbx/apps/desktop/src/lib/database/xuguCompileSql.ts
T
352403d79e feat(xugu): add programmable object compile actions
* feat(xugu): add programmable object compile actions

* chore(i18n): autofill new translations

---------

Co-authored-by: mapan <pan.anarkh1994@gmail.com>
Co-authored-by: dbx-i18n-bot <github-actions[bot]@users.noreply.github.com>
2026-08-07 03:30:52 +08:00

44 lines
1.3 KiB
TypeScript

/**
* 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('"', '""')}"`;
}