MCPcopy Create free account
hub / github.com/InsForge/InsForge / analyzeQuery

Function analyzeQuery

backend/src/utils/sql-parser.ts:86–106  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

84};
85
86export function analyzeQuery(query: string): DatabaseResourceUpdate[] {
87 try {
88 const { stmts } = parseSync(query);
89 const changes = stmts
90 .map((s: { stmt: Record<string, unknown> }) => extractChange(s.stmt))
91 .filter((c: DatabaseResourceUpdate | null): c is DatabaseResourceUpdate => c !== null);
92
93 const seen = new Set<string>();
94 return changes.filter((c: DatabaseResourceUpdate) => {
95 const key = `${c.type}:${c.name ?? ''}`;
96 if (seen.has(key)) {
97 return false;
98 }
99 seen.add(key);
100 return true;
101 });
102 } catch (e) {
103 logger.warn('SQL parse error:', e);
104 return [];
105 }
106}
107
108function extractChange(stmt: Record<string, unknown>): DatabaseResourceUpdate | null {
109 const [stmtType, data] = Object.entries(stmt)[0] as [string, Record<string, unknown>];

Callers 3

createMigrationMethod · 0.85
advance.routes.tsFile · 0.85

Calls 1

extractChangeFunction · 0.85

Tested by

no test coverage detected