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>
This commit is contained in:
11 files changed
+136
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildXuguCompileSql, xuguCompileKeyword } from "@/lib/database/xuguCompileSql";
|
||||
|
||||
describe("xuguCompileSql", () => {
|
||||
it.each([
|
||||
["procedure", "PROCEDURE"],
|
||||
["function", "FUNCTION"],
|
||||
["trigger", "TRIGGER"],
|
||||
["package", "PACKAGE"],
|
||||
["package-body", "PACKAGE"],
|
||||
["type", "TYPE"],
|
||||
["type-body", "TYPE"],
|
||||
])("maps %s to %s", (objectType, keyword) => {
|
||||
expect(xuguCompileKeyword(objectType)).toBe(keyword);
|
||||
});
|
||||
|
||||
it("quotes schema and object names while preserving mixed case", () => {
|
||||
expect(buildXuguCompileSql({ objectType: "procedure", schema: "AppSchema", name: "spCreateOrder" })).toBe('ALTER PROCEDURE "AppSchema"."spCreateOrder" RECOMPILE;');
|
||||
});
|
||||
|
||||
it("accepts object-browser uppercase kinds", () => {
|
||||
expect(buildXuguCompileSql({ objectType: "FUNCTION", name: "f_get_count" })).toBe('ALTER FUNCTION "f_get_count" RECOMPILE;');
|
||||
});
|
||||
|
||||
it("escapes embedded double quotes", () => {
|
||||
expect(buildXuguCompileSql({ objectType: "trigger", schema: 'A"Schema', name: 'T"1' })).toBe('ALTER TRIGGER "A""Schema"."T""1" RECOMPILE;');
|
||||
});
|
||||
|
||||
it("returns null for unsupported object kinds or blank names", () => {
|
||||
expect(buildXuguCompileSql({ objectType: "sequence", schema: "SYSDBA", name: "SEQ_1" })).toBeNull();
|
||||
expect(buildXuguCompileSql({ objectType: "procedure", schema: "SYSDBA", name: " " })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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('"', '""')}"`;
|
||||
}
|
||||
Reference in new issue
Block a user