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

Function parseCreateViewScript

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

Source from the content-addressed store, hash-verified

3import { CursorV2 } from "./sql-parse-table";
4
5export function parseCreateViewScript(
6 schemaName: string,
7 sql: string
8): DatabaseViewSchema {
9 const cursor = new CursorV2(tokenizeSql(sql, "sqlite"));
10
11 cursor.expectToken("CREATE");
12 cursor.expectTokenOptional("TEMP");
13 cursor.expectTokenOptional("TEMPORARY");
14 cursor.expectToken("VIEW");
15 cursor.expectTokensOptional(["IF", "NOT", "EXIST"]);
16
17 const name = cursor.consumeIdentifier();
18
19 cursor.expectToken("AS");
20
21 let statement = "";
22 const fromStatement = cursor.getPointer();
23 let toStatement;
24
25 while (!cursor.end()) {
26 toStatement = cursor.getPointer();
27
28 if (cursor.match(";")) {
29 break;
30 }
31
32 cursor.next();
33 }
34
35 if (fromStatement && toStatement) {
36 statement = cursor.toStringRange(fromStatement, toStatement);
37 }
38
39 return {
40 schemaName,
41 name,
42 statement,
43 };
44}

Callers 2

viewMethod · 0.90

Calls 9

expectTokenMethod · 0.95
expectTokenOptionalMethod · 0.95
expectTokensOptionalMethod · 0.95
consumeIdentifierMethod · 0.95
getPointerMethod · 0.95
endMethod · 0.95
matchMethod · 0.95
nextMethod · 0.95
toStringRangeMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…