-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-import-ddl.ts
More file actions
35 lines (33 loc) · 1.29 KB
/
altimate-core-import-ddl.ts
File metadata and controls
35 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreImportDdlTool = Tool.define("altimate_core_import_ddl", {
description:
"Convert CREATE TABLE DDL into YAML schema definition. Parses DDL statements and produces a structured schema that other altimate-core tools can consume.",
parameters: z.object({
ddl: z.string().describe("CREATE TABLE DDL statements to parse"),
dialect: z.string().optional().describe("SQL dialect of the DDL"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.import_ddl", {
ddl: args.ddl,
dialect: args.dialect ?? "",
})
const data = result.data as Record<string, any>
return {
title: "Import DDL: done",
metadata: { success: result.success },
output: formatImportDdl(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "Import DDL: ERROR", metadata: { success: false }, output: `Failed: ${msg}` }
}
},
})
function formatImportDdl(data: Record<string, any>): string {
if (data.error) return `Error: ${data.error}`
if (data.schema) return JSON.stringify(data.schema, null, 2)
return JSON.stringify(data, null, 2)
}