import { joinExportedDdls } from "@/lib/export/ddlExport"; interface SidebarDdlExecutionTarget { connectionId: string; database: string; catalog?: string; } export function sidebarDdlTargetsForExecutionContext(activeTarget: SidebarDdlExecutionTarget, targets: readonly T[]): T[] { return targets.filter((target) => target.connectionId === activeTarget.connectionId && target.database === activeTarget.database && (target.catalog ?? "") === (activeTarget.catalog ?? "")); } export async function buildSidebarDdlTemplateSql(targets: readonly T[], loadDdl: (target: T) => Promise, formatDdl: (ddl: string, target: T) => Promise): Promise { const parts: string[] = []; for (const target of targets) { parts.push(await formatDdl(await loadDdl(target), target)); } return parts.length === 1 ? parts[0]! : joinExportedDdls(parts); }