MCPcopy Index your code
hub / github.com/outerbase/studio / parseCreateTableScript

Function parseCreateTableScript

src/drivers/sqlite/sql-parse-table.ts:555–601  ·  view source on GitHub ↗
(
  schemaName: string,
  sql: string
)

Source from the content-addressed store, hash-verified

553// Our parser follows this spec
554// https://www.sqlite.org/lang_createtable.html
555export function parseCreateTableScript(
556 schemaName: string,
557 sql: string
558): DatabaseTableSchema {
559 const cursor = new CursorV2(tokenizeSql(sql, "sqlite"));
560
561 cursor.expectToken("CREATE");
562 cursor.expectTokenOptional("TEMP");
563 cursor.expectTokenOptional("TEMPORARY");
564 cursor.expectTokenOptional("VIRTUAL");
565 cursor.expectToken("TABLE");
566 cursor.expectTokensOptional(["IF", "NOT", "EXIST"]);
567
568 const tableName = cursor.consumeIdentifier();
569
570 // Check for FTS5
571 let fts5: DatabaseTableFts5 | undefined;
572
573 if (cursor.match("USING")) {
574 cursor.next();
575 if (cursor.match("FTS5")) {
576 cursor.next();
577 fts5 = parseFTS5(cursor.consumeParen());
578 }
579 }
580
581 const defs = cursor.match("(")
582 ? parseTableDefinition(schemaName, cursor.consumeParen())
583 : { columns: [], constraints: [] };
584
585 // Parsing table options
586 const pk = defs.columns.filter((col) => col.pk).map((col) => col.name);
587
588 const autoIncrement = defs.columns.some(
589 (col) => !!col.constraint?.autoIncrement
590 );
591
592 return {
593 tableName,
594 schemaName,
595 ...defs,
596 pk,
597 autoIncrement,
598 fts5,
599 ...parseTableOption(cursor),
600 };
601}

Callers 4

getSchemaListMethod · 0.90
tableSchemaMethod · 0.90
pFunction · 0.90
cFunction · 0.90

Calls 10

expectTokenMethod · 0.95
expectTokenOptionalMethod · 0.95
expectTokensOptionalMethod · 0.95
consumeIdentifierMethod · 0.95
matchMethod · 0.95
nextMethod · 0.95
consumeParenMethod · 0.95
parseFTS5Function · 0.85
parseTableDefinitionFunction · 0.85
parseTableOptionFunction · 0.85

Tested by 2

pFunction · 0.72
cFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…