( schemaName: string, sql: string )
| 3 | import { CursorV2 } from "./sql-parse-table"; |
| 4 | |
| 5 | export 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 | } |
no test coverage detected
searching dependent graphs…