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
@@ -1,4 +1,6 @@
|
|
1
1
|
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
2
|
+
import { CreateTableQuery } from "../models/CreateTableQuery";
|
3
|
+
import { InsertQuery } from "../models/InsertQuery";
|
2
4
|
/**
|
3
5
|
* Converts various SELECT query types to a standard SimpleSelectQuery format.
|
4
6
|
* - SimpleSelectQuery is returned as-is
|
@@ -14,9 +16,10 @@ export declare class QueryConverter {
|
|
14
16
|
* Converts a SELECT query to a standard SimpleSelectQuery form.
|
15
17
|
*
|
16
18
|
* @param query The query to convert
|
19
|
+
* @param columns Optional: column names for VALUES query
|
17
20
|
* @returns A SimpleSelectQuery
|
18
21
|
*/
|
19
|
-
static toSimple(query: SelectQuery): SimpleSelectQuery;
|
22
|
+
static toSimple(query: SelectQuery, columns?: string[]): SimpleSelectQuery;
|
20
23
|
/**
|
21
24
|
* Converts a BinarySelectQuery (UNION, EXCEPT, etc.) to a SimpleSelectQuery
|
22
25
|
* by wrapping it in SELECT * FROM (original) AS bq
|
@@ -26,9 +29,10 @@ export declare class QueryConverter {
|
|
26
29
|
*/
|
27
30
|
private static toSimpleBinaryQuery;
|
28
31
|
/**
|
29
|
-
* Converts a ValuesQuery to a SimpleSelectQuery with sequentially numbered columns
|
32
|
+
* Converts a ValuesQuery to a SimpleSelectQuery with sequentially numbered columns or user-specified columns
|
30
33
|
*
|
31
34
|
* @param query The VALUES query to convert
|
35
|
+
* @param columns Optional: column names
|
32
36
|
* @returns A SimpleSelectQuery
|
33
37
|
*/
|
34
38
|
private static toSimpleValuesQuery;
|
@@ -38,4 +42,20 @@ export declare class QueryConverter {
|
|
38
42
|
* @returns A SELECT clause with *
|
39
43
|
*/
|
40
44
|
private static createSelectAllClause;
|
45
|
+
/**
|
46
|
+
* Converts a SELECT query to a CREATE TABLE query (CREATE [TEMPORARY] TABLE ... AS SELECT ...)
|
47
|
+
* @param query The SELECT query to use as the source
|
48
|
+
* @param tableName The name of the table to create
|
49
|
+
* @param isTemporary If true, creates a temporary table
|
50
|
+
* @returns A CreateTableQuery instance
|
51
|
+
*/
|
52
|
+
static toCreateTableQuery(query: SelectQuery, tableName: string, isTemporary?: boolean): CreateTableQuery;
|
53
|
+
/**
|
54
|
+
* Converts a SELECT query to an INSERT query (INSERT INTO ... SELECT ...)
|
55
|
+
* @param selectQuery The SELECT query to use as the source
|
56
|
+
* @param tableName The name of the table to insert into
|
57
|
+
* @param columns Optional: array of column names. If omitted, columns are inferred from the selectQuery
|
58
|
+
* @returns An InsertQuery instance
|
59
|
+
*/
|
60
|
+
static toInsertQuery(selectQuery: SimpleSelectQuery, tableName: string): InsertQuery;
|
41
61
|
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Lexeme } from "../models/Lexeme";
|
2
|
+
/**
|
3
|
+
* Parses SQL Server-style escaped identifiers ([table]) and dot-separated identifiers.
|
4
|
+
* Returns the list of identifiers and the new index after parsing.
|
5
|
+
*/
|
6
|
+
export declare function parseEscapedOrDotSeparatedIdentifiers(lexemes: Lexeme[], index: number): {
|
7
|
+
identifiers: string[];
|
8
|
+
newIndex: number;
|
9
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Utility to extract namespaces and the final name from an array of identifiers
|
2
|
+
// Example: ["db", "schema", "users"] => { namespaces: ["db", "schema"], name: "users" }
|
3
|
+
function extractNamespacesAndName(identifiers) {
|
4
|
+
if (!identifiers || identifiers.length === 0) {
|
5
|
+
throw new Error("Identifier list is empty");
|
6
|
+
}
|
7
|
+
if (identifiers.length === 1) {
|
8
|
+
return { namespaces: null, name: identifiers[0] };
|
9
|
+
}
|
10
|
+
return {
|
11
|
+
namespaces: identifiers.slice(0, -1),
|
12
|
+
name: identifiers[identifiers.length - 1]
|
13
|
+
};
|
14
|
+
}
|
15
|
+
export { extractNamespacesAndName };
|
16
|
+
//# sourceMappingURL=extractNamespacesAndName.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"extractNamespacesAndName.js","sourceRoot":"","sources":["../../../src/utils/extractNamespacesAndName.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wFAAwF;AACxF,SAAS,wBAAwB,CAAC,WAAqB;IACnD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACtD,CAAC;IACD,OAAO;QACH,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;KAC5C,CAAC;AACN,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { TokenType } from "../models/Lexeme";
|
2
|
+
/**
|
3
|
+
* Parses SQL Server-style escaped identifiers ([table]) and dot-separated identifiers.
|
4
|
+
* Returns the list of identifiers and the new index after parsing.
|
5
|
+
*/
|
6
|
+
export function parseEscapedOrDotSeparatedIdentifiers(lexemes, index) {
|
7
|
+
let idx = index;
|
8
|
+
const identifiers = [];
|
9
|
+
while (idx < lexemes.length) {
|
10
|
+
if (lexemes[idx].type & TokenType.OpenBracket) {
|
11
|
+
idx++; // skip [
|
12
|
+
if (idx >= lexemes.length || !(lexemes[idx].type & TokenType.Identifier)) {
|
13
|
+
throw new Error(`Expected identifier after '[' at position ${idx}`);
|
14
|
+
}
|
15
|
+
identifiers.push(lexemes[idx].value);
|
16
|
+
idx++;
|
17
|
+
if (idx >= lexemes.length || lexemes[idx].value !== "]") {
|
18
|
+
throw new Error(`Expected closing ']' after identifier at position ${idx}`);
|
19
|
+
}
|
20
|
+
idx++; // skip ]
|
21
|
+
}
|
22
|
+
else if (lexemes[idx].type & TokenType.Identifier) {
|
23
|
+
identifiers.push(lexemes[idx].value);
|
24
|
+
idx++;
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
// Handle dot for schema.table or db.schema.table
|
30
|
+
if (idx < lexemes.length && (lexemes[idx].type & TokenType.Dot)) {
|
31
|
+
idx++; // skip dot
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return { identifiers, newIndex: idx };
|
38
|
+
}
|
39
|
+
//# sourceMappingURL=parseEscapedOrDotSeparatedIdentifiers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseEscapedOrDotSeparatedIdentifiers.js","sourceRoot":"","sources":["../../../src/utils/parseEscapedOrDotSeparatedIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;GAGG;AACH,MAAM,UAAU,qCAAqC,CAAC,OAAiB,EAAE,KAAa;IAClF,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,OAAO,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,OAAO,CAAC,GAAG,CAA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 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
// Entry point for rawsql-ts package
|
18
18
|
__exportStar(require("./parsers/SelectQueryParser"), exports);
|
19
|
+
__exportStar(require("./parsers/InsertQueryParser"), exports);
|
19
20
|
__exportStar(require("./models/BinarySelectQuery"), exports);
|
20
21
|
__exportStar(require("./models/SelectQuery"), exports);
|
21
22
|
__exportStar(require("./models/ValueComponent"), exports);
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,gEAA8C;AAC9C,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,oEAAoE"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAC5C,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,gEAA8C;AAC9C,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,oEAAoE"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { SqlComponent } from "./SqlComponent";
|
2
|
+
import type { SelectQuery } from "./SelectQuery";
|
3
|
+
import { IdentifierString } from "./ValueComponent";
|
4
|
+
import { SimpleSelectQuery } from "./SimpleSelectQuery";
|
5
|
+
export declare class CreateTableQuery extends SqlComponent {
|
6
|
+
/** SqlComponent kind symbol for visitor pattern */
|
7
|
+
static kind: symbol;
|
8
|
+
/** Table name (with optional schema) */
|
9
|
+
tableName: IdentifierString;
|
10
|
+
/** If true, this is a temporary table */
|
11
|
+
isTemporary: boolean;
|
12
|
+
/** Optional: SELECT query for AS SELECT ... */
|
13
|
+
asSelectQuery?: SelectQuery;
|
14
|
+
constructor(params: {
|
15
|
+
tableName: string;
|
16
|
+
isTemporary?: boolean;
|
17
|
+
asSelectQuery?: SelectQuery;
|
18
|
+
});
|
19
|
+
/**
|
20
|
+
* Returns a SelectQuery that selects all columns from this table.
|
21
|
+
*/
|
22
|
+
getSelectQuery(): SimpleSelectQuery;
|
23
|
+
/**
|
24
|
+
* Returns a SelectQuery that counts all rows in this table.
|
25
|
+
*/
|
26
|
+
getCountQuery(): SimpleSelectQuery;
|
27
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.CreateTableQuery = void 0;
|
4
|
+
const SqlComponent_1 = require("./SqlComponent");
|
5
|
+
const ValueComponent_1 = require("./ValueComponent");
|
6
|
+
const SimpleSelectQuery_1 = require("./SimpleSelectQuery");
|
7
|
+
const Clause_1 = require("./Clause");
|
8
|
+
const SelectValueCollector_1 = require("../transformers/SelectValueCollector");
|
9
|
+
// Represents a CREATE TABLE query model
|
10
|
+
// Supports temporary tables and AS SELECT ...
|
11
|
+
class CreateTableQuery extends SqlComponent_1.SqlComponent {
|
12
|
+
constructor(params) {
|
13
|
+
var _a;
|
14
|
+
super();
|
15
|
+
this.tableName = new ValueComponent_1.IdentifierString(params.tableName);
|
16
|
+
this.isTemporary = (_a = params.isTemporary) !== null && _a !== void 0 ? _a : false;
|
17
|
+
this.asSelectQuery = params.asSelectQuery;
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* Returns a SelectQuery that selects all columns from this table.
|
21
|
+
*/
|
22
|
+
getSelectQuery() {
|
23
|
+
let selectItems;
|
24
|
+
if (this.asSelectQuery) {
|
25
|
+
// Use SelectValueCollector to get columns from asSelectQuery
|
26
|
+
const collector = new SelectValueCollector_1.SelectValueCollector();
|
27
|
+
const values = collector.collect(this.asSelectQuery);
|
28
|
+
selectItems = values.map(val => new Clause_1.SelectItem(val.value, val.name));
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
// fallback: wildcard
|
32
|
+
selectItems = [new Clause_1.SelectItem(new ValueComponent_1.RawString("*"))];
|
33
|
+
}
|
34
|
+
return new SimpleSelectQuery_1.SimpleSelectQuery(null, // withClause
|
35
|
+
new Clause_1.SelectClause(selectItems), new Clause_1.FromClause(new Clause_1.SourceExpression(new Clause_1.TableSource(null, this.tableName.name), null), null // joins
|
36
|
+
), null, // whereClause
|
37
|
+
null, // groupByClause
|
38
|
+
null, // havingClause
|
39
|
+
null, // orderByClause
|
40
|
+
null, // windowFrameClause
|
41
|
+
null, // rowLimitClause
|
42
|
+
null // forClause
|
43
|
+
);
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Returns a SelectQuery that counts all rows in this table.
|
47
|
+
*/
|
48
|
+
getCountQuery() {
|
49
|
+
return new SimpleSelectQuery_1.SimpleSelectQuery(null, // withClause
|
50
|
+
new Clause_1.SelectClause([
|
51
|
+
new Clause_1.SelectItem(new ValueComponent_1.FunctionCall("count", new ValueComponent_1.ColumnReference(null, "*"), null))
|
52
|
+
]), new Clause_1.FromClause(new Clause_1.SourceExpression(new Clause_1.TableSource(null, this.tableName.name), null), null // joins
|
53
|
+
), null, // whereClause
|
54
|
+
null, // groupByClause
|
55
|
+
null, // havingClause
|
56
|
+
null, // orderByClause
|
57
|
+
null, // windowFrameClause
|
58
|
+
null, // rowLimitClause
|
59
|
+
null // forClause
|
60
|
+
);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
exports.CreateTableQuery = CreateTableQuery;
|
64
|
+
/** SqlComponent kind symbol for visitor pattern */
|
65
|
+
CreateTableQuery.kind = Symbol("CreateTableQuery");
|
66
|
+
//# sourceMappingURL=CreateTableQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"CreateTableQuery.js","sourceRoot":"","sources":["../../src/models/CreateTableQuery.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,qDAA8F;AAC9F,2DAAwD;AACxD,qCAA+F;AAC/F,+EAA4E;AAE5E,wCAAwC;AACxC,8CAA8C;AAC9C,MAAa,gBAAiB,SAAQ,2BAAY;IAU9C,YAAY,MAIX;;QACG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,WAAW,mCAAI,KAAK,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,cAAc;QACV,IAAI,WAAyB,CAAC;QAC9B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,6DAA6D;YAC7D,MAAM,SAAS,GAAG,IAAI,2CAAoB,EAAE,CAAC;YAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACrD,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,mBAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACzE,CAAC;aAAM,CAAC;YACJ,qBAAqB;YACrB,WAAW,GAAG,CAAC,IAAI,mBAAU,CAAC,IAAI,0BAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,qCAAiB,CACxB,IAAI,EAAE,aAAa;QACnB,IAAI,qBAAY,CAAC,WAAW,CAAC,EAC7B,IAAI,mBAAU,CACV,IAAI,yBAAgB,CAChB,IAAI,oBAAW,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,qCAAiB,CACxB,IAAI,EAAE,aAAa;QACnB,IAAI,qBAAY,CAAC;YACb,IAAI,mBAAU,CAAC,IAAI,6BAAY,CAAC,OAAO,EAAE,IAAI,gCAAe,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;SAClF,CAAC,EACF,IAAI,mBAAU,CACV,IAAI,yBAAgB,CAChB,IAAI,oBAAW,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;;AA/EL,4CAgFC;AA/EG,mDAAmD;AAC5C,qBAAI,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { SqlComponent } from "./SqlComponent";
|
2
|
+
import { IdentifierString } from "./ValueComponent";
|
3
|
+
import { SelectQuery } from "./SelectQuery";
|
4
|
+
export declare class InsertQuery extends SqlComponent {
|
5
|
+
static kind: symbol;
|
6
|
+
namespaces: IdentifierString[] | null;
|
7
|
+
table: IdentifierString;
|
8
|
+
columns: IdentifierString[];
|
9
|
+
selectQuery: SelectQuery | null;
|
10
|
+
/**
|
11
|
+
* @param params.table Table name (string or IdentifierString)
|
12
|
+
* @param params.columns Array of column names (string[] or IdentifierString[])
|
13
|
+
* @param params.selectQuery SELECT/VALUES query (required)
|
14
|
+
*/
|
15
|
+
constructor(params: {
|
16
|
+
namespaces: (string | IdentifierString)[] | null;
|
17
|
+
table: string | IdentifierString;
|
18
|
+
columns: (string | IdentifierString)[];
|
19
|
+
selectQuery?: SelectQuery | null;
|
20
|
+
});
|
21
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InsertQuery = void 0;
|
4
|
+
// filepath: src/models/InsertQuery.ts
|
5
|
+
// Represents an INSERT query in SQL.
|
6
|
+
// Supports single/multi-row VALUES and INSERT ... SELECT.
|
7
|
+
const SqlComponent_1 = require("./SqlComponent");
|
8
|
+
const ValueComponent_1 = require("./ValueComponent");
|
9
|
+
class InsertQuery extends SqlComponent_1.SqlComponent {
|
10
|
+
/**
|
11
|
+
* @param params.table Table name (string or IdentifierString)
|
12
|
+
* @param params.columns Array of column names (string[] or IdentifierString[])
|
13
|
+
* @param params.selectQuery SELECT/VALUES query (required)
|
14
|
+
*/
|
15
|
+
constructor(params) {
|
16
|
+
var _a;
|
17
|
+
super();
|
18
|
+
this.namespaces = params.namespaces
|
19
|
+
? params.namespaces.map(ns => typeof ns === "string" ? new ValueComponent_1.IdentifierString(ns) : ns)
|
20
|
+
: null;
|
21
|
+
this.table = typeof params.table === "string" ? new ValueComponent_1.IdentifierString(params.table) : params.table;
|
22
|
+
this.columns = params.columns.map(c => typeof c === "string" ? new ValueComponent_1.IdentifierString(c) : c);
|
23
|
+
this.selectQuery = (_a = params.selectQuery) !== null && _a !== void 0 ? _a : null;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.InsertQuery = InsertQuery;
|
27
|
+
InsertQuery.kind = Symbol("InsertQuery");
|
28
|
+
//# 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,iDAA8C;AAC9C,qDAAoE;AAGpE,MAAa,WAAY,SAAQ,2BAAY;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,iCAAgB,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,iCAAgB,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,iCAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,WAAW,mCAAI,IAAI,CAAC;IAClD,CAAC;;AAzBL,kCA0BC;AAzBU,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 type SelectQuery = SimpleSelectQuery | BinarySelectQuery | ValuesQuery;
|
5
|
-
export { SimpleSelectQuery, BinarySelectQuery, ValuesQuery };
|
5
|
+
export type SelectQuery = SimpleSelectQuery | BinarySelectQuery | ValuesQuery | InsertQuery;
|
6
|
+
export { SimpleSelectQuery, BinarySelectQuery, ValuesQuery, InsertQuery };
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ValuesQuery = exports.BinarySelectQuery = exports.SimpleSelectQuery = void 0;
|
3
|
+
exports.InsertQuery = exports.ValuesQuery = exports.BinarySelectQuery = exports.SimpleSelectQuery = void 0;
|
4
|
+
const InsertQuery_1 = require("./InsertQuery");
|
5
|
+
Object.defineProperty(exports, "InsertQuery", { enumerable: true, get: function () { return InsertQuery_1.InsertQuery; } });
|
4
6
|
const SimpleSelectQuery_1 = require("./SimpleSelectQuery");
|
5
7
|
Object.defineProperty(exports, "SimpleSelectQuery", { enumerable: true, get: function () { return SimpleSelectQuery_1.SimpleSelectQuery; } });
|
6
8
|
const BinarySelectQuery_1 = require("./BinarySelectQuery");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../src/models/SelectQuery.ts"],"names":[],"mappings":";;;AAAA,2DAAwD;AAK/C,kGALA,qCAAiB,OAKA;AAJ1B,2DAAwD;AAI5B,kGAJnB,qCAAiB,OAImB;AAH7C,+CAA4C;AAGG,4FAHtC,yBAAW,OAGsC"}
|
1
|
+
{"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../src/models/SelectQuery.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAMgB,4FANnD,yBAAW,OAMmD;AALvE,2DAAwD;AAK/C,kGALA,qCAAiB,OAKA;AAJ1B,2DAAwD;AAI5B,kGAJnB,qCAAiB,OAImB;AAH7C,+CAA4C;AAGG,4FAHtC,yBAAW,OAGsC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.IdentifierParser = void 0;
|
4
|
+
const extractNamespacesAndName_1 = require("../utils/extractNamespacesAndName");
|
4
5
|
const Lexeme_1 = require("../models/Lexeme");
|
5
6
|
const ValueComponent_1 = require("../models/ValueComponent");
|
6
7
|
class IdentifierParser {
|
@@ -24,8 +25,8 @@ class IdentifierParser {
|
|
24
25
|
}
|
25
26
|
if (identifiers.length > 1) {
|
26
27
|
// If there are multiple identifiers, treat it as a column reference
|
27
|
-
const
|
28
|
-
const value = new ValueComponent_1.ColumnReference(
|
28
|
+
const { namespaces, name } = (0, extractNamespacesAndName_1.extractNamespacesAndName)(identifiers);
|
29
|
+
const value = new ValueComponent_1.ColumnReference(namespaces, name);
|
29
30
|
return { value, newIndex: idx };
|
30
31
|
}
|
31
32
|
else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"IdentifierParser.js","sourceRoot":"","sources":["../../src/parsers/IdentifierParser.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,6DAA2E;AAE3E,MAAa,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;QAEN,sCAAsC;QACtC,8DAA8D;QAC9D,OACI,GAAG,GAAG,OAAO,CAAC,MAAM;YACpB,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM;YACxB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,kBAAS,CAAC,GAAG,CAAC;YACnC,CAAC,CAAC,OA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,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,IAAA,mDAAwB,EAAC,WAAW,CAAC,CAAC;YACnE,MAAM,KAAK,GAAG,IAAI,gCAAe,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,gCAAe,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QACpC,CAAC;IACL,CAAC;CACJ;AAnCD,4CAmCC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { InsertQuery } from "../models/InsertQuery";
|
2
|
+
import { Lexeme } from "../models/Lexeme";
|
3
|
+
export declare class InsertQueryParser {
|
4
|
+
/**
|
5
|
+
* Parse SQL string to InsertQuery AST.
|
6
|
+
* @param query SQL string
|
7
|
+
*/
|
8
|
+
static parse(query: string): InsertQuery;
|
9
|
+
/**
|
10
|
+
* Parse from lexeme array (for internal use and tests)
|
11
|
+
*/
|
12
|
+
static parseFromLexeme(lexemes: Lexeme[], index: number): {
|
13
|
+
value: InsertQuery;
|
14
|
+
newIndex: number;
|
15
|
+
};
|
16
|
+
private static parseFullQualifiedName;
|
17
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InsertQueryParser = void 0;
|
4
|
+
// filepath: src/parsers/InsertQueryParser.ts
|
5
|
+
// Provides parsing for INSERT queries, supporting optional columns and WITH/SELECT/VALUES structure.
|
6
|
+
const InsertQuery_1 = require("../models/InsertQuery");
|
7
|
+
const Lexeme_1 = require("../models/Lexeme");
|
8
|
+
const SqlTokenizer_1 = require("./SqlTokenizer");
|
9
|
+
const SelectQueryParser_1 = require("./SelectQueryParser");
|
10
|
+
const WithClauseParser_1 = require("./WithClauseParser");
|
11
|
+
const ValueComponent_1 = require("../models/ValueComponent");
|
12
|
+
const SimpleSelectQuery_1 = require("../models/SimpleSelectQuery");
|
13
|
+
const extractNamespacesAndName_1 = require("../utils/extractNamespacesAndName");
|
14
|
+
class InsertQueryParser {
|
15
|
+
/**
|
16
|
+
* Parse SQL string to InsertQuery AST.
|
17
|
+
* @param query SQL string
|
18
|
+
*/
|
19
|
+
static parse(query) {
|
20
|
+
const tokenizer = new SqlTokenizer_1.SqlTokenizer(query);
|
21
|
+
const lexemes = tokenizer.readLexmes();
|
22
|
+
const result = this.parseFromLexeme(lexemes, 0);
|
23
|
+
if (result.newIndex < lexemes.length) {
|
24
|
+
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.`);
|
25
|
+
}
|
26
|
+
return result.value;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Parse from lexeme array (for internal use and tests)
|
30
|
+
*/
|
31
|
+
static parseFromLexeme(lexemes, index) {
|
32
|
+
var _a, _b, _c;
|
33
|
+
let idx = index;
|
34
|
+
let withclause = null;
|
35
|
+
if (lexemes[idx].value === "with") {
|
36
|
+
const result = WithClauseParser_1.WithClauseParser.parseFromLexeme(lexemes, idx);
|
37
|
+
withclause = result.value;
|
38
|
+
idx = result.newIndex;
|
39
|
+
}
|
40
|
+
// Expect INSERT INTO
|
41
|
+
if (lexemes[idx].value !== "insert into") {
|
42
|
+
throw new Error(`Syntax error at position ${idx}: Expected 'INSERT INTO' but found '${lexemes[idx].value}'.`);
|
43
|
+
}
|
44
|
+
idx++;
|
45
|
+
// 完全名を取得
|
46
|
+
const { namespaces, table, newIndex: idxAfterName } = this.parseFullQualifiedName(lexemes, idx);
|
47
|
+
idx = idxAfterName;
|
48
|
+
// Optional columns
|
49
|
+
let columns = [];
|
50
|
+
if (((_a = lexemes[idx]) === null || _a === void 0 ? void 0 : _a.type) === Lexeme_1.TokenType.OpenParen) {
|
51
|
+
idx++;
|
52
|
+
while (idx < lexemes.length && lexemes[idx].type === Lexeme_1.TokenType.Identifier) {
|
53
|
+
columns.push(lexemes[idx].value);
|
54
|
+
idx++;
|
55
|
+
if (((_b = lexemes[idx]) === null || _b === void 0 ? void 0 : _b.type) === Lexeme_1.TokenType.Comma) {
|
56
|
+
idx++;
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
if (((_c = lexemes[idx]) === null || _c === void 0 ? void 0 : _c.type) !== Lexeme_1.TokenType.CloseParen) {
|
63
|
+
throw new Error(`Syntax error at position ${idx}: Expected ')' after column list.`);
|
64
|
+
}
|
65
|
+
idx++;
|
66
|
+
}
|
67
|
+
const selectResult = SelectQueryParser_1.SelectQueryParser.parseFromLexeme(lexemes, idx);
|
68
|
+
if (withclause) {
|
69
|
+
if (selectResult.value instanceof SimpleSelectQuery_1.SimpleSelectQuery) {
|
70
|
+
selectResult.value.WithClause = withclause;
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
throw new Error(`WITH clause is not supported in this context.`);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
idx = selectResult.newIndex;
|
77
|
+
return {
|
78
|
+
value: new InsertQuery_1.InsertQuery({
|
79
|
+
namespaces,
|
80
|
+
table,
|
81
|
+
columns,
|
82
|
+
selectQuery: selectResult.value
|
83
|
+
}),
|
84
|
+
newIndex: idx
|
85
|
+
};
|
86
|
+
}
|
87
|
+
// Get fully qualified name and split into namespaces/table
|
88
|
+
static parseFullQualifiedName(lexemes, index) {
|
89
|
+
let idx = index;
|
90
|
+
const fullname = [];
|
91
|
+
fullname.push(lexemes[index].value);
|
92
|
+
idx++;
|
93
|
+
while (idx < lexemes.length && lexemes[idx].type === Lexeme_1.TokenType.Dot) {
|
94
|
+
idx++; // Skip dot
|
95
|
+
if (idx < lexemes.length) {
|
96
|
+
fullname.push(lexemes[idx].value);
|
97
|
+
idx++;
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
throw new Error(`Syntax error at position ${idx}: Expected identifier after '.' but found end of input.`);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
const { namespaces, name } = (0, extractNamespacesAndName_1.extractNamespacesAndName)(fullname);
|
104
|
+
return { namespaces, table: new ValueComponent_1.IdentifierString(name), newIndex: idx };
|
105
|
+
}
|
106
|
+
}
|
107
|
+
exports.InsertQueryParser = InsertQueryParser;
|
108
|
+
//# 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,uDAAoD;AACpD,6CAAqD;AACrD,iDAA8C;AAC9C,2DAAwD;AAExD,yDAAsD;AACtD,6DAA4D;AAC5D,mEAAgE;AAChE,gFAA6E;AAE7E,MAAa,iBAAiB;IAC1B;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,2BAAY,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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MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,kBAAS,CAAC,GAAG,EAAE,CAAC;YACjE,GAAG,EAAE,CAAC,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,IAAA,mDAAwB,EAAC,QAAQ,CAAC,CAAC;QAChE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,iCAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IAC5E,CAAC;CACJ;AAhGD,8CAgGC"}
|
@@ -5,8 +5,17 @@ const ValueComponent_1 = require("../models/ValueComponent");
|
|
5
5
|
class ParameterExpressionParser {
|
6
6
|
static parseFromLexeme(lexemes, index) {
|
7
7
|
let idx = index;
|
8
|
-
|
9
|
-
|
8
|
+
let paramName = lexemes[idx].value;
|
9
|
+
// Normalize parameter: Remove the parameter symbol and extract the parameter name.
|
10
|
+
if (paramName.startsWith('${') && paramName.endsWith('}')) {
|
11
|
+
// ${name} → name
|
12
|
+
paramName = paramName.slice(2, -1);
|
13
|
+
}
|
14
|
+
else {
|
15
|
+
// :name → name
|
16
|
+
paramName = paramName.slice(1);
|
17
|
+
}
|
18
|
+
const value = new ValueComponent_1.ParameterExpression(paramName);
|
10
19
|
idx++;
|
11
20
|
return { value, newIndex: idx };
|
12
21
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ParameterExpressionParser.js","sourceRoot":"","sources":["../../src/parsers/ParameterExpressionParser.ts"],"names":[],"mappings":";;;AACA,6DAA+E;AAE/E,MAAa,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,6DAA+E;AAE/E,MAAa,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,oCAAmB,CAAC,SAAS,CAAC,CAAC;QACjD,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IACpC,CAAC;CACJ;AAlBD,8DAkBC"}
|
@@ -32,7 +32,7 @@ class SelectQueryParser {
|
|
32
32
|
const result = this.parseFromLexeme(lexemes, 0);
|
33
33
|
// Error if there are remaining tokens
|
34
34
|
if (result.newIndex < lexemes.length) {
|
35
|
-
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.`);
|
35
|
+
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.`);
|
36
36
|
}
|
37
37
|
return result.value;
|
38
38
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SelectQueryParser.js","sourceRoot":"","sources":["../../src/parsers/SelectQueryParser.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAA0F;AAC1F,6DAA0D;AAC1D,yDAAsD;AACtD,2DAAwD;AACxD,mDAAsD;AACtD,iDAAoD;AACpD,+DAA4D;AAC5D,6DAA0D;AAC1D,2DAAwD;AACxD,uDAAoD;AACpD,iDAA8C;AAC9C,yDAAsD;AACtD,2DAAwD;AAExD,MAAa,iBAAiB;IAC1B,uCAAuC;IAChC,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,2BAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QAEvC,QAAQ;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAEhD,sCAAsC;QACtC,IAAI,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,
|
1
|
+
{"version":3,"file":"SelectQueryParser.js","sourceRoot":"","sources":["../../src/parsers/SelectQueryParser.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAA0F;AAC1F,6DAA0D;AAC1D,yDAAsD;AACtD,2DAAwD;AACxD,mDAAsD;AACtD,iDAAoD;AACpD,+DAA4D;AAC5D,6DAA0D;AAC1D,2DAAwD;AACxD,uDAAoD;AACpD,iDAA8C;AAC9C,yDAAsD;AACtD,2DAAwD;AAExD,MAAa,iBAAiB;IAC1B,uCAAuC;IAChC,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,2BAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,SAAS,CAAC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AAW;IACX,WAAW;IACX,eAAe;IACf,QAAQ;IACR,YAAY;CACf,CAAC,CAAC;AACY,kCAAgB,GAAG,IAAI,GAAG,CAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC"}
|
@@ -6,6 +6,8 @@ const Lexeme_1 = require("../models/Lexeme");
|
|
6
6
|
const SelectQueryParser_1 = require("./SelectQueryParser");
|
7
7
|
const SqlTokenizer_1 = require("./SqlTokenizer");
|
8
8
|
const ValueParser_1 = require("./ValueParser");
|
9
|
+
const extractNamespacesAndName_1 = require("../utils/extractNamespacesAndName");
|
10
|
+
const parseEscapedOrDotSeparatedIdentifiers_1 = require("../utils/parseEscapedOrDotSeparatedIdentifiers");
|
9
11
|
class SourceParser {
|
10
12
|
// Parse SQL string to AST (was: parse)
|
11
13
|
static parse(query) {
|
@@ -34,33 +36,13 @@ class SourceParser {
|
|
34
36
|
return this.parseTableSource(lexemes, idx);
|
35
37
|
}
|
36
38
|
static parseTableSource(lexemes, index) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
// Add the first identifier
|
41
|
-
identifiers.push(lexemes[idx].value);
|
42
|
-
idx++;
|
43
|
-
// Look for dot and identifier pattern
|
44
|
-
while (idx < lexemes.length &&
|
45
|
-
idx + 1 < lexemes.length &&
|
46
|
-
(lexemes[idx].type & Lexeme_1.TokenType.Dot) &&
|
47
|
-
(lexemes[idx + 1].type & Lexeme_1.TokenType.Identifier)) {
|
48
|
-
// Skip the dot and add the next identifier
|
49
|
-
idx++;
|
50
|
-
identifiers.push(lexemes[idx].value);
|
51
|
-
idx++;
|
52
|
-
}
|
53
|
-
if (identifiers.length > 1) {
|
54
|
-
// If there are multiple identifiers, treat it as a column reference
|
55
|
-
const lastIdentifier = identifiers.pop() || '';
|
56
|
-
const value = new Clause_1.TableSource(identifiers, lastIdentifier);
|
57
|
-
return { value, newIndex: idx };
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
// If there is a single identifier, treat it as a simple identifier
|
61
|
-
const value = new Clause_1.TableSource(null, identifiers[0]);
|
62
|
-
return { value, newIndex: idx };
|
39
|
+
const { identifiers, newIndex } = (0, parseEscapedOrDotSeparatedIdentifiers_1.parseEscapedOrDotSeparatedIdentifiers)(lexemes, index);
|
40
|
+
if (identifiers.length === 0) {
|
41
|
+
throw new Error(`No table identifier found at position ${index}`);
|
63
42
|
}
|
43
|
+
const { namespaces, name } = (0, extractNamespacesAndName_1.extractNamespacesAndName)(identifiers);
|
44
|
+
const value = new Clause_1.TableSource(namespaces, name);
|
45
|
+
return { value, newIndex };
|
64
46
|
}
|
65
47
|
static parseFunctionSource(lexemes, index) {
|
66
48
|
let idx = index;
|