@iamkirbki/database-handler-core 4.3.0 → 4.4.0
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/dist/abstract/Controller.d.ts +17 -0
- package/dist/abstract/Controller.d.ts.map +1 -0
- package/dist/abstract/Controller.js +47 -0
- package/dist/abstract/Model.d.ts +33 -19
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +177 -120
- package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
- package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.d.ts +23 -0
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -0
- package/dist/abstract/model/ModelRelation.js +130 -0
- package/dist/base/Query.d.ts +10 -13
- package/dist/base/Query.d.ts.map +1 -1
- package/dist/base/Query.js +68 -26
- package/dist/base/Record.d.ts +4 -2
- package/dist/base/Record.d.ts.map +1 -1
- package/dist/base/Record.js +24 -14
- package/dist/base/Table.d.ts +12 -7
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +87 -47
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +4 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +6 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +4 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.js +6 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.js +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +27 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +9 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +102 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +63 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +49 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +19 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +60 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +15 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +74 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +10 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +8 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +5 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.js +17 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +54 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +102 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +16 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +169 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts +15 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.js +79 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts +160 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.js +217 -0
- package/dist/interfaces/IExpressionBuilder.d.ts +7 -0
- package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -0
- package/dist/interfaces/IExpressionBuilder.js +1 -0
- package/dist/interfaces/IQueryBuilder.d.ts +5 -0
- package/dist/interfaces/IQueryBuilder.d.ts.map +1 -0
- package/dist/interfaces/IQueryBuilder.js +1 -0
- package/dist/interfaces/ISchemaBuilder.d.ts +1 -1
- package/dist/interfaces/ISchemaBuilder.d.ts.map +1 -1
- package/dist/runtime/Container.d.ts +3 -0
- package/dist/runtime/Container.d.ts.map +1 -1
- package/dist/runtime/Container.js +12 -2
- package/dist/runtime/QueryCache.d.ts +12 -0
- package/dist/runtime/QueryCache.d.ts.map +1 -0
- package/dist/runtime/QueryCache.js +26 -0
- package/dist/runtime/Repository.d.ts +13 -7
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +114 -70
- package/dist/types/expressions.d.ts +154 -0
- package/dist/types/expressions.d.ts.map +1 -0
- package/dist/types/expressions.js +6 -0
- package/dist/types/factories.d.ts +7 -0
- package/dist/types/factories.d.ts.map +1 -0
- package/dist/types/factories.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/model.d.ts +8 -8
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/query.d.ts +63 -1
- package/dist/types/query.d.ts.map +1 -1
- package/package.json +11 -3
- package/dist/helpers/QueryStatementBuilder.d.ts +0 -304
- package/dist/helpers/QueryStatementBuilder.d.ts.map +0 -1
- package/dist/helpers/QueryStatementBuilder.js +0 -417
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import InvalidExpressionParametersError from "../../../helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js";
|
|
2
|
+
import { QueryEvaluationPhase } from "../../../types/index.js";
|
|
3
|
+
import QueryStatementBuilder from "../QueryStatementBuilder.js";
|
|
4
|
+
export default class SpatialDistanceExpression {
|
|
5
|
+
build(expression) {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!this.validate(expression)) {
|
|
8
|
+
throw new InvalidExpressionParametersError("Invalid spatial distance expression parameters.");
|
|
9
|
+
}
|
|
10
|
+
const earthRadius = (_a = expression.parameters.earthRadius) !== null && _a !== void 0 ? _a : (expression.parameters.unit === 'km' ? 6371 : 3959);
|
|
11
|
+
const isComputed = expression.parameters.isComputed;
|
|
12
|
+
const baseExpressionClause = `
|
|
13
|
+
${earthRadius} * acos(
|
|
14
|
+
cos(radians(@${expression.parameters.valueClauseKeywords[0]}))
|
|
15
|
+
* cos(radians(${isComputed ? expression.parameters.targetColumns.lat.replace(".", "_") : `${expression.parameters.targetColumns.lat}`}))
|
|
16
|
+
* cos(
|
|
17
|
+
radians(${isComputed ? expression.parameters.targetColumns.lon.replace(".", "_") : `${expression.parameters.targetColumns.lon}`})
|
|
18
|
+
- radians(@${expression.parameters.valueClauseKeywords[1]})
|
|
19
|
+
)
|
|
20
|
+
+ sin(radians(@${expression.parameters.valueClauseKeywords[0]}))
|
|
21
|
+
* sin(radians(${isComputed ? expression.parameters.targetColumns.lat.replace(".", "_") : `${expression.parameters.targetColumns.lat}`}))
|
|
22
|
+
) AS ${expression.parameters.alias}
|
|
23
|
+
`.trim();
|
|
24
|
+
const orderByClause = {
|
|
25
|
+
column: expression.parameters.alias,
|
|
26
|
+
direction: expression.parameters.orderByDistance || 'ASC'
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
baseExpressionClause,
|
|
30
|
+
phase: expression.requirements.phase,
|
|
31
|
+
requiresWrapping: expression.requirements.requiresSelectWrapping || false,
|
|
32
|
+
whereClause: [
|
|
33
|
+
{
|
|
34
|
+
column: expression.parameters.alias,
|
|
35
|
+
operator: '<=',
|
|
36
|
+
value: expression.parameters.maxDistance
|
|
37
|
+
},
|
|
38
|
+
...QueryStatementBuilder.normalizeQueryConditions(expression.parameters.where || [])
|
|
39
|
+
],
|
|
40
|
+
valueClauseKeywords: expression.parameters.valueClauseKeywords,
|
|
41
|
+
orderByClause
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
validate(expression) {
|
|
45
|
+
// Basic validation for spatial distance expression
|
|
46
|
+
return (expression.type === 'spatialDistance' &&
|
|
47
|
+
typeof expression.parameters.referencePoint.lat === 'number' &&
|
|
48
|
+
typeof expression.parameters.referencePoint.lon === 'number' &&
|
|
49
|
+
typeof expression.parameters.targetColumns.lat === 'string' &&
|
|
50
|
+
typeof expression.parameters.targetColumns.lon === 'string' &&
|
|
51
|
+
(expression.parameters.unit === 'km' ||
|
|
52
|
+
expression.parameters.unit === 'miles') &&
|
|
53
|
+
typeof expression.parameters.alias === 'string');
|
|
54
|
+
}
|
|
55
|
+
get defaultRequirements() {
|
|
56
|
+
return {
|
|
57
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
58
|
+
cardinality: 'row',
|
|
59
|
+
requiresAlias: true,
|
|
60
|
+
requiresSelectWrapping: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import IExpressionBuilder from "../../../interfaces/IExpressionBuilder.js";
|
|
2
|
+
import { expressionClause, QueryExpressionRequirements, TextRelevanceQueryExpression } from "../../../types/index.js";
|
|
3
|
+
export default class TextRelevanceExpression implements IExpressionBuilder {
|
|
4
|
+
build(expression: TextRelevanceQueryExpression): expressionClause;
|
|
5
|
+
validate(expression: TextRelevanceQueryExpression): boolean;
|
|
6
|
+
get defaultRequirements(): QueryExpressionRequirements;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=TextRelevanceExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextRelevanceExpression.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAwB,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEzI,MAAM,CAAC,OAAO,OAAO,uBAAwB,YAAW,kBAAkB;IACtE,KAAK,CAAC,UAAU,EAAE,4BAA4B,GAAG,gBAAgB;IAqCjE,QAAQ,CAAC,UAAU,EAAE,4BAA4B,GAAG,OAAO;IAW3D,IAAI,mBAAmB,IAAI,2BAA2B,CAOrD;CACJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import InvalidExpressionParametersError from "../../../helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js";
|
|
2
|
+
import { QueryEvaluationPhase } from "../../../types/index.js";
|
|
3
|
+
export default class TextRelevanceExpression {
|
|
4
|
+
build(expression) {
|
|
5
|
+
if (!this.validate(expression)) {
|
|
6
|
+
throw new InvalidExpressionParametersError("Invalid text relevance expression parameters.");
|
|
7
|
+
}
|
|
8
|
+
// Score: 3 = exact match, 2 = starts with, 1 = contains, 0 = no match
|
|
9
|
+
const columnConcat = expression.parameters.targetColumns
|
|
10
|
+
.map(col => `COALESCE(${col}, '')`)
|
|
11
|
+
.join(" || ' ' || ");
|
|
12
|
+
const baseExpressionClause = `(
|
|
13
|
+
CASE
|
|
14
|
+
WHEN LOWER(${columnConcat}) = LOWER(@${expression.parameters.valueClauseKeywords[0]}) THEN 3
|
|
15
|
+
WHEN LOWER(${columnConcat}) LIKE LOWER(@${expression.parameters.valueClauseKeywords[0]} || '%') THEN 2
|
|
16
|
+
WHEN LOWER(${columnConcat}) LIKE LOWER('%' || @${expression.parameters.valueClauseKeywords[0]} || '%') THEN 1
|
|
17
|
+
ELSE 0
|
|
18
|
+
END
|
|
19
|
+
) AS ${expression.parameters.alias}`;
|
|
20
|
+
const orderByClause = {
|
|
21
|
+
column: expression.parameters.alias,
|
|
22
|
+
direction: expression.parameters.orderByRelevance || 'ASC'
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
baseExpressionClause,
|
|
26
|
+
phase: expression.requirements.phase,
|
|
27
|
+
requiresWrapping: expression.requirements.requiresSelectWrapping || false,
|
|
28
|
+
whereClause: expression.parameters.where,
|
|
29
|
+
valueClauseKeywords: expression.parameters.valueClauseKeywords,
|
|
30
|
+
orderByClause,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
validate(expression) {
|
|
34
|
+
return (expression.type === 'textRelevance' &&
|
|
35
|
+
typeof expression.parameters.searchTerm === 'string' &&
|
|
36
|
+
Array.isArray(expression.parameters.targetColumns) &&
|
|
37
|
+
expression.parameters.targetColumns.every(col => typeof col === 'string') &&
|
|
38
|
+
typeof expression.parameters.alias === 'string' &&
|
|
39
|
+
typeof expression.parameters.minimumRelevance == 'number');
|
|
40
|
+
}
|
|
41
|
+
get defaultRequirements() {
|
|
42
|
+
return {
|
|
43
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
44
|
+
cardinality: 'row',
|
|
45
|
+
requiresAlias: true,
|
|
46
|
+
requiresSelectWrapping: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expressionClause, OrderByDefinition, QueryComparisonParameters, QueryContext } from "../../../types/index.js";
|
|
2
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
3
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
4
|
+
export default class ExpressionDecorator extends QueryDecorator {
|
|
5
|
+
private parsedExpressions;
|
|
6
|
+
whereClauses?: QueryComparisonParameters[];
|
|
7
|
+
orderByClauses?: OrderByDefinition[];
|
|
8
|
+
groupByClauses?: string[];
|
|
9
|
+
havingClauses?: QueryComparisonParameters[];
|
|
10
|
+
valueClauseKeywords: Set<string>;
|
|
11
|
+
constructor(component: IQueryBuilder, expressions: expressionClause[]);
|
|
12
|
+
build(): Promise<QueryContext>;
|
|
13
|
+
setWhereClauses(): void;
|
|
14
|
+
setOrderByClauses(): void;
|
|
15
|
+
setGroupByClauses(): void;
|
|
16
|
+
setHavingClauses(): void;
|
|
17
|
+
setValueClauseKeywords(): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ExpressionDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressionDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAG9D,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,cAAc;IAC3D,OAAO,CAAC,iBAAiB,CAAqB;IACvC,YAAY,CAAC,EAAE,yBAAyB,EAAE,CAAC;IAC3C,cAAc,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,yBAAyB,EAAE,CAAC;IAC5C,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;gBAGhD,SAAS,EAAE,aAAa,EACxB,WAAW,EAAE,gBAAgB,EAAE;IAW7B,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;IAU7B,eAAe,IAAI,IAAI;IASvB,iBAAiB,IAAI,IAAI;IAIzB,iBAAiB,IAAI,IAAI;IAIzB,gBAAgB,IAAI,IAAI;IASxB,sBAAsB,IAAI,IAAI;CASxC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
import QueryStatementBuilder from "../QueryStatementBuilder.js";
|
|
12
|
+
export default class ExpressionDecorator extends QueryDecorator {
|
|
13
|
+
constructor(component, expressions) {
|
|
14
|
+
super(component);
|
|
15
|
+
this.valueClauseKeywords = new Set();
|
|
16
|
+
this.parsedExpressions = expressions;
|
|
17
|
+
this.setWhereClauses();
|
|
18
|
+
this.setOrderByClauses();
|
|
19
|
+
this.setGroupByClauses();
|
|
20
|
+
this.setHavingClauses();
|
|
21
|
+
this.setValueClauseKeywords();
|
|
22
|
+
}
|
|
23
|
+
build() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const context = yield this.component.build();
|
|
27
|
+
(_a = context.expressionSelect) !== null && _a !== void 0 ? _a : (context.expressionSelect = []);
|
|
28
|
+
context.expressionSelect.push(...this.parsedExpressions.map(e => e.baseExpressionClause));
|
|
29
|
+
(_b = context.conditions) !== null && _b !== void 0 ? _b : (context.conditions = {});
|
|
30
|
+
return context;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
setWhereClauses() {
|
|
34
|
+
this.whereClauses = this.parsedExpressions
|
|
35
|
+
.flatMap(expr => expr.whereClause
|
|
36
|
+
? QueryStatementBuilder.normalizeQueryConditions(expr.whereClause)
|
|
37
|
+
: []);
|
|
38
|
+
}
|
|
39
|
+
setOrderByClauses() {
|
|
40
|
+
this.orderByClauses = this.parsedExpressions.map(expr => expr.orderByClause).filter(o => o !== undefined);
|
|
41
|
+
}
|
|
42
|
+
setGroupByClauses() {
|
|
43
|
+
this.groupByClauses = this.parsedExpressions.map(expr => expr.groupByClause).filter(g => g !== undefined);
|
|
44
|
+
}
|
|
45
|
+
setHavingClauses() {
|
|
46
|
+
this.havingClauses = this.parsedExpressions
|
|
47
|
+
.flatMap(expr => expr.havingClause
|
|
48
|
+
? QueryStatementBuilder.normalizeQueryConditions(expr.havingClause)
|
|
49
|
+
: []);
|
|
50
|
+
}
|
|
51
|
+
setValueClauseKeywords() {
|
|
52
|
+
this.parsedExpressions.forEach(expr => {
|
|
53
|
+
if (expr.valueClauseKeywords && expr.valueClauseKeywords.length > 0) {
|
|
54
|
+
for (const keyword of expr.valueClauseKeywords) {
|
|
55
|
+
this.valueClauseKeywords.add(keyword);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
3
|
+
import { QueryContext } from "../../../types/query.js";
|
|
4
|
+
export default class GroupByDecorator extends QueryDecorator {
|
|
5
|
+
private groupByColumns?;
|
|
6
|
+
constructor(component: IQueryBuilder, groupByColumns?: string[]);
|
|
7
|
+
build(): Promise<QueryContext>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=GroupByDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroupByDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc;IACxD,OAAO,CAAC,cAAc,CAAC,CAAW;gBAEtB,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE;IAKzD,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CASvC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
export default class GroupByDecorator extends QueryDecorator {
|
|
12
|
+
constructor(component, groupByColumns) {
|
|
13
|
+
super(component);
|
|
14
|
+
this.groupByColumns = groupByColumns;
|
|
15
|
+
}
|
|
16
|
+
build() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const context = yield this.component.build();
|
|
20
|
+
if (this.groupByColumns) {
|
|
21
|
+
(_a = context.groupBy) !== null && _a !== void 0 ? _a : (context.groupBy = []);
|
|
22
|
+
context.groupBy.push(...this.groupByColumns);
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueryLayers, QueryContext } from "../../../index.js";
|
|
2
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
3
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
4
|
+
import { TableColumnInfo } from "../../../types/index.js";
|
|
5
|
+
export default class JoinDecorator extends QueryDecorator {
|
|
6
|
+
private fromTableName;
|
|
7
|
+
private joins;
|
|
8
|
+
private tableColumnsCache;
|
|
9
|
+
private options?;
|
|
10
|
+
constructor(builder: IQueryBuilder, layer: QueryLayers, tableColumnInformation: Map<string, TableColumnInfo[]>);
|
|
11
|
+
build(): Promise<QueryContext>;
|
|
12
|
+
private buildJoinSelect;
|
|
13
|
+
private buildJoinPart;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=JoinDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoinDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/JoinDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,cAAc;IACrD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,iBAAiB,CAAiC;IAC1D,OAAO,CAAC,OAAO,CAAC,CAAgD;gBAEpD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;IAmBxG,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;YActB,eAAe;IAuB7B,OAAO,CAAC,aAAa;CAgBxB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
export default class JoinDecorator extends QueryDecorator {
|
|
12
|
+
constructor(builder, layer, tableColumnInformation) {
|
|
13
|
+
var _a, _b, _c, _d, _e;
|
|
14
|
+
if (!layer.base.from) {
|
|
15
|
+
throw new Error("Base layer must specify 'from' table name for JoinDecorator.");
|
|
16
|
+
}
|
|
17
|
+
super(builder);
|
|
18
|
+
this.fromTableName = layer.base.from;
|
|
19
|
+
this.joins = layer.base.joins || [];
|
|
20
|
+
this.tableColumnsCache = tableColumnInformation;
|
|
21
|
+
this.options = {
|
|
22
|
+
orderBy: (_a = layer.final) === null || _a === void 0 ? void 0 : _a.orderBy,
|
|
23
|
+
limit: (_b = layer.final) === null || _b === void 0 ? void 0 : _b.limit,
|
|
24
|
+
offset: (_c = layer.final) === null || _c === void 0 ? void 0 : _c.offset,
|
|
25
|
+
groupBy: (_d = layer.pretty) === null || _d === void 0 ? void 0 : _d.groupBy,
|
|
26
|
+
blacklistTables: (_e = layer.final) === null || _e === void 0 ? void 0 : _e.blacklistTables,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
build() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a;
|
|
32
|
+
const context = yield this.component.build();
|
|
33
|
+
const selectExtensions = yield this.buildJoinSelect();
|
|
34
|
+
const joinPart = this.buildJoinPart();
|
|
35
|
+
context.joinsSelect = selectExtensions;
|
|
36
|
+
(_a = context.joins) !== null && _a !== void 0 ? _a : (context.joins = []);
|
|
37
|
+
context.joins.push(...joinPart);
|
|
38
|
+
return context;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
buildJoinSelect() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
44
|
+
const blacklist = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.blacklistTables) || [];
|
|
45
|
+
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
46
|
+
const mainCols = this.tableColumnsCache.get(this.fromTableName) || [];
|
|
47
|
+
const mainSelect = mainCols
|
|
48
|
+
.filter(() => !blacklist.includes(this.fromTableName))
|
|
49
|
+
.map(col => `"${this.fromTableName}"."${col.name}" AS "${this.fromTableName}__${col.name}"`);
|
|
50
|
+
const joinedSelects = yield Promise.all(joinArray.map((join) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
if (blacklist.includes(join.fromTable))
|
|
52
|
+
return "";
|
|
53
|
+
const cols = this.tableColumnsCache.get(join.fromTable) || [];
|
|
54
|
+
return cols
|
|
55
|
+
.map(col => `"${join.fromTable}"."${col.name}" AS "${join.fromTable}__${col.name}"`)
|
|
56
|
+
.filter(col => col.trim() !== "");
|
|
57
|
+
})));
|
|
58
|
+
return [...mainSelect, ...joinedSelects.flat()].filter(s => s !== "").filter(Boolean);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
buildJoinPart() {
|
|
62
|
+
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
63
|
+
return joinArray.map(join => {
|
|
64
|
+
const baseTable = join.baseTable || this.fromTableName;
|
|
65
|
+
const onConditions = Array.isArray(join.on) ? join.on : [join.on];
|
|
66
|
+
const onClause = onConditions.map(part => {
|
|
67
|
+
const targetCol = Object.keys(part)[0];
|
|
68
|
+
const sourceCol = Object.values(part)[0];
|
|
69
|
+
return `${baseTable}.${sourceCol} = ${join.fromTable}.${targetCol}`;
|
|
70
|
+
}).join(" AND ");
|
|
71
|
+
return `${join.joinType} JOIN "${join.fromTable}" ON ${onClause}`;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
3
|
+
import { QueryContext } from "../../../types/query.js";
|
|
4
|
+
export default class LimitDecorator extends QueryDecorator {
|
|
5
|
+
private limitCount;
|
|
6
|
+
private offsetCount?;
|
|
7
|
+
constructor(component: IQueryBuilder, limitCount: number, offsetCount?: number);
|
|
8
|
+
build(): Promise<QueryContext>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=LimitDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LimitDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/LimitDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,cAAc;IACtD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAS;gBAEjB,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAMxE,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAYvC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
export default class LimitDecorator extends QueryDecorator {
|
|
12
|
+
constructor(component, limitCount, offsetCount) {
|
|
13
|
+
super(component);
|
|
14
|
+
this.limitCount = limitCount;
|
|
15
|
+
this.offsetCount = offsetCount;
|
|
16
|
+
}
|
|
17
|
+
build() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const context = yield this.component.build();
|
|
20
|
+
if (this.limitCount) {
|
|
21
|
+
context.limit = this.limitCount;
|
|
22
|
+
}
|
|
23
|
+
if (this.offsetCount) {
|
|
24
|
+
context.offset = this.offsetCount;
|
|
25
|
+
}
|
|
26
|
+
return context;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
3
|
+
import { OrderByDefinition, QueryContext } from "../../../types/query.js";
|
|
4
|
+
export default class OrderByDecorator extends QueryDecorator {
|
|
5
|
+
private orderByColumns?;
|
|
6
|
+
constructor(component: IQueryBuilder, orderByColumns?: OrderByDefinition[]);
|
|
7
|
+
build(): Promise<QueryContext>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=OrderByDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrderByDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEvE,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc;IACxD,OAAO,CAAC,cAAc,CAAC,CAAsB;gBAEjC,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,iBAAiB,EAAE;IAKpE,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CASvC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
export default class OrderByDecorator extends QueryDecorator {
|
|
12
|
+
constructor(component, orderByColumns) {
|
|
13
|
+
super(component);
|
|
14
|
+
this.orderByColumns = orderByColumns;
|
|
15
|
+
}
|
|
16
|
+
build() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const context = yield this.component.build();
|
|
20
|
+
if (this.orderByColumns) {
|
|
21
|
+
(_a = context.orderBy) !== null && _a !== void 0 ? _a : (context.orderBy = []);
|
|
22
|
+
context.orderBy.push(...this.orderByColumns);
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder";
|
|
2
|
+
import { QueryContext } from "../../../types/query";
|
|
3
|
+
export default abstract class QueryDecorator implements IQueryBuilder {
|
|
4
|
+
protected component: IQueryBuilder;
|
|
5
|
+
constructor(component: IQueryBuilder);
|
|
6
|
+
abstract build(): Promise<QueryContext>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=QueryDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/QueryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,cAAe,YAAW,aAAa;IACjE,SAAS,CAAC,SAAS,EAAE,aAAa,CAAC;gBAEvB,SAAS,EAAE,aAAa;IAIpC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAC1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=ValuesDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValuesDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
3
|
+
// import { columnType } from "../../../types/index.js";
|
|
4
|
+
// import QueryDecorator from "./QueryDecorator";
|
|
5
|
+
// export default class ValuesDecorator extends QueryDecorator {
|
|
6
|
+
// private values: columnType[];
|
|
7
|
+
// constructor(component: IQueryBuilder, values: columnType[]) {
|
|
8
|
+
// super(component);
|
|
9
|
+
// this.values = values;
|
|
10
|
+
// }
|
|
11
|
+
// async build(): Promise<string> {
|
|
12
|
+
// const baseQuery = await this.component.build();
|
|
13
|
+
// const columns = Object.keys(this.values);
|
|
14
|
+
// const placeholders = columns.map((col) => `@${col}`);
|
|
15
|
+
// return `${baseQuery} ${columns.map((c) => `"${c}"`).join(", ")} VALUES (${placeholders.join(", ")})`;
|
|
16
|
+
// }
|
|
17
|
+
// }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import { QueryContext, QueryWhereCondition } from "../../../types/query.js";
|
|
3
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
4
|
+
export default class WhereDecorator extends QueryDecorator {
|
|
5
|
+
private conditions;
|
|
6
|
+
constructor(component: IQueryBuilder, conditions: QueryWhereCondition);
|
|
7
|
+
build(): Promise<QueryContext>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=WhereDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WhereDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/WhereDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAGjD,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,cAAc;IACtD,OAAO,CAAC,UAAU,CAAsB;gBAGpC,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,mBAAmB;IAM7B,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAUvC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import QueryDecorator from "./QueryDecorator.js";
|
|
11
|
+
import QueryStatementBuilder from "../QueryStatementBuilder.js";
|
|
12
|
+
export default class WhereDecorator extends QueryDecorator {
|
|
13
|
+
constructor(component, conditions) {
|
|
14
|
+
super(component);
|
|
15
|
+
this.conditions = conditions;
|
|
16
|
+
}
|
|
17
|
+
build() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
var _c;
|
|
21
|
+
const context = yield this.component.build();
|
|
22
|
+
const combinedConditions = [...QueryStatementBuilder.normalizeQueryConditions(this.conditions)];
|
|
23
|
+
(_a = context.conditions) !== null && _a !== void 0 ? _a : (context.conditions = {});
|
|
24
|
+
(_b = (_c = context.conditions).where) !== null && _b !== void 0 ? _b : (_c.where = []);
|
|
25
|
+
context.conditions.where.push(...combinedConditions);
|
|
26
|
+
return context;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PossibleExpressions, ExpressionBuilderFunction, expressionClause } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* A normalized, intermediate representation of a query expression.
|
|
4
|
+
*
|
|
5
|
+
* Expressions are NOT SQL strings directly — they are metadata-rich
|
|
6
|
+
* building blocks that later stages of the query builder can reason about.
|
|
7
|
+
*
|
|
8
|
+
* This is what allows:
|
|
9
|
+
* - base vs projection expressions
|
|
10
|
+
* - conditional query wrapping
|
|
11
|
+
* - expression-driven WHERE / ORDER BY injection
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Central factory and orchestration layer for query expressions.
|
|
15
|
+
*
|
|
16
|
+
* This class is intentionally:
|
|
17
|
+
* - static
|
|
18
|
+
* - registry-driven
|
|
19
|
+
* - dumb about SQL execution
|
|
20
|
+
*
|
|
21
|
+
* Its ONLY job is to translate abstract expressions
|
|
22
|
+
* into structured SQL fragments with metadata.
|
|
23
|
+
*/
|
|
24
|
+
export default class QueryExpressionBuilder {
|
|
25
|
+
/**
|
|
26
|
+
* Registry mapping expression "type" → builder function.
|
|
27
|
+
*
|
|
28
|
+
* This allows:
|
|
29
|
+
* - zero switch statements
|
|
30
|
+
* - easy plugin-style extension
|
|
31
|
+
* - no touching core logic to add new expressions
|
|
32
|
+
*/
|
|
33
|
+
private static expressionBuilders;
|
|
34
|
+
private static expressionDefaults;
|
|
35
|
+
static getExpressionDefaultRequirements(type: string): PossibleExpressions['requirements'] | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Registers a new expression builder at runtime.
|
|
38
|
+
*
|
|
39
|
+
* This is your “escape hatch” when core expressions
|
|
40
|
+
* are not enough.
|
|
41
|
+
*
|
|
42
|
+
* @param type - expression.type value
|
|
43
|
+
* @param builder - function that converts expression → expressionClause
|
|
44
|
+
*/
|
|
45
|
+
static registerExpressionBuilder<T extends PossibleExpressions>(type: string, builder: ExpressionBuilderFunction<T>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Converts high-level expression definitions into normalized clauses.
|
|
48
|
+
*
|
|
49
|
+
* Any expression without a registered builder is ignored
|
|
50
|
+
* (with a error, because silence is how bugs breed).
|
|
51
|
+
*/
|
|
52
|
+
static buildExpressionsPart(expressions: PossibleExpressions[]): expressionClause[];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=QueryExpressionBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryExpressionBuilder.d.ts","sourceRoot":"","sources":["../../../src/helpers/QueryBuilders/QueryExpressionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EAEnB,yBAAyB,EACzB,gBAAgB,EAGnB,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;GAUG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAsB;IAEvC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB,CA0B9B;IAEH,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAa9B;WAEW,gCAAgC,CAC1C,IAAI,EAAE,MAAM,GACb,mBAAmB,CAAC,cAAc,CAAC,GAAG,SAAS;IAIlD;;;;;;;;OAQG;WACW,yBAAyB,CAAC,CAAC,SAAS,mBAAmB,EACjE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,yBAAyB,CAAC,CAAC,CAAC,GACtC,IAAI;IAIP;;;;;OAKG;WACW,oBAAoB,CAC9B,WAAW,EAAE,mBAAmB,EAAE,GACnC,gBAAgB,EAAE;CAexB"}
|