( filePath: string, content: string )
| 668 | })) as SchemaField[], |
| 669 | relations: (m.relations || []).map((r: any) => |
| 670 | `${r.name}: ${r.type === "many" ? "many" : "one"}(${r.target})` |
| 671 | ), |
| 672 | orm: "django" as const, |
| 673 | confidence: "ast" as const, |
| 674 | })); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Extract SQLModel table models from a Python file using AST. |
| 679 | * Detects class X(SQLModel, table=True) with typed field annotations. |
| 680 | */ |
| 681 | export async function extractSQLModelAST( |
| 682 | filePath: string, |
| 683 | content: string |
| 684 | ): Promise<SchemaModel[] | null> { |
| 685 | const result = await runPythonWithStdin(PYTHON_SQLMODEL_SCRIPT, content, filePath); |
| 686 | if (!result || !Array.isArray(result) || result.length === 0) return null; |
| 687 | |
| 688 | return result.map((m: any) => ({ |
| 689 | name: m.name, |
| 690 | fields: (m.fields || []).map((f: any) => ({ |
| 691 | name: f.name, |
no test coverage detected