rawsql-ts 0.2.0-beta → 0.3.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -8
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models/CreateTableQuery.js +62 -0
- package/dist/esm/models/CreateTableQuery.js.map +1 -0
- package/dist/esm/models/InsertQuery.js +24 -0
- package/dist/esm/models/InsertQuery.js.map +1 -0
- package/dist/esm/models/SelectQuery.js +2 -1
- package/dist/esm/models/SelectQuery.js.map +1 -1
- package/dist/esm/parsers/IdentifierParser.js +3 -2
- package/dist/esm/parsers/IdentifierParser.js.map +1 -1
- package/dist/esm/parsers/InsertQueryParser.js +104 -0
- package/dist/esm/parsers/InsertQueryParser.js.map +1 -0
- package/dist/esm/parsers/ParameterExpressionParser.js +11 -2
- package/dist/esm/parsers/ParameterExpressionParser.js.map +1 -1
- package/dist/esm/parsers/SelectQueryParser.js +1 -1
- package/dist/esm/parsers/SelectQueryParser.js.map +1 -1
- package/dist/esm/parsers/SourceParser.js +8 -26
- package/dist/esm/parsers/SourceParser.js.map +1 -1
- package/dist/esm/parsers/ValueParser.js +14 -1
- package/dist/esm/parsers/ValueParser.js.map +1 -1
- package/dist/esm/tokenReaders/ParameterTokenReader.js +21 -1
- package/dist/esm/tokenReaders/ParameterTokenReader.js.map +1 -1
- package/dist/esm/transformers/Formatter.js +76 -4
- package/dist/esm/transformers/Formatter.js.map +1 -1
- package/dist/esm/transformers/QueryConverter.js +67 -12
- package/dist/esm/transformers/QueryConverter.js.map +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/models/CreateTableQuery.d.ts +27 -0
- package/dist/esm/types/models/InsertQuery.d.ts +21 -0
- package/dist/esm/types/models/SelectQuery.d.ts +3 -2
- package/dist/esm/types/parsers/InsertQueryParser.d.ts +17 -0
- package/dist/esm/types/tokenReaders/ParameterTokenReader.d.ts +2 -1
- package/dist/esm/types/transformers/Formatter.d.ts +19 -2
- package/dist/esm/types/transformers/QueryConverter.d.ts +22 -2
- package/dist/esm/types/utils/extractNamespacesAndName.d.ts +5 -0
- package/dist/esm/types/utils/parseEscapedOrDotSeparatedIdentifiers.d.ts +9 -0
- package/dist/esm/utils/extractNamespacesAndName.js +16 -0
- package/dist/esm/utils/extractNamespacesAndName.js.map +1 -0
- package/dist/esm/utils/parseEscapedOrDotSeparatedIdentifiers.js +39 -0
- package/dist/esm/utils/parseEscapedOrDotSeparatedIdentifiers.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models/CreateTableQuery.d.ts +27 -0
- package/dist/models/CreateTableQuery.js +66 -0
- package/dist/models/CreateTableQuery.js.map +1 -0
- package/dist/models/InsertQuery.d.ts +21 -0
- package/dist/models/InsertQuery.js +28 -0
- package/dist/models/InsertQuery.js.map +1 -0
- package/dist/models/SelectQuery.d.ts +3 -2
- package/dist/models/SelectQuery.js +3 -1
- package/dist/models/SelectQuery.js.map +1 -1
- package/dist/parsers/IdentifierParser.js +3 -2
- package/dist/parsers/IdentifierParser.js.map +1 -1
- package/dist/parsers/InsertQueryParser.d.ts +17 -0
- package/dist/parsers/InsertQueryParser.js +108 -0
- package/dist/parsers/InsertQueryParser.js.map +1 -0
- package/dist/parsers/ParameterExpressionParser.js +11 -2
- package/dist/parsers/ParameterExpressionParser.js.map +1 -1
- package/dist/parsers/SelectQueryParser.js +1 -1
- package/dist/parsers/SelectQueryParser.js.map +1 -1
- package/dist/parsers/SourceParser.js +8 -26
- package/dist/parsers/SourceParser.js.map +1 -1
- package/dist/parsers/ValueParser.js +14 -1
- package/dist/parsers/ValueParser.js.map +1 -1
- package/dist/tokenReaders/ParameterTokenReader.d.ts +2 -1
- package/dist/tokenReaders/ParameterTokenReader.js +21 -1
- package/dist/tokenReaders/ParameterTokenReader.js.map +1 -1
- package/dist/transformers/Formatter.d.ts +19 -2
- package/dist/transformers/Formatter.js +76 -4
- package/dist/transformers/Formatter.js.map +1 -1
- package/dist/transformers/QueryConverter.d.ts +22 -2
- package/dist/transformers/QueryConverter.js +67 -12
- package/dist/transformers/QueryConverter.js.map +1 -1
- package/dist/utils/extractNamespacesAndName.d.ts +5 -0
- package/dist/utils/extractNamespacesAndName.js +18 -0
- package/dist/utils/extractNamespacesAndName.js.map +1 -0
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.d.ts +9 -0
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.js +42 -0
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -10,7 +10,8 @@
|
|
10
10
|
|
11
11
|
rawsql-ts is a high-performance SQL parser and AST transformer library written in TypeScript. It is designed for extensibility and advanced SQL analysis, with initial focus on PostgreSQL syntax but not limited to it. The library enables easy SQL parsing, transformation, and analysis for a wide range of SQL dialects.
|
12
12
|
|
13
|
-
>
|
13
|
+
> [!Note]
|
14
|
+
> This library is currently in beta. The API may change until the v1.0 release.
|
14
15
|
|
15
16
|
---
|
16
17
|
|
@@ -70,18 +71,113 @@ console.log(formattedSql);
|
|
70
71
|
|
71
72
|
---
|
72
73
|
|
74
|
+
## Formatter Functionality
|
75
|
+
|
76
|
+
The `Formatter` class in rawsql-ts converts a parsed query object (AST) back into a formatted SQL string. This is useful for programmatically manipulating SQL and then generating a string for execution or display.
|
77
|
+
|
78
|
+
### Preset Configurations (Formatter.PRESETS)
|
79
|
+
|
80
|
+
The `Formatter` class provides preset configurations for common SQL dialects. Use these presets to quickly format queries for MySQL, PostgreSQL, SQL Server, or SQLite without manually specifying options each time.
|
81
|
+
|
82
|
+
```typescript
|
83
|
+
const mysqlSql = formatter.format(query, Formatter.PRESETS.mysql);
|
84
|
+
const pgSql = formatter.format(query, Formatter.PRESETS.postgres);
|
85
|
+
const mssqlSql = formatter.format(query, Formatter.PRESETS.sqlserver);
|
86
|
+
const sqliteSql = formatter.format(query, Formatter.PRESETS.sqlite);
|
87
|
+
```
|
88
|
+
|
89
|
+
**Preset Details:**
|
90
|
+
- `Formatter.PRESETS.mysql`: Backtick identifier, `?` parameter, no named parameters
|
91
|
+
- `Formatter.PRESETS.postgres`: Double quote identifier, `:` parameter, named parameters supported
|
92
|
+
- `Formatter.PRESETS.sqlserver`: Square bracket identifier, `@` parameter, named parameters supported
|
93
|
+
- `Formatter.PRESETS.sqlite`: Double quote identifier, `:` parameter, named parameters supported
|
94
|
+
|
95
|
+
### How to Customize Presets
|
96
|
+
|
97
|
+
You can override any preset option as needed. For example, to use variable-style parameters (`${name}`):
|
98
|
+
|
99
|
+
```typescript
|
100
|
+
const variableSql = formatter.format(query, {
|
101
|
+
...Formatter.PRESETS.postgres,
|
102
|
+
parameterSymbol: { start: '${', end: '}' },
|
103
|
+
});
|
104
|
+
// => select "user_id", "name" from "users" where "active" = ${active}
|
105
|
+
```
|
106
|
+
|
107
|
+
Or to change only the identifier escape style:
|
108
|
+
|
109
|
+
```typescript
|
110
|
+
const customSql = formatter.format(query, {
|
111
|
+
...Formatter.PRESETS.mysql,
|
112
|
+
identifierEscape: { start: '"', end: '"' }
|
113
|
+
});
|
114
|
+
```
|
115
|
+
|
116
|
+
### Configurable Options
|
117
|
+
|
118
|
+
Formatting options are provided as the second argument to the `format()` method. You can customize:
|
119
|
+
- `identifierEscape`: How identifiers are escaped (e.g., `"`, `[`, `` ` ``)
|
120
|
+
- `parameterSymbol`: The symbol or pattern for parameters (e.g., `:`, `@`, `?`, or `{ start: '${', end: '}' }`)
|
121
|
+
- `supportNamedParameter`: If false, parameter names are omitted (for MySQL-style `?` only)
|
122
|
+
|
123
|
+
### Usage Example
|
124
|
+
|
125
|
+
#### Using a Preset
|
126
|
+
|
127
|
+
```typescript
|
128
|
+
import { SelectQueryParser, Formatter } from 'rawsql-ts';
|
129
|
+
|
130
|
+
const sql = `SELECT user_id, name FROM users WHERE active = TRUE`;
|
131
|
+
const query = SelectQueryParser.parse(sql);
|
132
|
+
const formatter = new Formatter();
|
133
|
+
const formattedSql = formatter.format(query, Formatter.PRESETS.postgres);
|
134
|
+
console.log(formattedSql);
|
135
|
+
// => select "user_id", "name" from "users" where "active" = true
|
136
|
+
```
|
137
|
+
|
138
|
+
#### Using Manual Configuration
|
139
|
+
|
140
|
+
```typescript
|
141
|
+
import { SelectQueryParser, Formatter } from 'rawsql-ts';
|
142
|
+
|
143
|
+
const sql = `SELECT user_id, name FROM users WHERE active = TRUE`;
|
144
|
+
const query = SelectQueryParser.parse(sql);
|
145
|
+
const formatter = new Formatter();
|
146
|
+
const formattedSql = formatter.format(query, {
|
147
|
+
identifierEscape: { start: '`', end: '`' },
|
148
|
+
parameterSymbol: '?',
|
149
|
+
supportNamedParameter: false,
|
150
|
+
});
|
151
|
+
console.log(formattedSql);
|
152
|
+
// => select `user_id`, `name` from `users` where `active` = ?
|
153
|
+
```
|
154
|
+
|
155
|
+
rawsql-ts is designed to be flexible and support various SQL dialects. The `Formatter` class can be customized to handle different dialects by adjusting the identifier escape characters, parameter symbols, and named parameter support. This makes it easy to work with SQL queries for different database systems using a consistent API.
|
156
|
+
|
157
|
+
---
|
158
|
+
|
73
159
|
## Main Parser Features
|
74
160
|
|
161
|
+
- All parsers automatically remove SQL comments before parsing.
|
162
|
+
- Detailed error messages are provided for all parsing errors.
|
163
|
+
- Highly accurate and advanced tokenization is used for robust SQL analysis.
|
164
|
+
|
165
|
+
> [!Note]
|
166
|
+
> All parsers in rawsql-ts have been tested with PostgreSQL syntax, but they are capable of parsing any generic SQL statement that does not use a DBMS-specific dialect.
|
167
|
+
|
75
168
|
- **SelectQueryParser**
|
76
|
-
The main class for converting SELECT and VALUES statements into AST. Fully supports CTEs (WITH), UNION/INTERSECT/EXCEPT, subqueries, and PostgreSQL-
|
169
|
+
The main class for converting SELECT and VALUES statements into AST. Fully supports CTEs (WITH), UNION/INTERSECT/EXCEPT, subqueries, and PostgreSQL-style syntax.
|
77
170
|
- `parse(sql: string): SelectQuery`
|
78
171
|
Converts a SQL string to an AST. Throws an exception on error.
|
79
|
-
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
172
|
+
- In this library, a "select query" is represented as one of the following types:
|
173
|
+
- `SimpleSelectQuery`: A standard SELECT statement with all major clauses (WHERE, GROUP BY, JOIN, etc.)
|
174
|
+
- `BinarySelectQuery`: A set operation query such as UNION, INTERSECT, or EXCEPT
|
175
|
+
- `ValuesQuery`: An inline VALUES table (e.g., `VALUES (1, 'a'), (2, 'b')`)
|
176
|
+
|
177
|
+
- **InsertQueryParser**
|
178
|
+
The main class for parsing `INSERT INTO` statements and converting them into AST. Supports PostgreSQL-style INSERT with or without column lists, as well as `INSERT ... SELECT` and `INSERT ... VALUES` forms.
|
179
|
+
- `parse(sql: string): InsertQuery`
|
180
|
+
Converts an INSERT SQL string to an AST. Throws an exception on error.
|
85
181
|
|
86
182
|
---
|
87
183
|
|
@@ -251,6 +347,11 @@ A suite of utilities for transforming and analyzing SQL ASTs.
|
|
251
347
|
Consolidates all CTEs into a single root-level WITH clause. Throws an error if duplicate CTE names with different definitions are found.
|
252
348
|
- **QueryNormalizer**
|
253
349
|
Converts any SELECT/UNION/VALUES query into a standard SimpleSelectQuery. Handles subquery wrapping and automatic column name generation.
|
350
|
+
- **QueryConverter**
|
351
|
+
Converts any SELECT/UNION/VALUES query into a standard SimpleSelectQuery. Handles subquery wrapping and automatic column name generation.
|
352
|
+
Supports CREATE TABLE ... AS SELECT ... conversion:
|
353
|
+
- `QueryConverter.toCreateTableQuery(query, tableName, isTemporary?)` creates a `CreateTableQuery` from any SELECT query.
|
354
|
+
|
254
355
|
- **TableColumnResolver**
|
255
356
|
A function type for resolving column names from a table name, mainly used for wildcard expansion (e.g., `table.*`). Used by analyzers like SelectValueCollector.
|
256
357
|
```typescript
|
@@ -291,7 +392,9 @@ Select values:
|
|
291
392
|
name: user_name, value: "u"."user_name"
|
292
393
|
name: email, value: "u"."email"
|
293
394
|
*/
|
395
|
+
```
|
294
396
|
|
397
|
+
```typescript
|
295
398
|
// Collects selectable columns from the FROM/JOIN clauses.
|
296
399
|
// You can get accurate information by specifying a TableColumnResolver.
|
297
400
|
// If omitted, the information will be inferred from the query content.
|
@@ -312,7 +415,25 @@ Selectable columns:
|
|
312
415
|
name: title, value: "p"."title"
|
313
416
|
name: content, value: "p"."content"
|
314
417
|
*/
|
418
|
+
```
|
315
419
|
|
420
|
+
```typescript
|
421
|
+
// Create Table from SELECT Example
|
422
|
+
import { QueryConverter, SelectQueryParser, Formatter } from 'rawsql-ts';
|
423
|
+
|
424
|
+
const select = SelectQueryParser.parse('SELECT id, name FROM users');
|
425
|
+
const create = QueryConverter.toCreateTableQuery(select, 'my_table');
|
426
|
+
const sqlCreate = new Formatter().format(create);
|
427
|
+
console.log(sqlCreate);
|
428
|
+
// => create table "my_table" as select "id", "name" from "users"
|
429
|
+
|
430
|
+
const createTemp = QueryConverter.toCreateTableQuery(select, 'tmp_table', true);
|
431
|
+
const sqlTemp = new Formatter().format(createTemp);
|
432
|
+
console.log(sqlTemp);
|
433
|
+
// => create temporary table "tmp_table" as select "id", "name" from "users"
|
434
|
+
```
|
435
|
+
|
436
|
+
```typescript
|
316
437
|
// Retrieves physical table sources.
|
317
438
|
const tableSourceCollector = new TableSourceCollector();
|
318
439
|
const sources = tableSourceCollector.collect(query);
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AAErC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,oEAAoE"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AAErC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,oEAAoE"}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { SqlComponent } from "./SqlComponent";
|
2
|
+
import { ColumnReference, FunctionCall, IdentifierString, RawString } from "./ValueComponent";
|
3
|
+
import { SimpleSelectQuery } from "./SimpleSelectQuery";
|
4
|
+
import { SelectClause, SelectItem, FromClause, TableSource, SourceExpression } from "./Clause";
|
5
|
+
import { SelectValueCollector } from "../transformers/SelectValueCollector";
|
6
|
+
// Represents a CREATE TABLE query model
|
7
|
+
// Supports temporary tables and AS SELECT ...
|
8
|
+
export class CreateTableQuery extends SqlComponent {
|
9
|
+
constructor(params) {
|
10
|
+
var _a;
|
11
|
+
super();
|
12
|
+
this.tableName = new IdentifierString(params.tableName);
|
13
|
+
this.isTemporary = (_a = params.isTemporary) !== null && _a !== void 0 ? _a : false;
|
14
|
+
this.asSelectQuery = params.asSelectQuery;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Returns a SelectQuery that selects all columns from this table.
|
18
|
+
*/
|
19
|
+
getSelectQuery() {
|
20
|
+
let selectItems;
|
21
|
+
if (this.asSelectQuery) {
|
22
|
+
// Use SelectValueCollector to get columns from asSelectQuery
|
23
|
+
const collector = new SelectValueCollector();
|
24
|
+
const values = collector.collect(this.asSelectQuery);
|
25
|
+
selectItems = values.map(val => new SelectItem(val.value, val.name));
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
// fallback: wildcard
|
29
|
+
selectItems = [new SelectItem(new RawString("*"))];
|
30
|
+
}
|
31
|
+
return new SimpleSelectQuery(null, // withClause
|
32
|
+
new SelectClause(selectItems), new FromClause(new SourceExpression(new TableSource(null, this.tableName.name), null), null // joins
|
33
|
+
), null, // whereClause
|
34
|
+
null, // groupByClause
|
35
|
+
null, // havingClause
|
36
|
+
null, // orderByClause
|
37
|
+
null, // windowFrameClause
|
38
|
+
null, // rowLimitClause
|
39
|
+
null // forClause
|
40
|
+
);
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Returns a SelectQuery that counts all rows in this table.
|
44
|
+
*/
|
45
|
+
getCountQuery() {
|
46
|
+
return new SimpleSelectQuery(null, // withClause
|
47
|
+
new SelectClause([
|
48
|
+
new SelectItem(new FunctionCall("count", new ColumnReference(null, "*"), null))
|
49
|
+
]), new FromClause(new SourceExpression(new TableSource(null, this.tableName.name), null), null // joins
|
50
|
+
), null, // whereClause
|
51
|
+
null, // groupByClause
|
52
|
+
null, // havingClause
|
53
|
+
null, // orderByClause
|
54
|
+
null, // windowFrameClause
|
55
|
+
null, // rowLimitClause
|
56
|
+
null // forClause
|
57
|
+
);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
/** SqlComponent kind symbol for visitor pattern */
|
61
|
+
CreateTableQuery.kind = Symbol("CreateTableQuery");
|
62
|
+
//# sourceMappingURL=CreateTableQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"CreateTableQuery.js","sourceRoot":"","sources":["../../../src/models/CreateTableQuery.ts"],"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,iBAAiB,CACxB,IAAI,EAAE,aAAa;QACnB,IAAI,YAAY,CAAC,WAAW,CAAC,EAC7B,IAAI,UAAU,CACV,IAAI,gBAAgB,CAChB,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAC1C,IAAI,CACP,EACD,IAAI,CAAC,QAAQ;SAChB,EACD,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,iBAAiB;QACvB,IAAI,CAAE,YAAY;SACrB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO,IAAI,iBAAiB,CACxB,IAAI,EAAE,aAAa;QACnB,IAAI,YAAY,CAAC;YACb,IAAI,UAAU,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;SAClF,CAAC,EACF,IAAI,UAAU,CACV,IAAI,gBAAgB,CAChB,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAC1C,IAAI,CACP,EACD,IAAI,CAAC,QAAQ;SAChB,EACD,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,iBAAiB;QACvB,IAAI,CAAE,YAAY;SACrB,CAAC;IACN,CAAC;;AA9ED,mDAAmD;AAC5C,qBAAI,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// filepath: src/models/InsertQuery.ts
|
2
|
+
// Represents an INSERT query in SQL.
|
3
|
+
// Supports single/multi-row VALUES and INSERT ... SELECT.
|
4
|
+
import { SqlComponent } from "./SqlComponent";
|
5
|
+
import { IdentifierString } from "./ValueComponent";
|
6
|
+
export class InsertQuery extends SqlComponent {
|
7
|
+
/**
|
8
|
+
* @param params.table Table name (string or IdentifierString)
|
9
|
+
* @param params.columns Array of column names (string[] or IdentifierString[])
|
10
|
+
* @param params.selectQuery SELECT/VALUES query (required)
|
11
|
+
*/
|
12
|
+
constructor(params) {
|
13
|
+
var _a;
|
14
|
+
super();
|
15
|
+
this.namespaces = params.namespaces
|
16
|
+
? params.namespaces.map(ns => typeof ns === "string" ? new IdentifierString(ns) : ns)
|
17
|
+
: null;
|
18
|
+
this.table = typeof params.table === "string" ? new IdentifierString(params.table) : params.table;
|
19
|
+
this.columns = params.columns.map(c => typeof c === "string" ? new IdentifierString(c) : c);
|
20
|
+
this.selectQuery = (_a = params.selectQuery) !== null && _a !== void 0 ? _a : null;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
InsertQuery.kind = Symbol("InsertQuery");
|
24
|
+
//# sourceMappingURL=InsertQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"InsertQuery.js","sourceRoot":"","sources":["../../../src/models/InsertQuery.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qCAAqC;AACrC,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAkB,MAAM,kBAAkB,CAAC;AAGpE,MAAM,OAAO,WAAY,SAAQ,YAAY;IAOzC;;;;OAIG;IACH,YAAY,MAKX;;QACG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;YAC/B,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrF,CAAC,CAAC,IAAI,CAAC;QACX,IAAI,CAAC,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAClG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,WAAW,mCAAI,IAAI,CAAC;IAClD,CAAC;;AAxBM,gBAAI,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import { InsertQuery } from "./InsertQuery";
|
1
2
|
import { SimpleSelectQuery } from "./SimpleSelectQuery";
|
2
3
|
import { BinarySelectQuery } from "./BinarySelectQuery";
|
3
4
|
import { ValuesQuery } from "./ValuesQuery";
|
4
|
-
export { SimpleSelectQuery, BinarySelectQuery, ValuesQuery };
|
5
|
+
export { SimpleSelectQuery, BinarySelectQuery, ValuesQuery, InsertQuery };
|
5
6
|
//# sourceMappingURL=SelectQuery.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../../src/models/SelectQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
|
1
|
+
{"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../../src/models/SelectQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { extractNamespacesAndName } from "../utils/extractNamespacesAndName";
|
1
2
|
import { TokenType } from "../models/Lexeme";
|
2
3
|
import { ColumnReference } from "../models/ValueComponent";
|
3
4
|
export class IdentifierParser {
|
@@ -21,8 +22,8 @@ export class IdentifierParser {
|
|
21
22
|
}
|
22
23
|
if (identifiers.length > 1) {
|
23
24
|
// If there are multiple identifiers, treat it as a column reference
|
24
|
-
const
|
25
|
-
const value = new ColumnReference(
|
25
|
+
const { namespaces, name } = extractNamespacesAndName(identifiers);
|
26
|
+
const value = new ColumnReference(namespaces, name);
|
26
27
|
return { value, newIndex: idx };
|
27
28
|
}
|
28
29
|
else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"IdentifierParser.js","sourceRoot":"","sources":["../../../src/parsers/IdentifierParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,0BAA0B,CAAC;AAE3E,MAAM,OAAO,gBAAgB;IAClB,MAAM,CAAC,eAAe,CAAC,OAAiB,EAAE,KAAa;QAC1D,yEAAyE;QACzE,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,MAAM,WAAW,GAAa,EAAE,CAAC;QAEjC,2BAA2B;QAC3B,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACrC,GAAG,EAAE,CAAC;QA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AG,OAAO,CAAC,MAAM;YACxB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC;YACnC,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,EACpF,CAAC;YACC,2CAA2C;YAC3C,GAAG,EAAE,CAAC;YACN,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACrC,GAAG,EAAE,CAAC;QACV,CAAC;QAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,oEAAoE;YACpE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;YACnE,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACpD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QACpC,CAAC;aAAM,CAAC;YACJ,mEAAmE;YACnE,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QACpC,CAAC;IACL,CAAC;CACJ"}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
// filepath: src/parsers/InsertQueryParser.ts
|
2
|
+
// Provides parsing for INSERT queries, supporting optional columns and WITH/SELECT/VALUES structure.
|
3
|
+
import { InsertQuery } from "../models/InsertQuery";
|
4
|
+
import { TokenType } from "../models/Lexeme";
|
5
|
+
import { SqlTokenizer } from "./SqlTokenizer";
|
6
|
+
import { SelectQueryParser } from "./SelectQueryParser";
|
7
|
+
import { WithClauseParser } from "./WithClauseParser";
|
8
|
+
import { IdentifierString } from "../models/ValueComponent";
|
9
|
+
import { SimpleSelectQuery } from "../models/SimpleSelectQuery";
|
10
|
+
import { extractNamespacesAndName } from "../utils/extractNamespacesAndName";
|
11
|
+
export class InsertQueryParser {
|
12
|
+
/**
|
13
|
+
* Parse SQL string to InsertQuery AST.
|
14
|
+
* @param query SQL string
|
15
|
+
*/
|
16
|
+
static parse(query) {
|
17
|
+
const tokenizer = new SqlTokenizer(query);
|
18
|
+
const lexemes = tokenizer.readLexmes();
|
19
|
+
const result = this.parseFromLexeme(lexemes, 0);
|
20
|
+
if (result.newIndex < lexemes.length) {
|
21
|
+
throw new Error(`Syntax error: Unexpected token "${lexemes[result.newIndex].value}" at position ${result.newIndex}. The INSERT query is complete but there are additional tokens.`);
|
22
|
+
}
|
23
|
+
return result.value;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Parse from lexeme array (for internal use and tests)
|
27
|
+
*/
|
28
|
+
static parseFromLexeme(lexemes, index) {
|
29
|
+
var _a, _b, _c;
|
30
|
+
let idx = index;
|
31
|
+
let withclause = null;
|
32
|
+
if (lexemes[idx].value === "with") {
|
33
|
+
const result = WithClauseParser.parseFromLexeme(lexemes, idx);
|
34
|
+
withclause = result.value;
|
35
|
+
idx = result.newIndex;
|
36
|
+
}
|
37
|
+
// Expect INSERT INTO
|
38
|
+
if (lexemes[idx].value !== "insert into") {
|
39
|
+
throw new Error(`Syntax error at position ${idx}: Expected 'INSERT INTO' but found '${lexemes[idx].value}'.`);
|
40
|
+
}
|
41
|
+
idx++;
|
42
|
+
// 完全名を取得
|
43
|
+
const { namespaces, table, newIndex: idxAfterName } = this.parseFullQualifiedName(lexemes, idx);
|
44
|
+
idx = idxAfterName;
|
45
|
+
// Optional columns
|
46
|
+
let columns = [];
|
47
|
+
if (((_a = lexemes[idx]) === null || _a === void 0 ? void 0 : _a.type) === TokenType.OpenParen) {
|
48
|
+
idx++;
|
49
|
+
while (idx < lexemes.length && lexemes[idx].type === TokenType.Identifier) {
|
50
|
+
columns.push(lexemes[idx].value);
|
51
|
+
idx++;
|
52
|
+
if (((_b = lexemes[idx]) === null || _b === void 0 ? void 0 : _b.type) === TokenType.Comma) {
|
53
|
+
idx++;
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
if (((_c = lexemes[idx]) === null || _c === void 0 ? void 0 : _c.type) !== TokenType.CloseParen) {
|
60
|
+
throw new Error(`Syntax error at position ${idx}: Expected ')' after column list.`);
|
61
|
+
}
|
62
|
+
idx++;
|
63
|
+
}
|
64
|
+
const selectResult = SelectQueryParser.parseFromLexeme(lexemes, idx);
|
65
|
+
if (withclause) {
|
66
|
+
if (selectResult.value instanceof SimpleSelectQuery) {
|
67
|
+
selectResult.value.WithClause = withclause;
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
throw new Error(`WITH clause is not supported in this context.`);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
idx = selectResult.newIndex;
|
74
|
+
return {
|
75
|
+
value: new InsertQuery({
|
76
|
+
namespaces,
|
77
|
+
table,
|
78
|
+
columns,
|
79
|
+
selectQuery: selectResult.value
|
80
|
+
}),
|
81
|
+
newIndex: idx
|
82
|
+
};
|
83
|
+
}
|
84
|
+
// Get fully qualified name and split into namespaces/table
|
85
|
+
static parseFullQualifiedName(lexemes, index) {
|
86
|
+
let idx = index;
|
87
|
+
const fullname = [];
|
88
|
+
fullname.push(lexemes[index].value);
|
89
|
+
idx++;
|
90
|
+
while (idx < lexemes.length && lexemes[idx].type === TokenType.Dot) {
|
91
|
+
idx++; // Skip dot
|
92
|
+
if (idx < lexemes.length) {
|
93
|
+
fullname.push(lexemes[idx].value);
|
94
|
+
idx++;
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
throw new Error(`Syntax error at position ${idx}: Expected identifier after '.' but found end of input.`);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
const { namespaces, name } = extractNamespacesAndName(fullname);
|
101
|
+
return { namespaces, table: new IdentifierString(name), newIndex: idx };
|
102
|
+
}
|
103
|
+
}
|
104
|
+
//# sourceMappingURL=InsertQueryParser.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"InsertQueryParser.js","sourceRoot":"","sources":["../../../src/parsers/InsertQueryParser.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AACrG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,MAAM,OAAO,iBAAiB;IAC1B;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAChD,IAAI,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,iBAAiB,MAAM,CAAC,QAAQ,iEAAiE,CAAC,CAAC;QACxL,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,eAAe,CAAC,OAAi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C,CAAC,WAAW;YAClB,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;gBACvB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;gBAClC,GAAG,EAAE,CAAC;YACV,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,yDAAyD,CAAC,CAAC;YAC9G,CAAC;QACL,CAAC;QACD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;QAChE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IAC5E,CAAC;CACJ"}
|
@@ -2,8 +2,17 @@ import { ParameterExpression } from "../models/ValueComponent";
|
|
2
2
|
export class ParameterExpressionParser {
|
3
3
|
static parseFromLexeme(lexemes, index) {
|
4
4
|
let idx = index;
|
5
|
-
|
6
|
-
|
5
|
+
let paramName = lexemes[idx].value;
|
6
|
+
// Normalize parameter: Remove the parameter symbol and extract the parameter name.
|
7
|
+
if (paramName.startsWith('${') && paramName.endsWith('}')) {
|
8
|
+
// ${name} → name
|
9
|
+
paramName = paramName.slice(2, -1);
|
10
|
+
}
|
11
|
+
else {
|
12
|
+
// :name → name
|
13
|
+
paramName = paramName.slice(1);
|
14
|
+
}
|
15
|
+
const value = new ParameterExpression(paramName);
|
7
16
|
idx++;
|
8
17
|
return { value, newIndex: idx };
|
9
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ParameterExpressionParser.js","sourceRoot":"","sources":["../../../src/parsers/ParameterExpressionParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAkB,MAAM,0BAA0B,CAAC;AAE/E,MAAM,OAAO,yBAAyB;IAC3B,MAAM,CAAC,eAAe,CAAC,OAAiB,EAAE,KAAa;QAC1D,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,
|
1
|
+
{"version":3,"file":"ParameterExpressionParser.js","sourceRoot":"","sources":["../../../src/parsers/ParameterExpressionParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAkB,MAAM,0BAA0B,CAAC;AAE/E,MAAM,OAAO,yBAAyB;IAC3B,MAAM,CAAC,eAAe,CAAC,OAAiB,EAAE,KAAa;QAC1D,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;QAEnC,mFAAmF;QACnF,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxD,iBAAiB;YACjB,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACJ,eAAe;YACf,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC;QACjD,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
@@ -29,7 +29,7 @@ export class SelectQueryParser {
|
|
29
29
|
const result = this.parseFromLexeme(lexemes, 0);
|
30
30
|
// Error if there are remaining tokens
|
31
31
|
if (result.newIndex < lexemes.length) {
|
32
|
-
throw new Error(`Syntax error: Unexpected token "${lexemes[result.newIndex].value}" at position ${result.newIndex}. The SELECT query is complete but there are additional tokens.`);
|
32
|
+
throw new Error(`[SelectQueryParser] Syntax error: Unexpected token "${lexemes[result.newIndex].value}" at position ${result.newIndex}. The SELECT query is complete but there are additional tokens.`);
|
33
33
|
}
|
34
34
|
return result.value;
|
35
35
|
}
|
@@ -1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Parser } from "./ValueParser";
|
6
|
+
import { extractNamespacesAndName } from "../utils/extractNamespacesAndName";
|
7
|
+
import { parseEscapedOrDotSeparatedIdentifiers } from "../utils/parseEscapedOrDotSeparatedIdentifiers";
|
6
8
|
export class SourceParser {
|
7
9
|
// Parse SQL string to AST (was: parse)
|
8
10
|
static parse(query) {
|
@@ -31,33 +33,13 @@ export class SourceParser {
|
|
31
33
|
return this.parseTableSource(lexemes, idx);
|
32
34
|
}
|
33
35
|
static parseTableSource(lexemes, index) {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
// Add the first identifier
|
38
|
-
identifiers.push(lexemes[idx].value);
|
39
|
-
idx++;
|
40
|
-
// Look for dot and identifier pattern
|
41
|
-
while (idx < lexemes.length &&
|
42
|
-
idx + 1 < lexemes.length &&
|
43
|
-
(lexemes[idx].type & TokenType.Dot) &&
|
44
|
-
(lexemes[idx + 1].type & TokenType.Identifier)) {
|
45
|
-
// Skip the dot and add the next identifier
|
46
|
-
idx++;
|
47
|
-
identifiers.push(lexemes[idx].value);
|
48
|
-
idx++;
|
49
|
-
}
|
50
|
-
if (identifiers.length > 1) {
|
51
|
-
// If there are multiple identifiers, treat it as a column reference
|
52
|
-
const lastIdentifier = identifiers.pop() || '';
|
53
|
-
const value = new TableSource(identifiers, lastIdentifier);
|
54
|
-
return { value, newIndex: idx };
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
// If there is a single identifier, treat it as a simple identifier
|
58
|
-
const value = new TableSource(null, identifiers[0]);
|
59
|
-
return { value, newIndex: idx };
|
36
|
+
const { identifiers, newIndex } = parseEscapedOrDotSeparatedIdentifiers(lexemes, index);
|
37
|
+
if (identifiers.length === 0) {
|
38
|
+
throw new Error(`No table identifier found at position ${index}`);
|
60
39
|
}
|
40
|
+
const { namespaces, name } = extractNamespacesAndName(identifiers);
|
41
|
+
const value = new TableSource(namespaces, name);
|
42
|
+
return { value, newIndex };
|
61
43
|
}
|
62
44
|
static parseFunctionSource(lexemes, index) {
|
63
45
|
let idx = index;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SourceParser.js","sourceRoot":"","sources":["../../../src/parsers/SourceParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAmB,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"SourceParser.js","sourceRoot":"","sources":["../../../src/parsers/SourceParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAmB,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,qCAAqC,EAAE,MAAM,gDAAgD,CAAC;AAEvG,MAAM,OAAO,YAAY;IACrB,uCAAuC;IAChC,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,uBAAuB;QAClE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,aAAa;QAErD,QAAQ;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAEhD,sCAAsC;QACtC,IAAI,MAAM,CAAC,QAAQ,GAAG,OAA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AAE,GAAG,CAAC,CAAC;QACzF,GAAG,GAAG,QAAQ,CAAC;QAEf,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC;QACvD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IACpD,CAAC;CACJ"}
|
@@ -9,6 +9,8 @@ import { ParameterExpressionParser } from "./ParameterExpressionParser";
|
|
9
9
|
import { StringSpecifierExpressionParser } from "./StringSpecifierExpressionParser";
|
10
10
|
import { CommandExpressionParser } from "./CommandExpressionParser";
|
11
11
|
import { FunctionExpressionParser } from "./FunctionExpressionParser";
|
12
|
+
import { parseEscapedOrDotSeparatedIdentifiers } from "../utils/parseEscapedOrDotSeparatedIdentifiers";
|
13
|
+
import { extractNamespacesAndName } from "../utils/extractNamespacesAndName";
|
12
14
|
export class ValueParser {
|
13
15
|
// Parse SQL string to AST (was: parse)
|
14
16
|
static parse(query) {
|
@@ -90,7 +92,18 @@ export class ValueParser {
|
|
90
92
|
else if (current.type & TokenType.Command) {
|
91
93
|
return CommandExpressionParser.parseFromLexeme(lexemes, idx);
|
92
94
|
}
|
93
|
-
|
95
|
+
else if (current.type & TokenType.OpenBracket) {
|
96
|
+
// SQLServer escape identifier format. e.g. [dbo] or [dbo].[table]
|
97
|
+
const { identifiers, newIndex } = parseEscapedOrDotSeparatedIdentifiers(lexemes, idx);
|
98
|
+
if (identifiers.length === 0) {
|
99
|
+
throw new Error(`[ValueParser] No identifier found after '[' at index ${idx}`);
|
100
|
+
}
|
101
|
+
// Use the same logic as IdentifierParser for dot-separated identifiers
|
102
|
+
const { namespaces, name } = extractNamespacesAndName(identifiers);
|
103
|
+
const value = new ColumnReference(namespaces, name);
|
104
|
+
return { value, newIndex };
|
105
|
+
}
|
106
|
+
throw new Error(`[ValueParser] Invalid lexeme. index: ${idx}, type: ${lexemes[idx].type}, value: ${lexemes[idx].value}`);
|
94
107
|
}
|
95
108
|
static parseArgument(openToken, closeToken, lexemes, index) {
|
96
109
|
let idx = index;
|