import type { DatabaseType, ObjectSourceKind } from "@/types/database"; import * as api from "@/lib/api"; export type BuildEditableObjectSourceSqlInput = { databaseType: DatabaseType; objectType: ObjectSourceKind; schema?: string | null; name: string; source: string; }; export type BuildRoutineRenameObjectSourceInput = BuildEditableObjectSourceSqlInput & { newName: string; }; export type ObjectSourceSaveExecutionMode = "single" | "script"; const postgresLikeRoutineRenameTypes = new Set([ "postgres", "redshift", "gaussdb", "kingbase", "highgo", "vastbase", ]); const mysqlLikeRoutineRenameTypes = new Set(["mysql", "goldendb"]); const oracleLikeRoutineRenameTypes = new Set(["oracle", "dameng"]); export function supportsSourceBackedRoutineRename( databaseType: DatabaseType | undefined, objectType: ObjectSourceKind, ): boolean { if (objectType !== "FUNCTION" && objectType !== "PROCEDURE") return false; if (!databaseType || databaseType === "sqlserver") return false; return ( mysqlLikeRoutineRenameTypes.has(databaseType) || postgresLikeRoutineRenameTypes.has(databaseType) || oracleLikeRoutineRenameTypes.has(databaseType) ); } export function buildRoutineRenameObjectSourceStatements( input: BuildRoutineRenameObjectSourceInput, ): Promise { return api.buildRoutineRenameObjectSourceStatements(input); } export function buildExecutableObjectSourceStatements(input: BuildEditableObjectSourceSqlInput): Promise { return api.buildExecutableObjectSourceStatements(input); } export async function buildExecutableObjectSourceSql(input: BuildEditableObjectSourceSqlInput): Promise { return api.buildExecutableObjectSourceSql(input); } export function objectSourceSaveExecutionMode(_databaseType: DatabaseType): ObjectSourceSaveExecutionMode { return "single"; }