@entity-access/entity-access 1.0.198 → 1.0.200
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/entity-query/EntityType.js +2 -2
- package/dist/entity-query/EntityType.js.map +1 -1
- package/dist/model/SourceExpression.js +2 -2
- package/dist/model/SourceExpression.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.d.ts +0 -1
- package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +4 -64
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/query/ast/Expressions.d.ts +4 -1
- package/dist/query/ast/Expressions.d.ts.map +1 -1
- package/dist/query/ast/Expressions.js +11 -2
- package/dist/query/ast/Expressions.js.map +1 -1
- package/dist/query/expander/QueryExpander.js +2 -2
- package/dist/query/expander/QueryExpander.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/workflows/WorkflowStorage.d.ts.map +1 -1
- package/dist/workflows/WorkflowStorage.js +11 -4
- package/dist/workflows/WorkflowStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/entity-query/EntityType.ts +2 -2
- package/src/model/SourceExpression.ts +2 -2
- package/src/query/ast/ExpressionToSql.ts +78 -76
- package/src/query/ast/Expressions.ts +14 -2
- package/src/query/expander/QueryExpander.ts +2 -2
- package/src/workflows/WorkflowStorage.ts +18 -6
|
@@ -693,8 +693,10 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
693
693
|
return join.as;
|
|
694
694
|
}
|
|
695
695
|
const joinType = select.preferLeftJoins ? "LEFT" : (fkColumn.nullable ? "LEFT" : "INNER");
|
|
696
|
-
const joinParameter = ParameterExpression.create({
|
|
697
|
-
|
|
696
|
+
const joinParameter = ParameterExpression.create({
|
|
697
|
+
name: relation.relatedEntity.name[0],
|
|
698
|
+
model: relation.relatedEntity
|
|
699
|
+
});
|
|
698
700
|
join = JoinExpression.create({
|
|
699
701
|
as: joinParameter,
|
|
700
702
|
joinType,
|
|
@@ -779,79 +781,79 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
779
781
|
// };
|
|
780
782
|
}
|
|
781
783
|
|
|
782
|
-
private flatten(pc: IPropertyChain) : IPropertyChain {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
}
|
|
784
|
+
// private flatten(pc: IPropertyChain) : IPropertyChain {
|
|
785
|
+
|
|
786
|
+
// if (!pc) {
|
|
787
|
+
// return pc;
|
|
788
|
+
// }
|
|
789
|
+
|
|
790
|
+
// // check if we have parameter..
|
|
791
|
+
// let { parameter } = pc;
|
|
792
|
+
// if (!parameter) {
|
|
793
|
+
// return pc;
|
|
794
|
+
// }
|
|
795
|
+
// if (pc.chain.length <= 1) {
|
|
796
|
+
// return pc;
|
|
797
|
+
// }
|
|
798
|
+
|
|
799
|
+
// const chain = [ ... pc.chain];
|
|
800
|
+
|
|
801
|
+
// const scope = this.scope.get(parameter);
|
|
802
|
+
// const select = scope?.selectStatement ?? this.source?.selectStatement;
|
|
803
|
+
// if (!select) {
|
|
804
|
+
// return pc;
|
|
805
|
+
// }
|
|
806
|
+
// let type = select.model;
|
|
807
|
+
|
|
808
|
+
// select.joins ??= [];
|
|
809
|
+
|
|
810
|
+
// while(chain.length > 1) {
|
|
811
|
+
// const property = chain.shift();
|
|
812
|
+
// const propertyInfo = type.getProperty(property);
|
|
813
|
+
// if (!propertyInfo.relation || propertyInfo.relation.isInverseRelation) {
|
|
814
|
+
// return pc;
|
|
815
|
+
// }
|
|
816
|
+
|
|
817
|
+
// const relation = propertyInfo.relation;
|
|
818
|
+
// // check if relation is optional...
|
|
819
|
+
// if (!relation.fkColumn) {
|
|
820
|
+
// return pc;
|
|
821
|
+
// }
|
|
822
|
+
|
|
823
|
+
// const { fkColumn } = relation;
|
|
824
|
+
|
|
825
|
+
// const join = select.joins.find((x) => x.model === relation.relatedEntity);
|
|
826
|
+
// if (!join) {
|
|
827
|
+
// const joinType = fkColumn.nullable ? "LEFT" : "INNER";
|
|
828
|
+
// const joinParameter = ParameterExpression.create({ name: relation.relatedEntity.name[0]});
|
|
829
|
+
// joinParameter.model = relation.relatedEntity;
|
|
830
|
+
// select.joins.push(JoinExpression.create({
|
|
831
|
+
// as: joinParameter,
|
|
832
|
+
// joinType,
|
|
833
|
+
// model: joinParameter.model,
|
|
834
|
+
// source: Expression.identifier(relation.relatedEntity.name),
|
|
835
|
+
// where: Expression.equal(
|
|
836
|
+
// Expression.member(parameter, fkColumn.columnName),
|
|
837
|
+
// Expression.member(joinParameter, relation.relatedEntity.keys[0].columnName)
|
|
838
|
+
// )
|
|
839
|
+
// }));
|
|
840
|
+
// parameter = joinParameter;
|
|
841
|
+
// type = relation.relatedEntity;
|
|
842
|
+
// this.scope.create({ parameter, model: type, selectStatement: select });
|
|
843
|
+
// pc.parameter = parameter;
|
|
844
|
+
// pc.chain = [ ... chain ];
|
|
845
|
+
// } else {
|
|
846
|
+
// // we will add parameter in scope in case if it is not there
|
|
847
|
+
// // this is the case when query is composed over already existing
|
|
848
|
+
// // there is still an error on this one...
|
|
849
|
+
// pc.parameter = parameter = join.as as ParameterExpression;
|
|
850
|
+
// type = join.model;
|
|
851
|
+
// pc.chain = [... chain];
|
|
852
|
+
// this.scope.create({ parameter, model: type, selectStatement: select });
|
|
853
|
+
// }
|
|
854
|
+
// }
|
|
855
|
+
|
|
856
|
+
// return pc;
|
|
857
|
+
// }
|
|
856
858
|
|
|
857
859
|
}
|
|
@@ -58,8 +58,8 @@ export abstract class Expression {
|
|
|
58
58
|
return Constant.create({ value });
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
static parameter(name: string) {
|
|
62
|
-
return ParameterExpression.create({ name });
|
|
61
|
+
static parameter(name: string, model?: EntityType) {
|
|
62
|
+
return ParameterExpression.create({ name, model });
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
static identifier(name: string) {
|
|
@@ -70,6 +70,10 @@ export abstract class Expression {
|
|
|
70
70
|
return BinaryExpression.create({ left, operator: "AND", right});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
static logicalOr(left: Expression, right: Expression): BinaryExpression {
|
|
74
|
+
return BinaryExpression.create({ left, operator: "OR", right});
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
static member(target: Expression, identifier: string |Expression): MemberExpression {
|
|
74
78
|
return MemberExpression.create({
|
|
75
79
|
target,
|
|
@@ -83,6 +87,14 @@ export abstract class Expression {
|
|
|
83
87
|
return BinaryExpression.create({ left, right, operator: "="});
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
static less(left: Expression, right: Expression) {
|
|
91
|
+
return BinaryExpression.create({ left, right, operator: "<"});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static lessOrEqual(left: Expression, right: Expression) {
|
|
95
|
+
return BinaryExpression.create({ left, right, operator: "<="});
|
|
96
|
+
}
|
|
97
|
+
|
|
86
98
|
static assign(left: Expression, right: Expression) {
|
|
87
99
|
return BinaryExpression.create({ left, right, operator: "="});
|
|
88
100
|
}
|
|
@@ -109,7 +109,7 @@ export class QueryExpander {
|
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
const joins = (select.joins ??= []);
|
|
112
|
-
const joinParameter = Expression.parameter(parent.sourceParameter.name);
|
|
112
|
+
const joinParameter = Expression.parameter(parent.sourceParameter.name, parent.model);
|
|
113
113
|
|
|
114
114
|
// This join has to be INNER JOIN as we are only interested
|
|
115
115
|
// in the results that matches parent query exactly
|
|
@@ -175,7 +175,7 @@ export class QueryExpander {
|
|
|
175
175
|
// : existsWhere;
|
|
176
176
|
|
|
177
177
|
const selectJoins = (select.joins ??= []);
|
|
178
|
-
const selectJoinParameter = Expression.parameter(parent.sourceParameter.name);
|
|
178
|
+
const selectJoinParameter = Expression.parameter(parent.sourceParameter.name, parent.model);
|
|
179
179
|
|
|
180
180
|
// This join has to be INNER JOIN as we are only interested
|
|
181
181
|
// in the results that matches parent query exactly
|
|
@@ -251,9 +251,17 @@ export default class WorkflowStorage {
|
|
|
251
251
|
where: Expression.logicalAnd(Expression.equal(
|
|
252
252
|
Expression.identifier("id"),
|
|
253
253
|
Expression.member(px, "id")
|
|
254
|
-
), Expression.
|
|
255
|
-
Expression.
|
|
256
|
-
|
|
254
|
+
), Expression.logicalOr(
|
|
255
|
+
Expression.equal(
|
|
256
|
+
Expression.identifier(lockTTLField),
|
|
257
|
+
NullExpression.create({})
|
|
258
|
+
),
|
|
259
|
+
Expression.lessOrEqual(
|
|
260
|
+
Expression.identifier(lockTTLField),
|
|
261
|
+
CallExpression.create({
|
|
262
|
+
callee: Expression.member(Expression.member(Expression.identifier("Sql"), "date"), "now")
|
|
263
|
+
})
|
|
264
|
+
)
|
|
257
265
|
))
|
|
258
266
|
});
|
|
259
267
|
|
|
@@ -279,9 +287,13 @@ export default class WorkflowStorage {
|
|
|
279
287
|
for (const iterator of items) {
|
|
280
288
|
// try to acquire lock...
|
|
281
289
|
iterator.lockToken = uuid;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
try {
|
|
291
|
+
const r = await q.invoke(db.connection, iterator);
|
|
292
|
+
if (r.updated > 0) {
|
|
293
|
+
list.push(iterator);
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error(error);
|
|
285
297
|
}
|
|
286
298
|
}
|
|
287
299
|
return list;
|