MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / splitColumnList

Function splitColumnList

packages/wl-sdk/scripts/sql-parser.ts:251–298  ·  view source on GitHub ↗

* Split a column-list body on top-level commas (i.e. commas not inside * parentheses). Needed for `CHECK (a BETWEEN 0 AND 1)` style entries.

(body: string)

Source from the content-addressed store, hash-verified

249 * parentheses). Needed for `CHECK (a BETWEEN 0 AND 1)` style entries.
250 */
251function splitColumnList(body: string): string[] {
252 const out: string[] = [];
253 let depth = 0;
254 let inBacktick = false;
255 let inSingle = false;
256 let buf = '';
257 for (let i = 0; i < body.length; i++) {
258 const ch = body[i];
259 if (inSingle) {
260 buf += ch;
261 if (ch === "'" && body[i - 1] !== '\\') inSingle = false;
262 continue;
263 }
264 if (inBacktick) {
265 buf += ch;
266 if (ch === '`') inBacktick = false;
267 continue;
268 }
269 if (ch === "'") {
270 inSingle = true;
271 buf += ch;
272 continue;
273 }
274 if (ch === '`') {
275 inBacktick = true;
276 buf += ch;
277 continue;
278 }
279 if (ch === '(') {
280 depth++;
281 buf += ch;
282 continue;
283 }
284 if (ch === ')') {
285 depth--;
286 buf += ch;
287 continue;
288 }
289 if (ch === ',' && depth === 0) {
290 out.push(buf);
291 buf = '';
292 continue;
293 }
294 buf += ch;
295 }
296 if (buf.trim().length > 0) out.push(buf);
297 return out;
298}
299
300export function parseSchema(sql: string): ParsedSchema {
301 const statements = splitStatements(sql);

Callers 1

parseCreateTableFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected