rawsql-ts 0.8.3-beta → 0.10.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 +204 -438
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models/SqlPrintToken.js +2 -0
- package/dist/esm/models/SqlPrintToken.js.map +1 -1
- package/dist/esm/models/ValueComponent.js +14 -13
- package/dist/esm/models/ValueComponent.js.map +1 -1
- package/dist/esm/parsers/SqlPrintTokenParser.js +22 -6
- package/dist/esm/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/transformers/PostgreJsonQueryBuilder.js +215 -0
- package/dist/esm/transformers/PostgreJsonQueryBuilder.js.map +1 -0
- package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js +231 -0
- package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js.map +1 -0
- package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js +283 -0
- package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js.map +1 -0
- package/dist/esm/transformers/SelectableColumnCollector.js +4 -1
- package/dist/esm/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/transformers/SqlParamInjector.js +133 -0
- package/dist/esm/transformers/SqlParamInjector.js.map +1 -0
- package/dist/esm/transformers/SqlPrinter.js +9 -3
- package/dist/esm/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/transformers/UpstreamSelectQueryFinder.js +10 -6
- package/dist/esm/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/models/SqlPrintToken.d.ts +2 -0
- package/dist/esm/types/models/ValueComponent.d.ts +3 -3
- package/dist/esm/types/transformers/PostgreJsonQueryBuilder.d.ts +78 -0
- package/dist/esm/types/transformers/PostgresArrayEntityCteBuilder.d.ts +97 -0
- package/dist/esm/types/transformers/PostgresObjectEntityCteBuilder.d.ts +140 -0
- package/dist/esm/types/transformers/SelectableColumnCollector.d.ts +6 -1
- package/dist/esm/types/transformers/SqlParamInjector.d.ts +36 -0
- package/dist/esm/types/transformers/UpstreamSelectQueryFinder.d.ts +6 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/models/SqlPrintToken.d.ts +2 -0
- package/dist/models/SqlPrintToken.js +2 -0
- package/dist/models/SqlPrintToken.js.map +1 -1
- package/dist/models/ValueComponent.d.ts +3 -3
- package/dist/models/ValueComponent.js +14 -13
- package/dist/models/ValueComponent.js.map +1 -1
- package/dist/parsers/SelectQueryParser.js +3 -14
- package/dist/parsers/SelectQueryParser.js.map +1 -1
- package/dist/parsers/SqlPrintTokenParser.js +23 -7
- package/dist/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/transformers/PostgreJsonQueryBuilder.d.ts +78 -0
- package/dist/transformers/PostgreJsonQueryBuilder.js +219 -0
- package/dist/transformers/PostgreJsonQueryBuilder.js.map +1 -0
- package/dist/transformers/PostgresArrayEntityCteBuilder.d.ts +97 -0
- package/dist/transformers/PostgresArrayEntityCteBuilder.js +235 -0
- package/dist/transformers/PostgresArrayEntityCteBuilder.js.map +1 -0
- package/dist/transformers/PostgresObjectEntityCteBuilder.d.ts +140 -0
- package/dist/transformers/PostgresObjectEntityCteBuilder.js +287 -0
- package/dist/transformers/PostgresObjectEntityCteBuilder.js.map +1 -0
- package/dist/transformers/SelectableColumnCollector.d.ts +6 -1
- package/dist/transformers/SelectableColumnCollector.js +4 -1
- package/dist/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/transformers/SqlFormatter.js +6 -1
- package/dist/transformers/SqlFormatter.js.map +1 -1
- package/dist/transformers/SqlParamInjector.d.ts +36 -0
- package/dist/transformers/SqlParamInjector.js +137 -0
- package/dist/transformers/SqlParamInjector.js.map +1 -0
- package/dist/transformers/SqlPrinter.js +9 -3
- package/dist/transformers/SqlPrinter.js.map +1 -1
- package/dist/transformers/UpstreamSelectQueryFinder.d.ts +6 -3
- package/dist/transformers/UpstreamSelectQueryFinder.js +10 -6
- package/dist/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/types/utils/SqlStaticAnalyzer.d.ts +0 -0
- package/dist/esm/utils/SqlStaticAnalyzer.js +0 -2
- package/dist/esm/utils/SqlStaticAnalyzer.js.map +0 -1
- package/dist/utils/SqlStaticAnalyzer.d.ts +0 -0
- package/dist/utils/SqlStaticAnalyzer.js +0 -2
- package/dist/utils/SqlStaticAnalyzer.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"UpstreamSelectQueryFinder.js","sourceRoot":"","sources":["../../../src/transformers/UpstreamSelectQueryFinder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAe,cAAc,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;
|
1
|
+
{"version":3,"file":"UpstreamSelectQueryFinder.js","sourceRoot":"","sources":["../../../src/transformers/UpstreamSelectQueryFinder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAe,cAAc,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAKlC,YAAY,mBAAqD,EAAE,OAA+C;QAC9G,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;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AAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClG,IAAI,MAAM,EAAE,CAAC;gBACT,OAAO,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;YACD,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;YAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAChE,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAClE,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;CACJ"}
|
@@ -8,6 +8,7 @@ export * from './transformers/CTECollector';
|
|
8
8
|
export * from './transformers/CTENormalizer';
|
9
9
|
export * from './transformers/Formatter';
|
10
10
|
export * from './transformers/SqlFormatter';
|
11
|
+
export * from './transformers/PostgreJsonQueryBuilder';
|
11
12
|
export * from './transformers/QueryBuilder';
|
12
13
|
export * from './transformers/SelectValueCollector';
|
13
14
|
export * from './transformers/SelectableColumnCollector';
|
@@ -15,4 +16,5 @@ export * from './transformers/TableColumnResolver';
|
|
15
16
|
export * from './transformers/TableSourceCollector';
|
16
17
|
export * from './transformers/UpstreamSelectQueryFinder';
|
17
18
|
export * from './transformers/SchemaCollector';
|
19
|
+
export * from './transformers/SqlParamInjector';
|
18
20
|
export * from './utils/SqlSchemaValidator';
|
@@ -27,6 +27,8 @@ export declare enum SqlPrintTokenContainerType {
|
|
27
27
|
SwitchCaseArgument = "SwitchCaseArgument",
|
28
28
|
ElseClause = "ElseClause",
|
29
29
|
CaseKeyValuePair = "CaseKeyValuePair",
|
30
|
+
CaseThenValue = "CaseThenValue",
|
31
|
+
CaseElseValue = "CaseElseValue",
|
30
32
|
ParenExpression = "ParenExpression",
|
31
33
|
CastExpression = "CastExpression",
|
32
34
|
CaseExpression = "CaseExpression",
|
@@ -32,7 +32,7 @@ export declare class FunctionCall extends SqlComponent {
|
|
32
32
|
qualifiedName: QualifiedName;
|
33
33
|
argument: ValueComponent | null;
|
34
34
|
over: OverExpression | null;
|
35
|
-
constructor(namespaces: string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument: ValueComponent | null, over: OverExpression | null);
|
35
|
+
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument: ValueComponent | null, over: OverExpression | null);
|
36
36
|
/**
|
37
37
|
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
|
38
38
|
*/
|
@@ -103,7 +103,7 @@ export declare class ParameterExpression extends SqlComponent {
|
|
103
103
|
value: any | null;
|
104
104
|
/**
|
105
105
|
* The index assigned by the formatter when generating parameterized queries.
|
106
|
-
*
|
106
|
+
* Used for naming parameters like $1, $2, etc.
|
107
107
|
*/
|
108
108
|
index: number | null;
|
109
109
|
constructor(name: string, value?: any | null);
|
@@ -195,7 +195,7 @@ export declare class QualifiedName extends SqlComponent {
|
|
195
195
|
namespaces: IdentifierString[] | null;
|
196
196
|
/** The actual name (e.g. table, function, type, column) */
|
197
197
|
name: RawString | IdentifierString;
|
198
|
-
constructor(namespaces: string[] | IdentifierString[] | null, name: string | RawString | IdentifierString);
|
198
|
+
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString);
|
199
199
|
/** Returns the full qualified name as a string (dot-separated) */
|
200
200
|
toString(): string;
|
201
201
|
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { SimpleSelectQuery } from '../models/SimpleSelectQuery';
|
2
|
+
/**
|
3
|
+
* Universal JSON mapping definition for creating any level of JSON structures.
|
4
|
+
* Supports flat arrays, nested objects, and unlimited hierarchical structures.
|
5
|
+
*/
|
6
|
+
export interface JsonMapping {
|
7
|
+
rootName: string;
|
8
|
+
rootEntity: {
|
9
|
+
id: string;
|
10
|
+
name: string;
|
11
|
+
columns: {
|
12
|
+
[jsonKey: string]: string;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
nestedEntities: Array<{
|
16
|
+
id: string;
|
17
|
+
name: string;
|
18
|
+
parentId: string;
|
19
|
+
propertyName: string;
|
20
|
+
relationshipType?: "object" | "array";
|
21
|
+
columns: {
|
22
|
+
[jsonKey: string]: string;
|
23
|
+
};
|
24
|
+
}>;
|
25
|
+
useJsonb?: boolean;
|
26
|
+
resultFormat?: "array" | "single";
|
27
|
+
emptyResult?: string;
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* PostgreSQL JSON query builder that transforms SimpleSelectQuery into queries
|
31
|
+
* that return JSON arrays or single JSON objects using PostgreSQL JSON functions.
|
32
|
+
*/
|
33
|
+
export declare class PostgreJsonQueryBuilder {
|
34
|
+
private selectValueCollector;
|
35
|
+
private objectEntityCteBuilder;
|
36
|
+
private arrayEntityCteBuilder;
|
37
|
+
constructor();
|
38
|
+
/**
|
39
|
+
* Validates the JSON mapping and the original query.
|
40
|
+
* @param query Original query to transform
|
41
|
+
* @param mapping JSON mapping configuration
|
42
|
+
*/
|
43
|
+
private validateMapping;
|
44
|
+
/**
|
45
|
+
* Build JSON query from original query and mapping configuration.
|
46
|
+
* @param originalQuery Original query to transform
|
47
|
+
* @param mapping JSON mapping configuration
|
48
|
+
* @returns Transformed query with JSON aggregation
|
49
|
+
*/
|
50
|
+
buildJson(originalQuery: SimpleSelectQuery, mapping: JsonMapping): SimpleSelectQuery;
|
51
|
+
/**
|
52
|
+
* Builds the JSON structure using a unified CTE-based strategy.
|
53
|
+
* @param originalQuery Original query
|
54
|
+
* @param mapping JSON mapping configuration
|
55
|
+
* @returns Query with CTE-based JSON aggregation
|
56
|
+
*/
|
57
|
+
private buildJsonWithCteStrategy;
|
58
|
+
/**
|
59
|
+
* Creates the initial Common Table Expression (CTE) from the original query.
|
60
|
+
* @param originalQuery The base SimpleSelectQuery.
|
61
|
+
* @returns An object containing the initial CTE and its alias.
|
62
|
+
*/
|
63
|
+
private createInitialCte;
|
64
|
+
/**
|
65
|
+
* Builds the final SELECT query that constructs the root JSON object (or array of objects).
|
66
|
+
* This query uses all previously generated CTEs.
|
67
|
+
* @param finalCtesList The complete list of all CTEs (initial and array CTEs).
|
68
|
+
* @param lastCteAliasForFromClause Alias of the final CTE from which the root object will be built.
|
69
|
+
* @param allEntities Map of all processable entities.
|
70
|
+
* @param mapping JSON mapping configuration.
|
71
|
+
* @returns The final SimpleSelectQuery.
|
72
|
+
*/
|
73
|
+
private buildFinalSelectQuery;
|
74
|
+
/**
|
75
|
+
* Build JSON object for entity, using parent JSON columns when available
|
76
|
+
*/
|
77
|
+
private buildEntityJsonObject;
|
78
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { CommonTable } from '../models/Clause';
|
2
|
+
import { JsonMapping } from './PostgreJsonQueryBuilder';
|
3
|
+
import { ProcessableEntity } from './PostgresObjectEntityCteBuilder';
|
4
|
+
/**
|
5
|
+
* PostgreSQL-specific builder for creating CTEs for array entities (array relationships).
|
6
|
+
* This class handles the creation of CTEs that build JSON/JSONB arrays for child entities,
|
7
|
+
* processing them from the deepest level up to ensure proper dependency ordering.
|
8
|
+
*
|
9
|
+
* Features:
|
10
|
+
* - Depth-based CTE naming (cte_array_depth_N)
|
11
|
+
* - Row compression using GROUP BY operations
|
12
|
+
* - JSONB/JSON array aggregation
|
13
|
+
* - Hierarchical processing of nested arrays
|
14
|
+
* - Column exclusion to avoid duplication
|
15
|
+
*
|
16
|
+
* Why depth calculation is critical:
|
17
|
+
* 1. Array entities can be nested at multiple levels. We must process the deepest
|
18
|
+
* (most distant) arrays first to ensure their JSON representations are available
|
19
|
+
* when building their parent arrays.
|
20
|
+
* 2. Array entity processing is essentially a row compression operation using GROUP BY.
|
21
|
+
* Unlike parent entities which use column compression, arrays require grouping
|
22
|
+
* to aggregate multiple rows into JSON arrays.
|
23
|
+
*
|
24
|
+
* Example hierarchy:
|
25
|
+
* Order (root, depth 0)
|
26
|
+
* └─ Items (array, depth 1)
|
27
|
+
* └─ Details (array, depth 2)
|
28
|
+
*
|
29
|
+
* Processing order: depth 2 → depth 1 → depth 0
|
30
|
+
*/
|
31
|
+
export declare class PostgresArrayEntityCteBuilder {
|
32
|
+
private static readonly CTE_ARRAY_PREFIX;
|
33
|
+
/**
|
34
|
+
* Build CTEs for all array entities in the correct dependency order
|
35
|
+
* @param ctesSoFar Array of CTEs built so far (starts with the initial CTE)
|
36
|
+
* @param aliasOfCteToBuildUpon Alias of the CTE from which the current array CTE will select
|
37
|
+
* @param allEntities Map of all entities in the mapping
|
38
|
+
* @param mapping The JSON mapping configuration
|
39
|
+
* @returns Object containing the updated list of all CTEs and the alias of the last CTE created
|
40
|
+
*/
|
41
|
+
buildArrayEntityCtes(ctesSoFar: CommonTable[], aliasOfCteToBuildUpon: string, allEntities: Map<string, ProcessableEntity>, mapping: JsonMapping): {
|
42
|
+
updatedCtes: CommonTable[];
|
43
|
+
lastCteAlias: string;
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Collect all array entities and calculate their depth from root.
|
47
|
+
*
|
48
|
+
* Depth calculation ensures proper processing order where deeper nested
|
49
|
+
* arrays are processed first, making their aggregated data available
|
50
|
+
* for parent array processing.
|
51
|
+
*
|
52
|
+
* @param mapping The JSON mapping configuration
|
53
|
+
* @param allEntities Map of all entities in the mapping
|
54
|
+
* @returns Array of array entity information with calculated depths, sorted deepest first
|
55
|
+
*/
|
56
|
+
private collectAndSortArrayEntities;
|
57
|
+
/**
|
58
|
+
* Group array entities by their depth level.
|
59
|
+
*
|
60
|
+
* Grouping by depth allows us to:
|
61
|
+
* - Process all entities at the same level in a single CTE
|
62
|
+
* - Optimize query performance by reducing the number of CTEs
|
63
|
+
* - Maintain clear dependency ordering
|
64
|
+
*
|
65
|
+
* @param arrayInfos Array of array entity information with depths
|
66
|
+
* @returns Map of depth level to entities at that depth
|
67
|
+
*/
|
68
|
+
private groupEntitiesByDepth;
|
69
|
+
/**
|
70
|
+
* Build a CTE that processes all array entities at a specific depth level.
|
71
|
+
*
|
72
|
+
* This method creates a single CTE that aggregates multiple array entities
|
73
|
+
* at the same depth, using GROUP BY to compress rows into JSON arrays.
|
74
|
+
*
|
75
|
+
* @param infos Array entities at this depth level
|
76
|
+
* @param currentCteAlias Alias of the CTE to build upon
|
77
|
+
* @param currentCtes All CTEs built so far
|
78
|
+
* @param depth Current depth level being processed
|
79
|
+
* @param mapping JSON mapping configuration
|
80
|
+
* @returns The new CTE and its alias
|
81
|
+
*/
|
82
|
+
private buildDepthCte;
|
83
|
+
/**
|
84
|
+
* Build JSON aggregation function for an array entity.
|
85
|
+
*
|
86
|
+
* This method creates a jsonb_agg or json_agg function call that aggregates
|
87
|
+
* the entity's columns into a JSON array. It also handles nested relationships
|
88
|
+
* by including child entity properties in the JSON object.
|
89
|
+
*
|
90
|
+
* @param entity The array entity being processed
|
91
|
+
* @param nestedEntities All nested entities from the mapping
|
92
|
+
* @param allEntities Map of all entities (not used in current implementation)
|
93
|
+
* @param useJsonb Whether to use JSONB functions
|
94
|
+
* @returns Object containing the JSON aggregation function
|
95
|
+
*/
|
96
|
+
private buildAggregationDetailsForArrayEntity;
|
97
|
+
}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import { CommonTable } from '../models/Clause';
|
2
|
+
import { JsonMapping } from './PostgreJsonQueryBuilder';
|
3
|
+
/**
|
4
|
+
* Entity with processing metadata
|
5
|
+
*/
|
6
|
+
export interface ProcessableEntity {
|
7
|
+
id: string;
|
8
|
+
name: string;
|
9
|
+
columns: {
|
10
|
+
[jsonKey: string]: string;
|
11
|
+
};
|
12
|
+
isRoot: boolean;
|
13
|
+
propertyName: string;
|
14
|
+
parentId?: string;
|
15
|
+
relationshipType?: "object" | "array";
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
* PostgreSQL-specific builder for creating CTEs for object entities (object relationships).
|
19
|
+
* This class handles the creation of CTEs that build JSON/JSONB objects for object entities,
|
20
|
+
* processing them from the deepest level up to ensure proper dependency ordering.
|
21
|
+
*
|
22
|
+
* Features:
|
23
|
+
* - Depth-based CTE naming (cte_object_depth_N)
|
24
|
+
* - NULL handling for entity columns
|
25
|
+
* - JSONB/JSON object construction
|
26
|
+
* - Hierarchical processing of nested objects
|
27
|
+
*
|
28
|
+
* Why depth calculation is critical:
|
29
|
+
* 1. Object entities can be nested at multiple levels. We must process the deepest
|
30
|
+
* (most distant) objects first to ensure their JSON representations are available
|
31
|
+
* when building their parent entities.
|
32
|
+
* 2. Object entity processing is essentially a column compression operation. Entities
|
33
|
+
* at the same depth level can be processed simultaneously since they don't depend
|
34
|
+
* on each other.
|
35
|
+
*
|
36
|
+
* Example hierarchy:
|
37
|
+
* Order (root, depth 0)
|
38
|
+
* └─ Customer (depth 1)
|
39
|
+
* └─ Address (depth 2)
|
40
|
+
* └─ Shipping (depth 1)
|
41
|
+
* └─ Carrier (depth 2)
|
42
|
+
*
|
43
|
+
* Processing order: depth 2 → depth 1 → depth 0
|
44
|
+
*/
|
45
|
+
export declare class PostgresObjectEntityCteBuilder {
|
46
|
+
private static readonly JSON_COLUMN_SUFFIX;
|
47
|
+
private static readonly CTE_OBJECT_PREFIX;
|
48
|
+
private static readonly WILDCARD_COLUMN; /**
|
49
|
+
* Build CTEs for all object entities in the correct dependency order
|
50
|
+
* @param initialCte The starting CTE containing all raw data
|
51
|
+
* @param allEntities Map of all entities in the mapping
|
52
|
+
* @param mapping The JSON mapping configuration
|
53
|
+
* @returns Array of CTEs and the alias of the last CTE created
|
54
|
+
*/
|
55
|
+
buildObjectEntityCtes(initialCte: CommonTable, allEntities: Map<string, ProcessableEntity>, mapping: JsonMapping): {
|
56
|
+
ctes: CommonTable[];
|
57
|
+
lastCteAlias: string;
|
58
|
+
}; /**
|
59
|
+
* Collect all object entities and calculate their depth from root.
|
60
|
+
*
|
61
|
+
* Depth calculation is crucial because:
|
62
|
+
* - It determines the processing order (deepest first)
|
63
|
+
* - It ensures dependencies are resolved before an entity is processed
|
64
|
+
* - It allows parallel processing of entities at the same depth level
|
65
|
+
*
|
66
|
+
* @param mapping The JSON mapping configuration
|
67
|
+
* @param allEntities Map of all entities in the mapping
|
68
|
+
* @returns Array of object entity information with calculated depths
|
69
|
+
*/
|
70
|
+
private collectAndSortObjectEntities;
|
71
|
+
/**
|
72
|
+
* Group entities by their depth level.
|
73
|
+
*
|
74
|
+
* Grouping by depth allows us to:
|
75
|
+
* - Process all entities at the same level in a single CTE
|
76
|
+
* - Optimize query performance by reducing the number of CTEs
|
77
|
+
* - Maintain clear dependency ordering
|
78
|
+
*
|
79
|
+
* @param parentInfos Array of parent entity information with depths
|
80
|
+
* @returns Map of depth level to entities at that depth
|
81
|
+
*/ private groupEntitiesByDepth;
|
82
|
+
/**
|
83
|
+
* Build a CTE that processes all entities at a specific depth level
|
84
|
+
*/
|
85
|
+
private buildDepthCte;
|
86
|
+
/**
|
87
|
+
* Build JSON column for a single entity with NULL handling
|
88
|
+
*/
|
89
|
+
private buildEntityJsonColumn;
|
90
|
+
/**
|
91
|
+
* Prepare entity columns and NULL checks.
|
92
|
+
*
|
93
|
+
* This method extracts column data and creates NULL checks for each column.
|
94
|
+
* The NULL checking is essential for handling outer joins correctly.
|
95
|
+
*
|
96
|
+
* In outer join scenarios, when there's no matching row in the joined table,
|
97
|
+
* all columns from that table will be NULL. Instead of creating an empty object
|
98
|
+
* with all NULL properties (e.g., {id: null, name: null, email: null}),
|
99
|
+
* we want to represent the absence of the entity as NULL itself.
|
100
|
+
*
|
101
|
+
* This ensures cleaner JSON output where missing relationships are represented
|
102
|
+
* as NULL rather than objects with all NULL fields.
|
103
|
+
*
|
104
|
+
* @param entity The entity whose columns are being processed
|
105
|
+
* @returns Object containing arrays of JSON object arguments and NULL check conditions
|
106
|
+
*/
|
107
|
+
private prepareEntityColumns;
|
108
|
+
/**
|
109
|
+
* Add child object relationships to JSON object arguments.
|
110
|
+
*
|
111
|
+
* This method processes nested object-type entities that are direct children of the current entity.
|
112
|
+
* For each child entity, it adds the property name and corresponding JSON column reference
|
113
|
+
* to the arguments array that will be used to build the parent's JSON object.
|
114
|
+
*
|
115
|
+
* The child JSON columns are expected to already exist in the data source (created by deeper
|
116
|
+
* level CTEs), as we process from the deepest level up to the root.
|
117
|
+
*
|
118
|
+
* Note: In this context, "child" refers to entities that have an object relationship (0..1)
|
119
|
+
* with their parent. From a data perspective, these are typically entities referenced via
|
120
|
+
* foreign keys, representing "parent" entities in traditional database terminology.
|
121
|
+
*
|
122
|
+
* @param entity The current entity being processed
|
123
|
+
* @param jsonObjectArgs Array to which JSON object arguments will be added
|
124
|
+
* @param mapping The JSON mapping configuration
|
125
|
+
* @param allEntities Map of all entities in the mapping
|
126
|
+
*/
|
127
|
+
private addChildObjectRelationships;
|
128
|
+
/**
|
129
|
+
* Create JSON object function call
|
130
|
+
*/
|
131
|
+
private createJsonObject;
|
132
|
+
/**
|
133
|
+
* Build NULL condition from NULL checks
|
134
|
+
*/
|
135
|
+
private buildNullCondition;
|
136
|
+
/**
|
137
|
+
* Create CASE expression with NULL handling
|
138
|
+
*/
|
139
|
+
private createCaseExpression;
|
140
|
+
}
|
@@ -37,14 +37,19 @@ export declare class SelectableColumnCollector implements SqlComponentVisitor<vo
|
|
37
37
|
private commonTables;
|
38
38
|
private includeWildCard;
|
39
39
|
private duplicateDetection;
|
40
|
+
private options;
|
40
41
|
/**
|
41
42
|
* Creates a new instance of SelectableColumnCollector.
|
42
43
|
*
|
43
44
|
* @param {TableColumnResolver | null} [tableColumnResolver=null] - The resolver used to resolve column references to their respective tables.
|
44
45
|
* @param {boolean} [includeWildCard=false] - If true, wildcard columns (e.g., `*`) are included in the collection.
|
45
46
|
* @param {DuplicateDetectionMode} [duplicateDetection=DuplicateDetectionMode.ColumnNameOnly] - Specifies the duplicate detection mode: 'columnNameOnly' (default, only column name is used), or 'fullName' (table name + column name).
|
47
|
+
* @param {Object} [options={}] - Additional options for the collector.
|
48
|
+
* @param {boolean} [options.ignoreCaseAndUnderscore=false] - If true, column names are compared without considering case and underscores.
|
46
49
|
*/
|
47
|
-
constructor(tableColumnResolver?: TableColumnResolver | null, includeWildCard?: boolean, duplicateDetection?: DuplicateDetectionMode
|
50
|
+
constructor(tableColumnResolver?: TableColumnResolver | null, includeWildCard?: boolean, duplicateDetection?: DuplicateDetectionMode, options?: {
|
51
|
+
ignoreCaseAndUnderscore?: boolean;
|
52
|
+
});
|
48
53
|
getValues(): {
|
49
54
|
name: string;
|
50
55
|
value: ValueComponent;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
2
|
+
/**
|
3
|
+
* SqlParamInjector injects state parameters into a SelectQuery model,
|
4
|
+
* creating WHERE conditions and setting parameter values.
|
5
|
+
*/
|
6
|
+
export declare class SqlParamInjector {
|
7
|
+
private tableColumnResolver?;
|
8
|
+
private options;
|
9
|
+
constructor(optionsOrResolver?: {
|
10
|
+
ignoreCaseAndUnderscore?: boolean;
|
11
|
+
} | ((tableName: string) => string[]), options?: {
|
12
|
+
ignoreCaseAndUnderscore?: boolean;
|
13
|
+
});
|
14
|
+
/**
|
15
|
+
* Injects parameters as WHERE conditions into the given query model.
|
16
|
+
* @param query The SelectQuery to modify
|
17
|
+
* @param state A record of parameter names and values
|
18
|
+
* @returns The modified SelectQuery
|
19
|
+
*/
|
20
|
+
inject(query: SimpleSelectQuery | string, state: Record<string, number | string | boolean | Date | null | undefined | Condition>): SelectQuery;
|
21
|
+
}
|
22
|
+
type Condition = {
|
23
|
+
'='?: number | string | boolean | Date;
|
24
|
+
min?: number | string | Date;
|
25
|
+
max?: number | string | Date;
|
26
|
+
like?: string;
|
27
|
+
in?: (number | string | Date)[];
|
28
|
+
any?: (number | string | Date)[];
|
29
|
+
'<'?: number | string | Date;
|
30
|
+
'>'?: number | string | Date;
|
31
|
+
'!='?: number | string | boolean | Date;
|
32
|
+
'<>'?: number | string | boolean | Date;
|
33
|
+
'<='?: number | string | Date;
|
34
|
+
'>='?: number | string | Date;
|
35
|
+
};
|
36
|
+
export {};
|
@@ -6,16 +6,19 @@ import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
|
6
6
|
* For UNION queries, it checks each branch independently.
|
7
7
|
*/
|
8
8
|
export declare class UpstreamSelectQueryFinder {
|
9
|
+
private options;
|
9
10
|
private tableColumnResolver?;
|
10
11
|
private columnCollector;
|
11
|
-
constructor(tableColumnResolver?: (tableName: string) => string[]
|
12
|
+
constructor(tableColumnResolver?: (tableName: string) => string[], options?: {
|
13
|
+
ignoreCaseAndUnderscore?: boolean;
|
14
|
+
});
|
12
15
|
/**
|
13
16
|
* Finds the highest SelectQuery containing all specified columns.
|
14
17
|
* @param query The root SelectQuery to search.
|
15
|
-
* @param columnNames
|
18
|
+
* @param columnNames A column name or array of column names to check for.
|
16
19
|
* @returns An array of SelectQuery objects, or an empty array if not found.
|
17
20
|
*/
|
18
|
-
find(query: SelectQuery, columnNames: string[]): SimpleSelectQuery[];
|
21
|
+
find(query: SelectQuery, columnNames: string | string[]): SimpleSelectQuery[];
|
19
22
|
private handleTableSource;
|
20
23
|
private handleSubQuerySource;
|
21
24
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -8,6 +8,7 @@ export * from './transformers/CTECollector';
|
|
8
8
|
export * from './transformers/CTENormalizer';
|
9
9
|
export * from './transformers/Formatter';
|
10
10
|
export * from './transformers/SqlFormatter';
|
11
|
+
export * from './transformers/PostgreJsonQueryBuilder';
|
11
12
|
export * from './transformers/QueryBuilder';
|
12
13
|
export * from './transformers/SelectValueCollector';
|
13
14
|
export * from './transformers/SelectableColumnCollector';
|
@@ -15,4 +16,5 @@ export * from './transformers/TableColumnResolver';
|
|
15
16
|
export * from './transformers/TableSourceCollector';
|
16
17
|
export * from './transformers/UpstreamSelectQueryFinder';
|
17
18
|
export * from './transformers/SchemaCollector';
|
19
|
+
export * from './transformers/SqlParamInjector';
|
18
20
|
export * from './utils/SqlSchemaValidator';
|
package/dist/index.js
CHANGED
@@ -25,6 +25,7 @@ __exportStar(require("./transformers/CTECollector"), exports);
|
|
25
25
|
__exportStar(require("./transformers/CTENormalizer"), exports);
|
26
26
|
__exportStar(require("./transformers/Formatter"), exports);
|
27
27
|
__exportStar(require("./transformers/SqlFormatter"), exports);
|
28
|
+
__exportStar(require("./transformers/PostgreJsonQueryBuilder"), exports);
|
28
29
|
__exportStar(require("./transformers/QueryBuilder"), exports); // old name:QueryConverter
|
29
30
|
__exportStar(require("./transformers/SelectValueCollector"), exports);
|
30
31
|
__exportStar(require("./transformers/SelectableColumnCollector"), exports);
|
@@ -32,6 +33,7 @@ __exportStar(require("./transformers/TableColumnResolver"), exports);
|
|
32
33
|
__exportStar(require("./transformers/TableSourceCollector"), exports);
|
33
34
|
__exportStar(require("./transformers/UpstreamSelectQueryFinder"), exports);
|
34
35
|
__exportStar(require("./transformers/SchemaCollector"), exports);
|
36
|
+
__exportStar(require("./transformers/SqlParamInjector"), exports);
|
35
37
|
__exportStar(require("./utils/SqlSchemaValidator"), exports);
|
36
38
|
// Add more exports here if you want to expose additional public API
|
37
39
|
//# sourceMappingURL=index.js.map
|
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;AAC5C,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,8DAA4C;AAC5C,8DAA4C,CAAC,0BAA0B;AACvE,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,iEAA+C;
|
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,8DAA4C;AAC5C,yEAAuD;AACvD,8DAA4C,CAAC,0BAA0B;AACvE,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,iEAA+C;AAC/C,kEAAgD;AAEhD,6DAA2C;AAC3C,oEAAoE"}
|
@@ -27,6 +27,8 @@ export declare enum SqlPrintTokenContainerType {
|
|
27
27
|
SwitchCaseArgument = "SwitchCaseArgument",
|
28
28
|
ElseClause = "ElseClause",
|
29
29
|
CaseKeyValuePair = "CaseKeyValuePair",
|
30
|
+
CaseThenValue = "CaseThenValue",
|
31
|
+
CaseElseValue = "CaseElseValue",
|
30
32
|
ParenExpression = "ParenExpression",
|
31
33
|
CastExpression = "CastExpression",
|
32
34
|
CaseExpression = "CaseExpression",
|
@@ -33,6 +33,8 @@ var SqlPrintTokenContainerType;
|
|
33
33
|
SqlPrintTokenContainerType["SwitchCaseArgument"] = "SwitchCaseArgument";
|
34
34
|
SqlPrintTokenContainerType["ElseClause"] = "ElseClause";
|
35
35
|
SqlPrintTokenContainerType["CaseKeyValuePair"] = "CaseKeyValuePair";
|
36
|
+
SqlPrintTokenContainerType["CaseThenValue"] = "CaseThenValue";
|
37
|
+
SqlPrintTokenContainerType["CaseElseValue"] = "CaseElseValue";
|
36
38
|
SqlPrintTokenContainerType["ParenExpression"] = "ParenExpression";
|
37
39
|
SqlPrintTokenContainerType["CastExpression"] = "CastExpression";
|
38
40
|
SqlPrintTokenContainerType["CaseExpression"] = "CaseExpression";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SqlPrintToken.js","sourceRoot":"","sources":["../../src/models/SqlPrintToken.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAaX;AAbD,WAAY,iBAAiB;IACzB,mEAAa,CAAA;IACb,+DAAO,CAAA;IACP,2DAAK,CAAA;IACL,2DAAK,CAAA;IACL,uEAAW,CAAA;IACX,iEAAQ,CAAA;IACR,+DAAO,CAAA;IACP,mEAAS,CAAA;IACT,uDAAG,CAAA;IACH,yDAAI,CAAA;IACJ,4DAAK,CAAA;IACL,kFAAgB,CAAA;AACpB,CAAC,EAbW,iBAAiB,iCAAjB,iBAAiB,QAa5B;AAED,2DAA2D;AAC3D,IAAY,
|
1
|
+
{"version":3,"file":"SqlPrintToken.js","sourceRoot":"","sources":["../../src/models/SqlPrintToken.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAaX;AAbD,WAAY,iBAAiB;IACzB,mEAAa,CAAA;IACb,+DAAO,CAAA;IACP,2DAAK,CAAA;IACL,2DAAK,CAAA;IACL,uEAAW,CAAA;IACX,iEAAQ,CAAA;IACR,+DAAO,CAAA;IACP,mEAAS,CAAA;IACT,uDAAG,CAAA;IACH,yDAAI,CAAA;IACJ,4DAAK,CAAA;IACL,kFAAgB,CAAA;AACpB,CAAC,EAbW,iBAAiB,iCAAjB,iBAAiB,QAa5B;AAED,2DAA2D;AAC3D,IAAY,0BAkEX;AAlED,WAAY,0BAA0B;IAClC,iEAAmC,CAAA;IACnC,2DAA6B,CAAA;IAC7B,mEAAqC,CAAA;IACrC,yDAA2B,CAAA;IAC3B,qFAAuD,CAAA;IACvD,uCAAS,CAAA;IACT,qDAAuB,CAAA;IACvB,yDAA2B,CAAA;IAC3B,2DAA6B,CAAA;IAC7B,iEAAmC,CAAA;IACnC,mEAAqC,CAAA;IACrC,uEAAyC,CAAA;IACzC,uDAAyB,CAAA;IACzB,mEAAqC,CAAA;IACrC,6DAA+B,CAAA;IAC/B,6DAA+B,CAAA;IAC/B,iEAAmC,CAAA;IACnC,+DAAiC,CAAA;IACjC,+DAAiC,CAAA;IACjC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IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;CACJ;AA9BD,sCA8BC"}
|
@@ -32,7 +32,7 @@ export declare class FunctionCall extends SqlComponent {
|
|
32
32
|
qualifiedName: QualifiedName;
|
33
33
|
argument: ValueComponent | null;
|
34
34
|
over: OverExpression | null;
|
35
|
-
constructor(namespaces: string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument: ValueComponent | null, over: OverExpression | null);
|
35
|
+
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString, argument: ValueComponent | null, over: OverExpression | null);
|
36
36
|
/**
|
37
37
|
* For backward compatibility: returns the namespaces as IdentifierString[] | null (readonly)
|
38
38
|
*/
|
@@ -103,7 +103,7 @@ export declare class ParameterExpression extends SqlComponent {
|
|
103
103
|
value: any | null;
|
104
104
|
/**
|
105
105
|
* The index assigned by the formatter when generating parameterized queries.
|
106
|
-
*
|
106
|
+
* Used for naming parameters like $1, $2, etc.
|
107
107
|
*/
|
108
108
|
index: number | null;
|
109
109
|
constructor(name: string, value?: any | null);
|
@@ -195,7 +195,7 @@ export declare class QualifiedName extends SqlComponent {
|
|
195
195
|
namespaces: IdentifierString[] | null;
|
196
196
|
/** The actual name (e.g. table, function, type, column) */
|
197
197
|
name: RawString | IdentifierString;
|
198
|
-
constructor(namespaces: string[] | IdentifierString[] | null, name: string | RawString | IdentifierString);
|
198
|
+
constructor(namespaces: string | string[] | IdentifierString[] | null, name: string | RawString | IdentifierString);
|
199
199
|
/** Returns the full qualified name as a string (dot-separated) */
|
200
200
|
toString(): string;
|
201
201
|
}
|
@@ -39,15 +39,8 @@ class ColumnReference extends SqlComponent_1.SqlComponent {
|
|
39
39
|
}
|
40
40
|
constructor(namespaces, column) {
|
41
41
|
super();
|
42
|
-
let nsArr;
|
43
|
-
if (typeof namespaces === "string") {
|
44
|
-
nsArr = [namespaces];
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
nsArr = namespaces;
|
48
|
-
}
|
49
42
|
const col = typeof column === "string" ? new IdentifierString(column) : column;
|
50
|
-
this.qualifiedName = new QualifiedName(
|
43
|
+
this.qualifiedName = new QualifiedName(toIdentifierStringArray(namespaces), col);
|
51
44
|
}
|
52
45
|
toString() {
|
53
46
|
return this.qualifiedName.toString();
|
@@ -165,7 +158,7 @@ class ParameterExpression extends SqlComponent_1.SqlComponent {
|
|
165
158
|
constructor(name, value = null) {
|
166
159
|
super();
|
167
160
|
this.name = new RawString(name);
|
168
|
-
this.value = value;
|
161
|
+
this.value = value; // Value is now accepted as a second argument (optional)
|
169
162
|
this.index = null;
|
170
163
|
}
|
171
164
|
}
|
@@ -305,14 +298,22 @@ TupleExpression.kind = Symbol("TupleExpression");
|
|
305
298
|
function toIdentifierStringArray(input) {
|
306
299
|
if (input == null)
|
307
300
|
return null;
|
308
|
-
if (typeof input === "string")
|
309
|
-
|
301
|
+
if (typeof input === "string") {
|
302
|
+
// Empty string should be treated as null
|
303
|
+
return input.trim() === "" ? null : [new IdentifierString(input)];
|
304
|
+
}
|
310
305
|
if (Array.isArray(input)) {
|
306
|
+
if (input.length === 0)
|
307
|
+
return null;
|
311
308
|
if (typeof input[0] === "string") {
|
312
|
-
|
309
|
+
// Filter out empty strings from string array
|
310
|
+
const filteredStrings = input.filter(ns => ns.trim() !== "");
|
311
|
+
return filteredStrings.length === 0 ? null : filteredStrings.map(ns => new IdentifierString(ns));
|
313
312
|
}
|
314
313
|
else {
|
315
|
-
|
314
|
+
// Filter out empty IdentifierStrings from IdentifierString array
|
315
|
+
const filteredIdentifiers = input.filter(ns => ns.name.trim() !== "");
|
316
|
+
return filteredIdentifiers.length === 0 ? null : filteredIdentifiers;
|
316
317
|
}
|
317
318
|
}
|
318
319
|
return null;
|