@iamkirbki/database-handler-core 4.4.6 → 4.4.8
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 +2 -2
- package/dist/abstract/Controller.d.ts.map +1 -1
- package/dist/abstract/Controller.js +1 -1
- package/dist/abstract/Model.d.ts +10 -9
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +92 -70
- package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
- package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
- package/dist/abstract/SchemaTableBuilder.js +8 -8
- package/dist/abstract/model/ModelRelation.d.ts +5 -4
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.js +35 -27
- package/dist/base/Query.d.ts +4 -8
- package/dist/base/Query.d.ts.map +1 -1
- package/dist/base/Query.js +91 -73
- package/dist/base/Record.d.ts +5 -4
- package/dist/base/Record.d.ts.map +1 -1
- package/dist/base/Record.js +44 -23
- package/dist/base/Table.d.ts +17 -14
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +123 -89
- package/dist/factories/ModelFactory.d.ts +7 -0
- package/dist/factories/ModelFactory.d.ts.map +1 -0
- package/dist/factories/ModelFactory.js +6 -0
- package/dist/factories/QueryFactory.d.ts +7 -0
- package/dist/factories/QueryFactory.d.ts.map +1 -0
- package/dist/factories/QueryFactory.js +6 -0
- package/dist/factories/RecordFactory.d.ts +8 -0
- package/dist/factories/RecordFactory.d.ts.map +1 -0
- package/dist/factories/RecordFactory.js +6 -0
- package/dist/factories/TableFactory.d.ts +7 -0
- package/dist/factories/TableFactory.d.ts.map +1 -0
- package/dist/factories/TableFactory.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +3 -3
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +3 -3
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +3 -3
- package/dist/helpers/Errors/DatabaseHandlerError.d.ts +9 -0
- package/dist/helpers/Errors/DatabaseHandlerError.d.ts.map +1 -0
- package/dist/helpers/Errors/DatabaseHandlerError.js +10 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +5 -3
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +5 -3
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +3 -3
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.d.ts +5 -0
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.js +6 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.d.ts +6 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.js +6 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.d.ts +5 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.d.ts +5 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.d.ts +5 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +2 -1
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -1
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +3 -3
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +3 -2
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -1
- package/dist/helpers/Errors/TableErrors/UnknownTableError.js +4 -4
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +2 -2
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +46 -44
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +34 -32
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +9 -20
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +4 -4
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +14 -17
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +4 -4
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +17 -14
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +5 -5
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +3 -4
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +1 -3
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +4 -22
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +3 -4
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +59 -45
- package/dist/helpers/QueryBuilders/{SqlRenderer.d.ts → SqlGenerator.d.ts} +3 -3
- package/dist/helpers/QueryBuilders/SqlGenerator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/{SqlRenderer.js → SqlGenerator.js} +30 -19
- package/dist/helpers/QueryBuilders/{oldQueryStatementBuilder.d.ts → depricatedQueryStatementBuilder.d.ts} +19 -46
- package/dist/helpers/QueryBuilders/depricatedQueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/{oldQueryStatementBuilder.js → depricatedQueryStatementBuilder.js} +31 -67
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/interfaces/IController.d.ts +1 -1
- package/dist/interfaces/IController.d.ts.map +1 -1
- package/dist/interfaces/IDatabaseAdapter.d.ts +2 -2
- package/dist/interfaces/IDatabaseAdapter.d.ts.map +1 -1
- package/dist/interfaces/IExpressionBuilder.d.ts +1 -2
- package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -1
- package/dist/interfaces/IFactory.d.ts +4 -0
- package/dist/interfaces/IFactory.d.ts.map +1 -0
- package/dist/interfaces/IFactory.js +1 -0
- package/dist/interfaces/IMigration.d.ts +4 -4
- package/dist/interfaces/IMigration.d.ts.map +1 -1
- package/dist/interfaces/IQueryBuilder.d.ts +1 -1
- package/dist/interfaces/IQueryBuilder.d.ts.map +1 -1
- package/dist/interfaces/ISchemaBuilder.d.ts +2 -2
- package/dist/interfaces/ISchemaBuilder.d.ts.map +1 -1
- package/dist/interfaces/IStatementAdapter.d.ts +1 -1
- package/dist/interfaces/IStatementAdapter.d.ts.map +1 -1
- package/dist/runtime/Container.d.ts +2 -3
- package/dist/runtime/Container.d.ts.map +1 -1
- package/dist/runtime/Container.js +3 -4
- package/dist/runtime/QueryCache.d.ts +1 -1
- package/dist/runtime/QueryCache.d.ts.map +1 -1
- package/dist/runtime/QueryCache.js +1 -1
- package/dist/runtime/Repository.d.ts +23 -12
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +324 -65
- package/dist/types/expressions.d.ts +12 -47
- package/dist/types/expressions.d.ts.map +1 -1
- package/dist/types/expressions.js +1 -6
- package/dist/types/factories.d.ts +5 -3
- package/dist/types/factories.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/model.d.ts +5 -23
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/query.d.ts +5 -4
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/record.d.ts +11 -0
- package/dist/types/record.d.ts.map +1 -0
- package/dist/types/record.js +1 -0
- package/dist/types/repository.d.ts +8 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/repository.js +1 -0
- package/dist/types/table.d.ts +9 -1
- package/dist/types/table.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +0 -1
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import QueryDecorator from "./QueryDecorator.js";
|
|
2
|
-
|
|
1
|
+
import { QueryDecorator } from "./QueryDecorator.js";
|
|
2
|
+
import { InvalidOperationError } from "../../../helpers/Errors/ModelErrors/InvalidOperationError.js";
|
|
3
|
+
export class JoinDecorator extends QueryDecorator {
|
|
3
4
|
constructor(builder, layer, tableColumnInformation) {
|
|
4
5
|
var _a, _b, _c, _d, _e;
|
|
5
6
|
if (!layer.base.from) {
|
|
6
|
-
throw new
|
|
7
|
+
throw new InvalidOperationError("Base layer must specify 'from' table name for JoinDecorator.");
|
|
7
8
|
}
|
|
8
9
|
super(builder);
|
|
9
10
|
this.fromTableName = layer.base.from;
|
|
@@ -20,14 +21,14 @@ export default class JoinDecorator extends QueryDecorator {
|
|
|
20
21
|
async build() {
|
|
21
22
|
var _a;
|
|
22
23
|
const context = await this.component.build();
|
|
23
|
-
const selectExtensions =
|
|
24
|
-
const joinPart = this.
|
|
24
|
+
const selectExtensions = this.buildJoinSelect();
|
|
25
|
+
const joinPart = this.buildSqlJoinPart();
|
|
25
26
|
context.joinsSelect = selectExtensions;
|
|
26
27
|
(_a = context.joins) !== null && _a !== void 0 ? _a : (context.joins = []);
|
|
27
28
|
context.joins.push(...joinPart);
|
|
28
29
|
return context;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
buildJoinSelect() {
|
|
31
32
|
var _a;
|
|
32
33
|
const blacklist = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.blacklistTables) || [];
|
|
33
34
|
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
@@ -35,27 +36,29 @@ export default class JoinDecorator extends QueryDecorator {
|
|
|
35
36
|
const mainSelect = mainCols
|
|
36
37
|
.filter(() => !blacklist.includes(this.fromTableName))
|
|
37
38
|
.map(col => `"${this.fromTableName}"."${col.name}" AS "${this.fromTableName}__${col.name}"`);
|
|
38
|
-
const
|
|
39
|
-
|
|
39
|
+
const innerSelects = joinArray.map((join) => {
|
|
40
|
+
const alias = join.name || join.fromTable;
|
|
41
|
+
if (blacklist.includes(join.fromTable) || blacklist.includes(alias))
|
|
40
42
|
return "";
|
|
41
43
|
const cols = this.tableColumnsCache.get(join.fromTable) || [];
|
|
42
44
|
return cols
|
|
43
|
-
.map(col => `"${
|
|
45
|
+
.map(col => `"${alias}"."${col.name}" AS "${alias}__${col.name}"`)
|
|
44
46
|
.filter(col => col.trim() !== "");
|
|
45
|
-
})
|
|
46
|
-
return [...mainSelect, ...
|
|
47
|
+
});
|
|
48
|
+
return [...mainSelect, ...innerSelects.flat()].filter(s => s !== "").filter(Boolean);
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
buildSqlJoinPart() {
|
|
49
51
|
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
50
52
|
return joinArray.map(join => {
|
|
51
53
|
const baseTable = join.baseTable || this.fromTableName;
|
|
52
54
|
const onConditions = Array.isArray(join.on) ? join.on : [join.on];
|
|
55
|
+
const alias = join.name || join.fromTable;
|
|
53
56
|
const onClause = onConditions.map(part => {
|
|
54
57
|
const targetCol = Object.keys(part)[0];
|
|
55
58
|
const sourceCol = Object.values(part)[0];
|
|
56
|
-
return `${baseTable}.${sourceCol} = ${
|
|
59
|
+
return `${baseTable}.${sourceCol} = ${alias}.${targetCol}`;
|
|
57
60
|
}).join(" AND ");
|
|
58
|
-
return `${join.joinType} JOIN "${join.fromTable}" ON ${onClause}`;
|
|
61
|
+
return `${join.joinType} JOIN "${join.fromTable}" AS "${alias}" ON ${onClause}`;
|
|
59
62
|
});
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
-
import QueryDecorator from "./QueryDecorator.js";
|
|
1
|
+
import { IQueryBuilder } from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import { QueryDecorator } from "./QueryDecorator.js";
|
|
3
3
|
import { QueryContext } from "../../../types/query.js";
|
|
4
|
-
export
|
|
4
|
+
export declare class LimitDecorator extends QueryDecorator {
|
|
5
5
|
private limitCount;
|
|
6
6
|
private offsetCount?;
|
|
7
7
|
constructor(component: IQueryBuilder, limitCount: number, offsetCount?: number);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LimitDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/LimitDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"LimitDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/LimitDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,qBAAa,cAAe,SAAQ,cAAc;IAC9C,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import QueryDecorator from "./QueryDecorator.js";
|
|
2
|
-
export
|
|
1
|
+
import { QueryDecorator } from "./QueryDecorator.js";
|
|
2
|
+
export class LimitDecorator extends QueryDecorator {
|
|
3
3
|
constructor(component, limitCount, offsetCount) {
|
|
4
4
|
super(component);
|
|
5
5
|
this.limitCount = limitCount;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
-
import QueryDecorator from "./QueryDecorator.js";
|
|
1
|
+
import { IQueryBuilder } from "../../../interfaces/IQueryBuilder.js";
|
|
2
|
+
import { QueryDecorator } from "./QueryDecorator.js";
|
|
3
3
|
import { OrderByDefinition, QueryContext } from "../../../types/query.js";
|
|
4
|
-
export
|
|
4
|
+
export declare class OrderByDecorator extends QueryDecorator {
|
|
5
5
|
private orderByColumns?;
|
|
6
6
|
constructor(component: IQueryBuilder, orderByColumns?: OrderByDefinition[]);
|
|
7
7
|
build(): Promise<QueryContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderByDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"OrderByDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,gBAAiB,SAAQ,cAAc;IAChD,OAAO,CAAC,cAAc,CAAC,CAAsB;gBAEjC,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,iBAAiB,EAAE;IAKpE,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CASvC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import QueryDecorator from "./QueryDecorator.js";
|
|
2
|
-
export
|
|
1
|
+
import { QueryDecorator } from "./QueryDecorator.js";
|
|
2
|
+
export class OrderByDecorator extends QueryDecorator {
|
|
3
3
|
constructor(component, orderByColumns) {
|
|
4
4
|
super(component);
|
|
5
5
|
this.orderByColumns = orderByColumns;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import IQueryBuilder from "../../../interfaces/IQueryBuilder";
|
|
1
|
+
import { IQueryBuilder } from "../../../interfaces/IQueryBuilder";
|
|
2
2
|
import { QueryContext } from "../../../types/query";
|
|
3
|
-
export
|
|
3
|
+
export declare abstract class QueryDecorator implements IQueryBuilder {
|
|
4
4
|
protected component: IQueryBuilder;
|
|
5
5
|
constructor(component: IQueryBuilder);
|
|
6
6
|
abstract build(): Promise<QueryContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/QueryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/QueryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,8BAAsB,cAAe,YAAW,aAAa;IACzD,SAAS,CAAC,SAAS,EAAE,aAAa,CAAC;gBAEvB,SAAS,EAAE,aAAa;IAIpC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAC1C"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import IQueryBuilder from
|
|
2
|
-
import { QueryContext,
|
|
3
|
-
import QueryDecorator from
|
|
4
|
-
export
|
|
1
|
+
import { IQueryBuilder } from '../../../interfaces/IQueryBuilder.js';
|
|
2
|
+
import { QueryContext, QueryComparisonParameters } from '../../../types/query.js';
|
|
3
|
+
import { QueryDecorator } from './QueryDecorator.js';
|
|
4
|
+
export declare class WhereDecorator extends QueryDecorator {
|
|
5
5
|
private conditions;
|
|
6
|
-
constructor(component: IQueryBuilder, conditions:
|
|
6
|
+
constructor(component: IQueryBuilder, conditions: QueryComparisonParameters[]);
|
|
7
7
|
build(): Promise<QueryContext>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=WhereDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WhereDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/WhereDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"WhereDecorator.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/QueryDecorators/WhereDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,cAAe,SAAQ,cAAc;IAChD,OAAO,CAAC,UAAU,CAA8B;gBAG9C,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,yBAAyB,EAAE;IAMnC,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAUrC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import QueryDecorator from
|
|
2
|
-
|
|
3
|
-
export default class WhereDecorator extends QueryDecorator {
|
|
1
|
+
import { QueryDecorator } from './QueryDecorator.js';
|
|
2
|
+
export class WhereDecorator extends QueryDecorator {
|
|
4
3
|
constructor(component, conditions) {
|
|
5
4
|
super(component);
|
|
6
5
|
this.conditions = conditions;
|
|
@@ -9,7 +8,7 @@ export default class WhereDecorator extends QueryDecorator {
|
|
|
9
8
|
var _a, _b;
|
|
10
9
|
var _c;
|
|
11
10
|
const context = await this.component.build();
|
|
12
|
-
const combinedConditions = [...
|
|
11
|
+
const combinedConditions = [...this.conditions];
|
|
13
12
|
(_a = context.conditions) !== null && _a !== void 0 ? _a : (context.conditions = {});
|
|
14
13
|
(_b = (_c = context.conditions).where) !== null && _b !== void 0 ? _b : (_c.where = []);
|
|
15
14
|
context.conditions.where.push(...combinedConditions);
|
|
@@ -21,7 +21,7 @@ import { PossibleExpressions, ExpressionBuilderFunction, expressionClause } from
|
|
|
21
21
|
* Its ONLY job is to translate abstract expressions
|
|
22
22
|
* into structured SQL fragments with metadata.
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export declare class QueryExpressionBuilder {
|
|
25
25
|
/**
|
|
26
26
|
* Registry mapping expression "type" → builder function.
|
|
27
27
|
*
|
|
@@ -31,8 +31,6 @@ export default class QueryExpressionBuilder {
|
|
|
31
31
|
* - no touching core logic to add new expressions
|
|
32
32
|
*/
|
|
33
33
|
private static expressionBuilders;
|
|
34
|
-
private static expressionDefaults;
|
|
35
|
-
static getExpressionDefaultRequirements(type: string): PossibleExpressions['requirements'] | undefined;
|
|
36
34
|
/**
|
|
37
35
|
* Registers a new expression builder at runtime.
|
|
38
36
|
*
|
|
@@ -1 +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,
|
|
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,qBAAa,sBAAsB;IAE/B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB,CA0B9B;IAEH;;;;;;;;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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import SpatialDistanceExpression from "./ExpressionBuilders/SpatialDistanceExpression.js";
|
|
1
|
+
import { SpatialDistanceExpression } from "./ExpressionBuilders/SpatialDistanceExpression.js";
|
|
2
2
|
import { UnknownExpressionTypeError } from "../Errors/ExpressionErrors/UnknownExpressionTypeError.js";
|
|
3
|
-
import TextRelevanceExpression from "./ExpressionBuilders/TextRelevanceExpression.js";
|
|
4
|
-
import JsonAggregateExpression from "./ExpressionBuilders/JsonAggregateExpression.js";
|
|
3
|
+
import { TextRelevanceExpression } from "./ExpressionBuilders/TextRelevanceExpression.js";
|
|
4
|
+
import { JsonAggregateExpression } from "./ExpressionBuilders/JsonAggregateExpression.js";
|
|
5
5
|
/**
|
|
6
6
|
* A normalized, intermediate representation of a query expression.
|
|
7
7
|
*
|
|
@@ -24,10 +24,7 @@ import JsonAggregateExpression from "./ExpressionBuilders/JsonAggregateExpressio
|
|
|
24
24
|
* Its ONLY job is to translate abstract expressions
|
|
25
25
|
* into structured SQL fragments with metadata.
|
|
26
26
|
*/
|
|
27
|
-
class QueryExpressionBuilder {
|
|
28
|
-
static getExpressionDefaultRequirements(type) {
|
|
29
|
-
return this.expressionDefaults.get(type);
|
|
30
|
-
}
|
|
27
|
+
export class QueryExpressionBuilder {
|
|
31
28
|
/**
|
|
32
29
|
* Registers a new expression builder at runtime.
|
|
33
30
|
*
|
|
@@ -85,18 +82,3 @@ QueryExpressionBuilder.expressionBuilders = new Map([
|
|
|
85
82
|
// ['jsonAggregation', (expr) => QueryExpressionBuilder.BuildJsonAggregation(expr)]
|
|
86
83
|
// ['windowFunction', (expr) => QueryExpressionBuilder.BuildWindowFunction(expr)]
|
|
87
84
|
]);
|
|
88
|
-
QueryExpressionBuilder.expressionDefaults = new Map([
|
|
89
|
-
[
|
|
90
|
-
'spatialDistance',
|
|
91
|
-
new SpatialDistanceExpression().defaultRequirements
|
|
92
|
-
],
|
|
93
|
-
[
|
|
94
|
-
'textRelevance',
|
|
95
|
-
new TextRelevanceExpression().defaultRequirements
|
|
96
|
-
],
|
|
97
|
-
[
|
|
98
|
-
'jsonAggregate',
|
|
99
|
-
new JsonAggregateExpression().defaultRequirements
|
|
100
|
-
]
|
|
101
|
-
]);
|
|
102
|
-
export default QueryExpressionBuilder;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { QueryComparisonParameters, QueryLayers, TableColumnInfo } from '../../types/index.js';
|
|
2
|
+
export declare class QueryStatementBuilder {
|
|
3
3
|
private _layers;
|
|
4
4
|
private _contexts;
|
|
5
5
|
private _tableColumnsCache;
|
|
@@ -9,8 +9,7 @@ export default class QueryStatementBuilder {
|
|
|
9
9
|
private buildBaseLayer;
|
|
10
10
|
private buildPrettyLayer;
|
|
11
11
|
private buildFinalLayer;
|
|
12
|
-
static normalizeAndQualifyConditions(where:
|
|
13
|
-
static normalizeQueryConditions(where: QueryWhereCondition): QueryComparisonParameters[];
|
|
12
|
+
static normalizeAndQualifyConditions(where: QueryComparisonParameters[], tableName: string, normalizeBlacklist?: string[], valueClauseKeywords?: Set<string>): QueryComparisonParameters[];
|
|
14
13
|
private addUnique;
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=QueryStatementBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryStatementBuilder.d.ts","sourceRoot":"","sources":["../../../src/helpers/QueryBuilders/QueryStatementBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"QueryStatementBuilder.d.ts","sourceRoot":"","sources":["../../../src/helpers/QueryBuilders/QueryStatementBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,WAAW,EAEX,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAa9B,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,SAAS,CAIV;IAEP,OAAO,CAAC,kBAAkB,CAA6C;IACvE,OAAO,CAAC,oBAAoB,CAA0B;gBAGpD,WAAW,EAAE,WAAW,EACxB,sBAAsB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;IAS5C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;YAcvB,cAAc;YA6Gd,gBAAgB;YAsFhB,eAAe;WAwBf,6BAA6B,CACzC,KAAK,EAAE,yBAAyB,EAAE,EAClC,SAAS,EAAE,MAAM,EACjB,kBAAkB,GAAE,MAAM,EAAO,EACjC,mBAAmB,GAAE,GAAG,CAAC,MAAM,CAAa,GAC3C,yBAAyB,EAAE;IAyB9B,OAAO,CAAC,SAAS;CAWlB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import BaseSelectQueryBuilder from
|
|
2
|
-
import ExpressionDecorator from
|
|
3
|
-
import QueryExpressionBuilder from
|
|
4
|
-
import WhereDecorator from
|
|
5
|
-
import JoinDecorator from
|
|
6
|
-
import GroupByDecorator from
|
|
7
|
-
import OrderByDecorator from
|
|
8
|
-
import LimitDecorator from
|
|
9
|
-
import
|
|
10
|
-
|
|
1
|
+
import { BaseSelectQueryBuilder } from './BaseQueryBuilders/BaseSelectQueryBuilder.js';
|
|
2
|
+
import { ExpressionDecorator } from './QueryDecorators/ExpressionDecorator.js';
|
|
3
|
+
import { QueryExpressionBuilder } from './QueryExpressionBuilder.js';
|
|
4
|
+
import { WhereDecorator } from './QueryDecorators/WhereDecorator.js';
|
|
5
|
+
import { JoinDecorator } from './QueryDecorators/JoinDecorator.js';
|
|
6
|
+
import { GroupByDecorator } from './QueryDecorators/GroupByDecorator.js';
|
|
7
|
+
import { OrderByDecorator } from './QueryDecorators/OrderByDecorator.js';
|
|
8
|
+
import { LimitDecorator } from './QueryDecorators/LimitDecorator.js';
|
|
9
|
+
import { SqlGenerator } from './SqlGenerator.js';
|
|
10
|
+
import { InvalidOperationError } from '../../helpers/Errors/ModelErrors/InvalidOperationError.js';
|
|
11
|
+
export class QueryStatementBuilder {
|
|
11
12
|
constructor(queryLayers, tableColumnInformation) {
|
|
12
13
|
this._contexts = {};
|
|
13
14
|
this._tableColumnsCache = new Map();
|
|
@@ -31,45 +32,66 @@ export default class QueryStatementBuilder {
|
|
|
31
32
|
var _a, _b, _c;
|
|
32
33
|
var _d, _e;
|
|
33
34
|
if (!this._layers.base.from) {
|
|
34
|
-
throw new
|
|
35
|
+
throw new InvalidOperationError("Base layer must specify 'from' table name.");
|
|
35
36
|
}
|
|
36
37
|
let builder = new BaseSelectQueryBuilder(this._layers.base.from, this._layers.base.select || [], this._layers.base.joinsSelect || [], this._layers.base.expressionsSelect || []);
|
|
37
38
|
if (this._layers.base.joins && this._layers.base.joins.length > 0) {
|
|
38
|
-
builder = new JoinDecorator(builder, {
|
|
39
|
+
builder = new JoinDecorator(builder, {
|
|
40
|
+
base: this._layers.base,
|
|
41
|
+
pretty: this._layers.pretty,
|
|
42
|
+
final: this._layers.final,
|
|
43
|
+
}, this._tableColumnsCache);
|
|
39
44
|
}
|
|
40
|
-
if (this._layers.base.expressions &&
|
|
45
|
+
if (this._layers.base.expressions &&
|
|
46
|
+
this._layers.base.expressions.length > 0) {
|
|
41
47
|
const expressions = QueryExpressionBuilder.buildExpressionsPart(this._layers.base.expressions || []);
|
|
42
48
|
builder = new ExpressionDecorator(builder, expressions || []);
|
|
43
49
|
if (builder instanceof ExpressionDecorator) {
|
|
44
|
-
this._valueClauseKeywords = new Set([
|
|
50
|
+
this._valueClauseKeywords = new Set([
|
|
51
|
+
...this._valueClauseKeywords,
|
|
52
|
+
...builder.valueClauseKeywords,
|
|
53
|
+
]);
|
|
45
54
|
(_a = (_d = this._layers).pretty) !== null && _a !== void 0 ? _a : (_d.pretty = {});
|
|
46
55
|
(_b = (_e = this._layers).final) !== null && _b !== void 0 ? _b : (_e.final = {});
|
|
47
56
|
this._layers.pretty.where = this.addUnique(this._layers.pretty.where, builder.whereClauses);
|
|
48
57
|
this._layers.pretty.groupBy = this.addUnique(this._layers.pretty.groupBy, builder.groupByClauses);
|
|
49
58
|
this._layers.pretty.having = this.addUnique(this._layers.pretty.having, builder.havingClauses);
|
|
50
|
-
this._layers.base.orderBy = this.addUnique((_c = this._layers.base.orderBy) === null || _c === void 0 ? void 0 : _c.map(ob => ({
|
|
59
|
+
this._layers.base.orderBy = this.addUnique((_c = this._layers.base.orderBy) === null || _c === void 0 ? void 0 : _c.map((ob) => ({
|
|
60
|
+
column: `${ob.column}`,
|
|
61
|
+
direction: ob.direction,
|
|
62
|
+
})), builder.orderByClauses);
|
|
51
63
|
}
|
|
52
64
|
if (this._layers.base.where) {
|
|
53
|
-
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
65
|
+
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
66
|
+
? QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.base.where, this._layers.base.from)
|
|
67
|
+
: this._layers.base.where);
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
else if (this._layers.base.where) {
|
|
57
|
-
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
71
|
+
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
72
|
+
? QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.base.where, this._layers.base.from)
|
|
73
|
+
: this._layers.base.where);
|
|
58
74
|
}
|
|
59
75
|
if (this._layers.base.where) {
|
|
60
|
-
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
76
|
+
builder = new WhereDecorator(builder, this._layers.base.joins
|
|
77
|
+
? QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.base.where, this._layers.base.from)
|
|
78
|
+
: this._layers.base.where);
|
|
61
79
|
}
|
|
62
80
|
if (this._layers.base.orderBy) {
|
|
63
81
|
builder = new OrderByDecorator(builder, this._layers.base.orderBy);
|
|
64
82
|
}
|
|
65
83
|
this._contexts.base = await builder.build();
|
|
66
|
-
const renderer = new
|
|
84
|
+
const renderer = new SqlGenerator(this._contexts.base);
|
|
67
85
|
return renderer.build();
|
|
68
86
|
}
|
|
69
87
|
async buildPrettyLayer(sql) {
|
|
70
88
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
71
89
|
var _h;
|
|
72
|
-
let builder = new BaseSelectQueryBuilder(`( ${sql} ) AS BASE_QUERY`, [
|
|
90
|
+
let builder = new BaseSelectQueryBuilder(`( ${sql} ) AS BASE_QUERY`, [
|
|
91
|
+
...(((_a = this._contexts.base) === null || _a === void 0 ? void 0 : _a.select) || []),
|
|
92
|
+
...(((_b = this._layers.pretty) === null || _b === void 0 ? void 0 : _b.select) || []),
|
|
93
|
+
], ((_d = (_c = this._contexts.base) === null || _c === void 0 ? void 0 : _c.joinsSelect) === null || _d === void 0 ? void 0 : _d.map((j) => j.split('AS')[1].trim())) ||
|
|
94
|
+
[]);
|
|
73
95
|
if (this._layers.pretty) {
|
|
74
96
|
const expressions = ((_e = this._layers.pretty.expressions) === null || _e === void 0 ? void 0 : _e.length)
|
|
75
97
|
? QueryExpressionBuilder.buildExpressionsPart(this._layers.pretty.expressions)
|
|
@@ -81,24 +103,27 @@ export default class QueryStatementBuilder {
|
|
|
81
103
|
this._layers.pretty.groupBy = this.addUnique(this._layers.pretty.groupBy, builder.groupByClauses);
|
|
82
104
|
this._layers.pretty.having = this.addUnique(this._layers.pretty.having, builder.havingClauses);
|
|
83
105
|
(_f = (_h = this._layers).final) !== null && _f !== void 0 ? _f : (_h.final = {});
|
|
84
|
-
this._layers.final.orderBy = this.addUnique((_g = this._layers.final.orderBy) === null || _g === void 0 ? void 0 : _g.map(ob => ({
|
|
106
|
+
this._layers.final.orderBy = this.addUnique((_g = this._layers.final.orderBy) === null || _g === void 0 ? void 0 : _g.map((ob) => ({
|
|
107
|
+
column: `BASE_QUERY.${ob.column}`,
|
|
108
|
+
direction: ob.direction,
|
|
109
|
+
})), builder.orderByClauses);
|
|
85
110
|
}
|
|
86
111
|
if (this._layers.pretty.where) {
|
|
87
|
-
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.where,
|
|
112
|
+
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.where, 'BASE_QUERY', [], this._valueClauseKeywords));
|
|
88
113
|
}
|
|
89
114
|
}
|
|
90
115
|
else if (this._layers.pretty.where) {
|
|
91
|
-
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.where,
|
|
116
|
+
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.where, 'BASE_QUERY', [], this._valueClauseKeywords));
|
|
92
117
|
}
|
|
93
118
|
if (this._layers.pretty.groupBy) {
|
|
94
119
|
builder = new GroupByDecorator(builder, this._layers.pretty.groupBy);
|
|
95
120
|
}
|
|
96
121
|
if (this._layers.pretty.having) {
|
|
97
|
-
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.having,
|
|
122
|
+
builder = new WhereDecorator(builder, QueryStatementBuilder.normalizeAndQualifyConditions(this._layers.pretty.having, 'BASE_QUERY'));
|
|
98
123
|
}
|
|
99
124
|
}
|
|
100
125
|
this._contexts.pretty = await builder.build();
|
|
101
|
-
const renderer = new
|
|
126
|
+
const renderer = new SqlGenerator(this._contexts.pretty);
|
|
102
127
|
return renderer.build();
|
|
103
128
|
}
|
|
104
129
|
async buildFinalLayer(sql) {
|
|
@@ -113,14 +138,15 @@ export default class QueryStatementBuilder {
|
|
|
113
138
|
}
|
|
114
139
|
}
|
|
115
140
|
this._contexts.final = await builder.build();
|
|
116
|
-
const renderer = new
|
|
141
|
+
const renderer = new SqlGenerator(this._contexts.final);
|
|
117
142
|
return renderer.build();
|
|
118
143
|
}
|
|
119
144
|
static normalizeAndQualifyConditions(where, tableName, normalizeBlacklist = [], valueClauseKeywords = new Set()) {
|
|
120
|
-
const
|
|
121
|
-
return
|
|
145
|
+
const normalizedWhere = where;
|
|
146
|
+
return normalizedWhere
|
|
147
|
+
.map((condition) => {
|
|
122
148
|
const shouldSkipQualification = normalizeBlacklist.some((blk) => condition.column.includes(blk)) ||
|
|
123
|
-
condition.column.includes(
|
|
149
|
+
condition.column.includes('.');
|
|
124
150
|
const isValueClauseKeyword = valueClauseKeywords.has(condition.column);
|
|
125
151
|
if (isValueClauseKeyword) {
|
|
126
152
|
return;
|
|
@@ -131,31 +157,19 @@ export default class QueryStatementBuilder {
|
|
|
131
157
|
? condition.column
|
|
132
158
|
: `${tableName}.${condition.column}`,
|
|
133
159
|
};
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
static normalizeQueryConditions(where) {
|
|
137
|
-
if (Array.isArray(where)) {
|
|
138
|
-
return where;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
return Object.entries(where).map(([column, value]) => ({
|
|
142
|
-
column,
|
|
143
|
-
operator: "=",
|
|
144
|
-
value,
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
160
|
+
})
|
|
161
|
+
.filter((cond) => cond !== undefined);
|
|
147
162
|
}
|
|
148
163
|
// Copilot moment maybe refactor this later
|
|
149
164
|
addUnique(target, values) {
|
|
150
165
|
if (!(values === null || values === void 0 ? void 0 : values.length))
|
|
151
166
|
return target !== null && target !== void 0 ? target : [];
|
|
152
|
-
const set = new Set((target !== null && target !== void 0 ? target : []).map(v => JSON.stringify(v)));
|
|
167
|
+
const set = new Set((target !== null && target !== void 0 ? target : []).map((v) => JSON.stringify(v)));
|
|
153
168
|
for (const v of values) {
|
|
154
169
|
const key = JSON.stringify(v);
|
|
155
170
|
if (!set.has(key))
|
|
156
171
|
set.add(key);
|
|
157
172
|
}
|
|
158
|
-
return Array.from(set).map(s => JSON.parse(s));
|
|
173
|
+
return Array.from(set).map((s) => JSON.parse(s));
|
|
159
174
|
}
|
|
160
|
-
;
|
|
161
175
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { QueryContext } from
|
|
2
|
-
export
|
|
1
|
+
import { QueryContext } from '../../types/query.js';
|
|
2
|
+
export declare class SqlGenerator {
|
|
3
3
|
private _context;
|
|
4
4
|
constructor(context: QueryContext);
|
|
5
5
|
build(): string;
|
|
@@ -12,4 +12,4 @@ export default class SqlRenderer {
|
|
|
12
12
|
private renderLimit;
|
|
13
13
|
private renderOffset;
|
|
14
14
|
}
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=SqlGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlGenerator.d.ts","sourceRoot":"","sources":["../../../src/helpers/QueryBuilders/SqlGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG/E,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAe;gBAEnB,OAAO,EAAE,YAAY;IAI1B,KAAK,IAAI,MAAM;IAgBtB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,YAAY;CAOvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { InvalidWhereConditionError } from '../Errors/QueryErrors/InvalidWhereConditionError.js';
|
|
2
|
+
export class SqlGenerator {
|
|
2
3
|
constructor(context) {
|
|
3
4
|
this._context = context;
|
|
4
5
|
}
|
|
@@ -7,34 +8,42 @@ export default class SqlRenderer {
|
|
|
7
8
|
return [
|
|
8
9
|
this.renderSelect(),
|
|
9
10
|
this.renderFrom(),
|
|
10
|
-
(_a = this._context.joins) === null || _a === void 0 ? void 0 : _a.join(
|
|
11
|
+
(_a = this._context.joins) === null || _a === void 0 ? void 0 : _a.join(' '),
|
|
11
12
|
this.renderWhere(),
|
|
12
13
|
this.renderGroupBy(),
|
|
13
14
|
this.renderOrderBy(),
|
|
14
15
|
this.renderLimit(),
|
|
15
|
-
this.renderOffset()
|
|
16
|
-
]
|
|
16
|
+
this.renderOffset(),
|
|
17
|
+
]
|
|
18
|
+
.map((e) => e === null || e === void 0 ? void 0 : e.trim())
|
|
19
|
+
.filter((e) => e !== '')
|
|
20
|
+
.join(' ');
|
|
17
21
|
}
|
|
18
22
|
renderSelect() {
|
|
19
23
|
const selects = [];
|
|
20
24
|
if (this._context.select && this._context.select.length > 0) {
|
|
21
25
|
selects.push(...this._context.select);
|
|
22
26
|
}
|
|
23
|
-
else if (!this._context.joinsSelect ||
|
|
27
|
+
else if (!this._context.joinsSelect ||
|
|
28
|
+
this._context.joinsSelect.length === 0) {
|
|
24
29
|
selects.push('*');
|
|
25
30
|
}
|
|
26
31
|
selects.push(...(this._context.joinsSelect || []));
|
|
27
32
|
selects.push(...(this._context.expressionSelect || []));
|
|
28
|
-
return selects.length > 0 ? `SELECT ${selects.join(
|
|
33
|
+
return selects.length > 0 ? `SELECT ${selects.join(', ')}` : 'SELECT *';
|
|
29
34
|
}
|
|
30
35
|
renderFrom() {
|
|
31
|
-
return this._context.from ? `FROM ${this._context.from}` :
|
|
36
|
+
return this._context.from ? `FROM ${this._context.from}` : '';
|
|
32
37
|
}
|
|
33
38
|
renderWhere() {
|
|
34
|
-
var _a;
|
|
35
|
-
if (
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (((_a = this._context.conditions) === null || _a === void 0 ? void 0 : _a.where) &&
|
|
41
|
+
this._context.conditions.where instanceof Date) {
|
|
42
|
+
throw new InvalidWhereConditionError('Date objects are not supported in WHERE conditions.');
|
|
43
|
+
}
|
|
44
|
+
if (!((_b = this._context.conditions) === null || _b === void 0 ? void 0 : _b.where) ||
|
|
36
45
|
Object.keys(this._context.conditions.where).length === 0) {
|
|
37
|
-
return
|
|
46
|
+
return '';
|
|
38
47
|
}
|
|
39
48
|
return `WHERE ${this.buildWhereWithOperators(this._context.conditions.where)}`;
|
|
40
49
|
}
|
|
@@ -42,36 +51,38 @@ export default class SqlRenderer {
|
|
|
42
51
|
return where
|
|
43
52
|
.map((condition) => {
|
|
44
53
|
const colName = condition.column.trim();
|
|
45
|
-
const paramName = colName.includes(
|
|
54
|
+
const paramName = colName.includes('.')
|
|
55
|
+
? colName.split('.')[1].trim()
|
|
56
|
+
: colName;
|
|
46
57
|
return `${colName} ${condition.operator} @${paramName}`;
|
|
47
58
|
})
|
|
48
59
|
.filter(Boolean)
|
|
49
|
-
.join(
|
|
60
|
+
.join(' AND ');
|
|
50
61
|
}
|
|
51
62
|
renderOrderBy() {
|
|
52
63
|
if (!this._context.orderBy || this._context.orderBy.length === 0) {
|
|
53
|
-
return
|
|
64
|
+
return '';
|
|
54
65
|
}
|
|
55
|
-
const orderByClauses = this._context.orderBy.map(ob => {
|
|
66
|
+
const orderByClauses = this._context.orderBy.map((ob) => {
|
|
56
67
|
return `${ob.column} ${ob.direction}`;
|
|
57
68
|
});
|
|
58
|
-
return `ORDER BY ${orderByClauses.join(
|
|
69
|
+
return `ORDER BY ${orderByClauses.join(', ')}`;
|
|
59
70
|
}
|
|
60
71
|
renderGroupBy() {
|
|
61
72
|
if (!this._context.groupBy || this._context.groupBy.length === 0) {
|
|
62
|
-
return
|
|
73
|
+
return '';
|
|
63
74
|
}
|
|
64
|
-
return `GROUP BY ${this._context.groupBy.join(
|
|
75
|
+
return `GROUP BY ${this._context.groupBy.join(', ')}`;
|
|
65
76
|
}
|
|
66
77
|
renderLimit() {
|
|
67
78
|
if (!this._context.limit) {
|
|
68
|
-
return
|
|
79
|
+
return '';
|
|
69
80
|
}
|
|
70
81
|
return `LIMIT ${this._context.limit}`;
|
|
71
82
|
}
|
|
72
83
|
renderOffset() {
|
|
73
84
|
if (!this._context.offset) {
|
|
74
|
-
return
|
|
85
|
+
return '';
|
|
75
86
|
}
|
|
76
87
|
return `OFFSET ${this._context.offset}`;
|
|
77
88
|
}
|