MCPcopy Index your code
hub / github.com/BuilderIO/agent-native / parseStatements

Function parseStatements

packages/core/src/scripts/db/exec.ts:56–95  ·  view source on GitHub ↗
(parsed: Record<string, string>)

Source from the content-addressed store, hash-verified

54}
55
56function parseStatements(parsed: Record<string, string>): DbExecStatement[] {
57 if (parsed.statements) {
58 if (parsed.sql) {
59 fail("Pass either --sql or --statements, not both.");
60 }
61 let raw: unknown;
62 try {
63 raw = JSON.parse(parsed.statements);
64 } catch {
65 fail(
66 '--statements must be a JSON array of {"sql": string, "args"?: unknown[]} objects',
67 );
68 }
69 if (!Array.isArray(raw) || raw.length === 0) {
70 fail("--statements must be a non-empty JSON array");
71 }
72 return raw.map((entry, index) => {
73 if (
74 !entry ||
75 typeof entry !== "object" ||
76 typeof (entry as any).sql !== "string" ||
77 !(entry as any).sql.trim()
78 ) {
79 fail(`Statement ${index + 1} must include a non-empty sql string`);
80 }
81 const args = (entry as any).args;
82 if (args != null && !Array.isArray(args)) {
83 fail(`Statement ${index + 1} args must be a JSON array`);
84 }
85 return { sql: (entry as any).sql, args: args ?? [] };
86 });
87 }
88
89 if (!parsed.sql) {
90 fail(
91 '--sql is required unless --statements is provided. Example: --sql "UPDATE forms SET status=? WHERE id=?" --args \'["published","abc"]\'',
92 );
93 }
94 return [{ sql: parsed.sql, args: parseSqlArgs(parsed.args) }];
95}
96
97function stripLeadingSqlComments(sql: string): string {
98 return sql

Callers 1

dbExecFunction · 0.85

Calls 2

failFunction · 0.90
parseSqlArgsFunction · 0.70

Tested by

no test coverage detected