@entity-access/entity-access 1.0.54 → 1.0.56
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/compiler/NamingConventions.d.ts +7 -0
- package/dist/compiler/NamingConventions.d.ts.map +1 -0
- package/dist/compiler/NamingConventions.js +7 -0
- package/dist/compiler/NamingConventions.js.map +1 -0
- package/dist/compiler/QueryCompiler.d.ts +2 -2
- package/dist/compiler/QueryCompiler.d.ts.map +1 -1
- package/dist/compiler/QueryCompiler.js +8 -3
- package/dist/compiler/QueryCompiler.js.map +1 -1
- package/dist/decorators/Column.d.ts.map +1 -1
- package/dist/decorators/Column.js +3 -0
- package/dist/decorators/Column.js.map +1 -1
- package/dist/decorators/IColumn.d.ts +5 -0
- package/dist/decorators/IColumn.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.js +7 -7
- package/dist/drivers/base/BaseDriver.js.map +1 -1
- package/dist/drivers/postgres/PostgreSqlDriver.js +1 -1
- package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
- package/dist/drivers/sql-server/ExpressionToSqlServer.d.ts.map +1 -1
- package/dist/drivers/sql-server/ExpressionToSqlServer.js +2 -2
- package/dist/drivers/sql-server/ExpressionToSqlServer.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js +6 -2
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js.map +1 -1
- package/dist/entity-query/EntityType.d.ts +7 -5
- package/dist/entity-query/EntityType.d.ts.map +1 -1
- package/dist/entity-query/EntityType.js +31 -14
- package/dist/entity-query/EntityType.js.map +1 -1
- package/dist/eternity/EternityStorage.d.ts +1 -1
- package/dist/eternity/EternityStorage.d.ts.map +1 -1
- package/dist/eternity/EternityStorage.js +4 -4
- package/dist/eternity/EternityStorage.js.map +1 -1
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +5 -4
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js +17 -14
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +12 -12
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/model/EntityContext.d.ts +1 -0
- package/dist/model/EntityContext.d.ts.map +1 -1
- package/dist/model/EntityContext.js +20 -0
- package/dist/model/EntityContext.js.map +1 -1
- package/dist/model/EntityModel.d.ts +4 -1
- package/dist/model/EntityModel.d.ts.map +1 -1
- package/dist/model/EntityModel.js +36 -5
- package/dist/model/EntityModel.js.map +1 -1
- package/dist/model/EntityQuery.d.ts.map +1 -1
- package/dist/model/EntityQuery.js +7 -7
- package/dist/model/EntityQuery.js.map +1 -1
- package/dist/model/SourceExpression.d.ts.map +1 -1
- package/dist/model/SourceExpression.js +3 -4
- package/dist/model/SourceExpression.js.map +1 -1
- package/dist/model/changes/ChangeEntry.js +2 -2
- package/dist/model/changes/ChangeEntry.js.map +1 -1
- package/dist/model/changes/ChangeSet.js +1 -2
- package/dist/model/changes/ChangeSet.js.map +1 -1
- package/dist/model/verification/VerificationSession.d.ts.map +1 -1
- package/dist/model/verification/VerificationSession.js +6 -6
- package/dist/model/verification/VerificationSession.js.map +1 -1
- package/dist/query/ast/DebugStringVisitor.d.ts +1 -2
- package/dist/query/ast/DebugStringVisitor.d.ts.map +1 -1
- package/dist/query/ast/DebugStringVisitor.js +0 -3
- package/dist/query/ast/DebugStringVisitor.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.d.ts +1 -2
- package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +22 -20
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/query/ast/Expressions.d.ts +15 -20
- package/dist/query/ast/Expressions.d.ts.map +1 -1
- package/dist/query/ast/Expressions.js +17 -19
- package/dist/query/ast/Expressions.js.map +1 -1
- package/dist/query/ast/IStringTransformer.d.ts +2 -3
- package/dist/query/ast/IStringTransformer.d.ts.map +1 -1
- package/dist/query/ast/IStringTransformer.js +4 -6
- package/dist/query/ast/IStringTransformer.js.map +1 -1
- package/dist/query/ast/Visitor.d.ts +1 -2
- package/dist/query/ast/Visitor.d.ts.map +1 -1
- package/dist/query/ast/Visitor.js +0 -5
- package/dist/query/ast/Visitor.js.map +1 -1
- package/dist/query/expander/QueryExpander.js +7 -7
- package/dist/query/expander/QueryExpander.js.map +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.js +2 -2
- package/dist/query/parser/ArrowToExpression.js.map +1 -1
- package/dist/tests/eternity/eternity-tests.d.ts.map +1 -1
- package/dist/tests/eternity/eternity-tests.js +1 -1
- package/dist/tests/eternity/eternity-tests.js.map +1 -1
- package/dist/tests/expressions/left-joins/child-joins.js +41 -41
- package/dist/tests/expressions/left-joins/child-joins.js.map +1 -1
- package/dist/tests/expressions/select/select.d.ts.map +1 -1
- package/dist/tests/expressions/select/select.js +2 -2
- package/dist/tests/expressions/select/select.js.map +1 -1
- package/dist/tests/expressions/simple/parse-arrow.js +10 -10
- package/dist/tests/expressions/simple/parse-arrow.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/compiler/NamingConventions.ts +6 -0
- package/src/compiler/QueryCompiler.ts +7 -5
- package/src/decorators/Column.ts +3 -0
- package/src/decorators/IColumn.ts +7 -0
- package/src/drivers/base/BaseDriver.ts +9 -9
- package/src/drivers/postgres/PostgreSqlDriver.ts +1 -1
- package/src/drivers/sql-server/ExpressionToSqlServer.ts +2 -2
- package/src/drivers/sql-server/SqlServerQueryCompiler.ts +5 -2
- package/src/entity-query/EntityType.ts +34 -13
- package/src/eternity/EternityStorage.ts +3 -3
- package/src/migrations/Migrations.ts +5 -3
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +17 -14
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +12 -12
- package/src/model/EntityContext.ts +22 -1
- package/src/model/EntityModel.ts +41 -7
- package/src/model/EntityQuery.ts +7 -7
- package/src/model/SourceExpression.ts +3 -4
- package/src/model/changes/ChangeEntry.ts +2 -2
- package/src/model/changes/ChangeSet.ts +1 -1
- package/src/model/verification/VerificationSession.ts +6 -7
- package/src/query/ast/DebugStringVisitor.ts +1 -5
- package/src/query/ast/ExpressionToSql.ts +24 -21
- package/src/query/ast/Expressions.ts +33 -34
- package/src/query/ast/IStringTransformer.ts +4 -4
- package/src/query/ast/Visitor.ts +1 -7
- package/src/query/expander/QueryExpander.ts +9 -9
- package/src/query/parser/ArrowToExpression.ts +2 -2
- package/src/tests/eternity/eternity-tests.ts +2 -1
- package/src/tests/expressions/left-joins/child-joins.ts +41 -41
- package/src/tests/expressions/select/select.ts +2 -5
- package/src/tests/expressions/simple/parse-arrow.ts +10 -10
|
@@ -2,7 +2,7 @@ import QueryCompiler from "../../compiler/QueryCompiler.js";
|
|
|
2
2
|
import EntityType from "../../entity-query/EntityType.js";
|
|
3
3
|
import EntityQuery from "../../model/EntityQuery.js";
|
|
4
4
|
import { filteredSymbol } from "../../model/events/EntityEvents.js";
|
|
5
|
-
import { BigIntLiteral, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, ExpressionType, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression,
|
|
5
|
+
import { BigIntLiteral, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, ExpressionType, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression, ReturnUpdated, SelectStatement, StringLiteral, TableLiteral, TemplateLiteral, UnionAllStatement, UpdateStatement, ValuesStatement } from "./Expressions.js";
|
|
6
6
|
import { ITextQuery, QueryParameter, prepare, prepareJoin } from "./IStringTransformer.js";
|
|
7
7
|
import ParameterScope from "./ParameterScope.js";
|
|
8
8
|
import Visitor from "./Visitor.js";
|
|
@@ -75,7 +75,7 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
75
75
|
const source = e.source.type === "ValuesStatement"
|
|
76
76
|
? prepare `(${this.visit(e.source)})`
|
|
77
77
|
: this.visit(e.source);
|
|
78
|
-
const as = e.sourceParameter ? prepare ` AS ${this.
|
|
78
|
+
const as = e.sourceParameter ? prepare ` AS ${this.scope.nameOf(e.sourceParameter)}` : "";
|
|
79
79
|
const fields = this.visitArray(e.fields, ",\n\t\t");
|
|
80
80
|
return prepare `SELECT
|
|
81
81
|
${fields}
|
|
@@ -100,10 +100,6 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
visitQuotedLiteral(e: QuotedLiteral): ITextQuery {
|
|
104
|
-
return [this.compiler.quotedLiteral(e.literal)];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
103
|
visitExpressionAs(e: ExpressionAs): ITextQuery {
|
|
108
104
|
return prepare `${this.visit(e.expression)} AS ${this.visit(e.alias)}`;
|
|
109
105
|
}
|
|
@@ -113,16 +109,16 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
113
109
|
}
|
|
114
110
|
|
|
115
111
|
visitBigIntLiteral({ value }: BigIntLiteral): ITextQuery {
|
|
116
|
-
return [()
|
|
112
|
+
return [value.toString()];
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
visitNumberLiteral( { value }: NumberLiteral): ITextQuery {
|
|
120
|
-
return [()
|
|
116
|
+
return [value.toString()];
|
|
121
117
|
}
|
|
122
118
|
|
|
123
119
|
visitStringLiteral({ value }: StringLiteral): ITextQuery {
|
|
124
120
|
const escapeLiteral = this.compiler.escapeLiteral;
|
|
125
|
-
return [
|
|
121
|
+
return [escapeLiteral(value)];
|
|
126
122
|
}
|
|
127
123
|
|
|
128
124
|
visitBooleanLiteral( { value }: BooleanLiteral): ITextQuery {
|
|
@@ -163,15 +159,15 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
163
159
|
let select: SelectStatement;
|
|
164
160
|
|
|
165
161
|
if (this.source?.context) {
|
|
166
|
-
|
|
167
|
-
// check if we have filter...
|
|
168
|
-
const entityEvents = this.source.context.eventsFor(relatedType, false);
|
|
169
|
-
if (entityEvents) {
|
|
170
|
-
|
|
171
|
-
}
|
|
162
|
+
const query = this.source.context.filteredQuery(relatedType, "include", false);
|
|
163
|
+
// // check if we have filter...
|
|
164
|
+
// const entityEvents = this.source.context.eventsFor(relatedType, false);
|
|
165
|
+
// if (entityEvents) {
|
|
166
|
+
// query = entityEvents.includeFilter(query);
|
|
167
|
+
// }
|
|
172
168
|
select = { ... (query as EntityQuery).selectStatement };
|
|
173
169
|
select.fields = [
|
|
174
|
-
|
|
170
|
+
NumberLiteral.create({ value: 1})
|
|
175
171
|
];
|
|
176
172
|
} else {
|
|
177
173
|
select = relatedModel.selectOneNumber();
|
|
@@ -273,7 +269,14 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
273
269
|
return [(p) => p[chain[0]]];
|
|
274
270
|
}
|
|
275
271
|
const name = this.scope.nameOf(parameter);
|
|
276
|
-
|
|
272
|
+
|
|
273
|
+
// need to change name as per naming convention here...
|
|
274
|
+
const namingConvention = this.compiler.namingConvention;
|
|
275
|
+
if (scope.model && namingConvention) {
|
|
276
|
+
chain[0] = namingConvention(chain[0]);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return [ QueryParameter.create(() => name) , "." , chain.join(".")];
|
|
277
280
|
}
|
|
278
281
|
|
|
279
282
|
const { target, computed, property } = me;
|
|
@@ -395,9 +398,9 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
395
398
|
}
|
|
396
399
|
const table = this.visit(e.source);
|
|
397
400
|
const where = this.visit(e.where);
|
|
398
|
-
const as = e.as ? prepare ` AS ${ e.as.type === "
|
|
399
|
-
?
|
|
400
|
-
: this.
|
|
401
|
+
const as = e.as ? prepare ` AS ${ e.as.type === "Identifier"
|
|
402
|
+
? e.as.value
|
|
403
|
+
: this.scope.nameOf(e.as )}` : "";
|
|
401
404
|
return prepare ` ${e.joinType || "LEFT"} JOIN ${table}${as} ON ${where}`;
|
|
402
405
|
}
|
|
403
406
|
|
|
@@ -519,7 +522,7 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
519
522
|
as: joinParameter,
|
|
520
523
|
joinType,
|
|
521
524
|
model: joinParameter.model,
|
|
522
|
-
source: Expression.
|
|
525
|
+
source: Expression.identifier(relation.relatedEntity.name),
|
|
523
526
|
where: Expression.equal(
|
|
524
527
|
Expression.member(parameter, fkColumn.columnName),
|
|
525
528
|
Expression.member(joinParameter, relation.relatedEntity.keys[0].columnName)
|
|
@@ -29,9 +29,9 @@ export abstract class Expression {
|
|
|
29
29
|
return ArrayExpression.create({ elements });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static as(expression: Expression, alias:
|
|
32
|
+
static as(expression: Expression, alias: Identifier | string) {
|
|
33
33
|
if (typeof alias === "string") {
|
|
34
|
-
alias = Expression.
|
|
34
|
+
alias = Expression.identifier(alias);
|
|
35
35
|
}
|
|
36
36
|
return ExpressionAs.create({
|
|
37
37
|
expression,
|
|
@@ -48,10 +48,6 @@ export abstract class Expression {
|
|
|
48
48
|
return Constant.create({ value });
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
static quotedLiteral(name: string) {
|
|
52
|
-
return QuotedLiteral.create({ literal: name });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
51
|
static parameter(name: string) {
|
|
56
52
|
return ParameterExpression.create({ name });
|
|
57
53
|
}
|
|
@@ -155,8 +151,8 @@ export class CoalesceExpression extends Expression {
|
|
|
155
151
|
|
|
156
152
|
export class ValuesStatement extends Expression {
|
|
157
153
|
readonly type = "ValuesStatement";
|
|
158
|
-
as:
|
|
159
|
-
fields:
|
|
154
|
+
as: Identifier;
|
|
155
|
+
fields: Identifier[];
|
|
160
156
|
values: Expression[][];
|
|
161
157
|
}
|
|
162
158
|
|
|
@@ -215,7 +211,7 @@ export class ArrowFunctionExpression extends Expression {
|
|
|
215
211
|
body: Expression;
|
|
216
212
|
}
|
|
217
213
|
|
|
218
|
-
export type TableSource = SelectStatement |
|
|
214
|
+
export type TableSource = SelectStatement | Identifier | ExpressionAs | TableLiteral;
|
|
219
215
|
|
|
220
216
|
export type Expand = { [key: string]: string | Expand };
|
|
221
217
|
|
|
@@ -227,7 +223,7 @@ export class SelectStatement extends Expression {
|
|
|
227
223
|
|
|
228
224
|
sourceParameter: ParameterExpression;
|
|
229
225
|
|
|
230
|
-
fields: (Expression |
|
|
226
|
+
fields: (Expression | Identifier | ExpressionAs)[];
|
|
231
227
|
|
|
232
228
|
where: Expression;
|
|
233
229
|
|
|
@@ -261,8 +257,8 @@ export class ConditionalExpression extends Expression {
|
|
|
261
257
|
export class JoinExpression extends Expression {
|
|
262
258
|
readonly type = "JoinExpression";
|
|
263
259
|
joinType: "LEFT" | "INNER";
|
|
264
|
-
source: SelectStatement |
|
|
265
|
-
as:
|
|
260
|
+
source: SelectStatement | Identifier | ExpressionAs | TableLiteral;
|
|
261
|
+
as: Identifier | ParameterExpression;
|
|
266
262
|
where: Expression;
|
|
267
263
|
model: EntityType;
|
|
268
264
|
}
|
|
@@ -270,7 +266,7 @@ export class JoinExpression extends Expression {
|
|
|
270
266
|
export class ReturnUpdated extends Expression {
|
|
271
267
|
readonly type = "ReturnUpdated";
|
|
272
268
|
|
|
273
|
-
fields:
|
|
269
|
+
fields: Identifier[];
|
|
274
270
|
|
|
275
271
|
changes: "INSERTED" | "DELETED" | "UPDATED";
|
|
276
272
|
}
|
|
@@ -300,6 +296,9 @@ export class BooleanLiteral extends Expression {
|
|
|
300
296
|
}
|
|
301
297
|
|
|
302
298
|
export class NumberLiteral extends Expression {
|
|
299
|
+
|
|
300
|
+
static one = NumberLiteral.create({ value: 1 });
|
|
301
|
+
|
|
303
302
|
readonly type = "NumberLiteral";
|
|
304
303
|
public value: number;
|
|
305
304
|
}
|
|
@@ -323,34 +322,34 @@ export class TemplateLiteral extends Expression {
|
|
|
323
322
|
public value: Expression[];
|
|
324
323
|
}
|
|
325
324
|
|
|
326
|
-
export class QuotedLiteral extends Expression {
|
|
325
|
+
// export class QuotedLiteral extends Expression {
|
|
327
326
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
327
|
+
// static propertyChain(... properties: string[]): Expression {
|
|
328
|
+
// const literal = properties.pop();
|
|
329
|
+
// const property = QuotedLiteral.create({ literal });
|
|
330
|
+
// if (properties.length === 0) {
|
|
331
|
+
// return property;
|
|
332
|
+
// }
|
|
333
|
+
// return MemberExpression.create({
|
|
334
|
+
// target: QuotedLiteral.propertyChain(... properties),
|
|
335
|
+
// property
|
|
336
|
+
// });
|
|
337
|
+
// }
|
|
339
338
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
339
|
+
// readonly type = "QuotedLiteral";
|
|
340
|
+
// public literal: string;
|
|
341
|
+
// }
|
|
343
342
|
|
|
344
343
|
export class ExpressionAs extends Expression {
|
|
345
344
|
readonly type = "ExpressionAs";
|
|
346
345
|
expression: Expression;
|
|
347
|
-
alias:
|
|
346
|
+
alias: Identifier;
|
|
348
347
|
}
|
|
349
348
|
|
|
350
349
|
export class TableLiteral extends Expression {
|
|
351
350
|
readonly type = "TableLiteral";
|
|
352
|
-
schema:
|
|
353
|
-
name:
|
|
351
|
+
schema: Identifier;
|
|
352
|
+
name: Identifier;
|
|
354
353
|
|
|
355
354
|
}
|
|
356
355
|
|
|
@@ -368,7 +367,7 @@ export class UpdateStatement extends Expression {
|
|
|
368
367
|
|
|
369
368
|
readonly type = "UpdateStatement";
|
|
370
369
|
|
|
371
|
-
table: TableLiteral |
|
|
370
|
+
table: TableLiteral | Identifier;
|
|
372
371
|
|
|
373
372
|
set: BinaryExpression[];
|
|
374
373
|
|
|
@@ -383,7 +382,7 @@ export class UnionAllStatement extends Expression {
|
|
|
383
382
|
|
|
384
383
|
export class DeleteStatement extends Expression {
|
|
385
384
|
readonly type = "DeleteStatement";
|
|
386
|
-
table: TableLiteral |
|
|
385
|
+
table: TableLiteral | Identifier
|
|
387
386
|
where: Expression;
|
|
388
387
|
}
|
|
389
388
|
|
|
@@ -392,7 +391,7 @@ export type ExpressionType =
|
|
|
392
391
|
ValuesStatement |
|
|
393
392
|
SelectStatement |
|
|
394
393
|
Constant|
|
|
395
|
-
QuotedLiteral|
|
|
394
|
+
// QuotedLiteral|
|
|
396
395
|
ExpressionAs|
|
|
397
396
|
TableLiteral|
|
|
398
397
|
InsertStatement|
|
|
@@ -9,14 +9,14 @@ export type ISqlMethodTransformer = (compiler: QueryCompiler, callee: string[],
|
|
|
9
9
|
|
|
10
10
|
export class QueryParameter {
|
|
11
11
|
|
|
12
|
-
static create(name: () => string
|
|
13
|
-
return new QueryParameter(name
|
|
12
|
+
static create(name: () => string) {
|
|
13
|
+
return new QueryParameter(name);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
constructor(public name: () => string
|
|
16
|
+
constructor(public name: () => string) {}
|
|
17
17
|
|
|
18
18
|
toString() {
|
|
19
|
-
return this.
|
|
19
|
+
return this.name();
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
package/src/query/ast/Visitor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NotSupportedError } from "../parser/NotSupportedError.js";
|
|
2
|
-
import { ArrayExpression, ArrowFunctionExpression, BigIntLiteral, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, ExpressionType, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression,
|
|
2
|
+
import { ArrayExpression, ArrowFunctionExpression, BigIntLiteral, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, DeleteStatement, ExistsExpression, Expression, ExpressionAs, ExpressionType, Identifier, InsertStatement, JoinExpression, MemberExpression, NewObjectExpression, NotExits, NullExpression, NumberLiteral, OrderByExpression, ParameterExpression, ReturnUpdated, SelectStatement, StringLiteral, TableLiteral, TemplateElement, TemplateLiteral, UnionAllStatement, UpdateStatement, ValuesStatement } from "./Expressions.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export default abstract class Visitor<T = any> {
|
|
@@ -15,8 +15,6 @@ export default abstract class Visitor<T = any> {
|
|
|
15
15
|
return this.visitConstant(e);
|
|
16
16
|
case "ExpressionAs":
|
|
17
17
|
return this.visitExpressionAs(e);
|
|
18
|
-
case "QuotedLiteral":
|
|
19
|
-
return this.visitQuotedLiteral(e);
|
|
20
18
|
case "SelectStatement":
|
|
21
19
|
return this.visitSelectStatement(e);
|
|
22
20
|
case "TableLiteral":
|
|
@@ -171,10 +169,6 @@ export default abstract class Visitor<T = any> {
|
|
|
171
169
|
return;
|
|
172
170
|
}
|
|
173
171
|
|
|
174
|
-
visitQuotedLiteral(e: QuotedLiteral): T {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
172
|
visitExpressionAs(e: ExpressionAs): T {
|
|
179
173
|
return;
|
|
180
174
|
}
|
|
@@ -75,12 +75,12 @@ export class QueryExpander {
|
|
|
75
75
|
const { relation } = mp;
|
|
76
76
|
const { relatedTypeClass: propertyType } = relation;
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
const query = this.context.filteredQuery(propertyType, "include", false, model, p.value);
|
|
79
79
|
// if (this.filter) {
|
|
80
|
-
const events = this.context.eventsFor(propertyType, false);
|
|
81
|
-
if (events) {
|
|
82
|
-
|
|
83
|
-
}
|
|
80
|
+
// const events = this.context.eventsFor(propertyType, false);
|
|
81
|
+
// if (events) {
|
|
82
|
+
// query = events.includeFilter(query, model, p.value) ?? query;
|
|
83
|
+
// }
|
|
84
84
|
// }
|
|
85
85
|
const select = { ... (query as EntityQuery).selectStatement };
|
|
86
86
|
|
|
@@ -95,11 +95,11 @@ export class QueryExpander {
|
|
|
95
95
|
joinWhere = Expression.equal(
|
|
96
96
|
Expression.member(
|
|
97
97
|
parent.sourceParameter,
|
|
98
|
-
Expression.
|
|
98
|
+
Expression.identifier(fk.columnName)
|
|
99
99
|
),
|
|
100
100
|
Expression.member(
|
|
101
101
|
select.sourceParameter,
|
|
102
|
-
Expression.
|
|
102
|
+
Expression.identifier(model.keys[0].columnName)
|
|
103
103
|
)
|
|
104
104
|
);
|
|
105
105
|
// load parent..
|
|
@@ -121,11 +121,11 @@ export class QueryExpander {
|
|
|
121
121
|
joinWhere = Expression.equal(
|
|
122
122
|
Expression.member(
|
|
123
123
|
parent.sourceParameter,
|
|
124
|
-
Expression.
|
|
124
|
+
Expression.identifier(fk.columnName)
|
|
125
125
|
),
|
|
126
126
|
Expression.member(
|
|
127
127
|
select.sourceParameter,
|
|
128
|
-
Expression.
|
|
128
|
+
Expression.identifier(relation.relatedEntity.keys[0].columnName)
|
|
129
129
|
)
|
|
130
130
|
);
|
|
131
131
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseExpression } from "@babel/parser";
|
|
2
|
-
import { ArrowFunctionExpression, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, Expression, ExpressionAs, Identifier, MemberExpression, NewObjectExpression, NullExpression, NumberLiteral, ParameterExpression,
|
|
2
|
+
import { ArrowFunctionExpression, BinaryExpression, BooleanLiteral, CallExpression, CoalesceExpression, ConditionalExpression, Constant, Expression, ExpressionAs, Identifier, MemberExpression, NewObjectExpression, NullExpression, NumberLiteral, ParameterExpression, StringLiteral, TemplateLiteral } from "../ast/Expressions.js";
|
|
3
3
|
import { BabelVisitor } from "./BabelVisitor.js";
|
|
4
4
|
import * as bpe from "@babel/types";
|
|
5
5
|
import Restructure from "./Restructure.js";
|
|
@@ -231,7 +231,7 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
231
231
|
switch(iterator.key.type) {
|
|
232
232
|
case "Identifier":
|
|
233
233
|
properties.push( ExpressionAs.create({
|
|
234
|
-
alias:
|
|
234
|
+
alias: Expression.identifier(iterator.key.name),
|
|
235
235
|
expression: this.visit(iterator.value)
|
|
236
236
|
}) );
|
|
237
237
|
break;
|
|
@@ -65,7 +65,6 @@ export default async function (this: TestConfig) {
|
|
|
65
65
|
scope.add(WorkflowClock, mockClock);
|
|
66
66
|
scope.add(BaseDriver, this.driver);
|
|
67
67
|
const storage = new EternityStorage(this.driver, mockClock);
|
|
68
|
-
await storage.seed();
|
|
69
68
|
scope.add(Mailer, mailer);
|
|
70
69
|
scope.add(EternityStorage, storage);
|
|
71
70
|
|
|
@@ -75,6 +74,8 @@ export default async function (this: TestConfig) {
|
|
|
75
74
|
// this is an important step
|
|
76
75
|
c.register(SendWorkflow);
|
|
77
76
|
|
|
77
|
+
await storage.seed();
|
|
78
|
+
|
|
78
79
|
const id = await c.queue(SendWorkflow, "a");
|
|
79
80
|
|
|
80
81
|
mockClock.add(TimeSpan.fromSeconds(15));
|
|
@@ -5,64 +5,64 @@ import { assertSqlMatch, trimInternal } from "../trimInternal.js";
|
|
|
5
5
|
import PostgreSqlDriver from "../../../drivers/postgres/PostgreSqlDriver.js";
|
|
6
6
|
|
|
7
7
|
const sql1 = `SELECT
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
FROM
|
|
8
|
+
p1.product_id,
|
|
9
|
+
p1.name,
|
|
10
|
+
p1.owner_id,
|
|
11
|
+
p1.status
|
|
12
|
+
FROM Products AS p1
|
|
13
13
|
WHERE EXISTS (SELECT
|
|
14
14
|
1
|
|
15
|
-
FROM
|
|
16
|
-
WHERE (
|
|
15
|
+
FROM OrderItems AS o
|
|
16
|
+
WHERE (p1.product_id = o.product_id) AND (o.product_id = $1))`;
|
|
17
17
|
|
|
18
18
|
const sql2 = `SELECT
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
FROM
|
|
19
|
+
p1.product_id,
|
|
20
|
+
p1.name,
|
|
21
|
+
p1.owner_id,
|
|
22
|
+
p1.status
|
|
23
|
+
FROM Products AS p1
|
|
24
24
|
WHERE EXISTS (SELECT
|
|
25
25
|
1
|
|
26
|
-
FROM
|
|
27
|
-
WHERE (
|
|
26
|
+
FROM OrderItems AS o
|
|
27
|
+
WHERE (p1.product_id = o.product_id) AND (o.product_id = $1)) AND EXISTS (SELECT
|
|
28
28
|
1
|
|
29
|
-
FROM
|
|
30
|
-
WHERE (
|
|
29
|
+
FROM OrderItems AS o1
|
|
30
|
+
WHERE (p1.product_id = o1.product_id) AND (o1.amount > $2))`;
|
|
31
31
|
|
|
32
32
|
const sql3 = `SELECT
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
FROM
|
|
33
|
+
p1.product_id,
|
|
34
|
+
p1.name,
|
|
35
|
+
p1.owner_id,
|
|
36
|
+
p1.status
|
|
37
|
+
FROM Products AS p1
|
|
38
38
|
WHERE EXISTS (SELECT
|
|
39
39
|
1
|
|
40
|
-
FROM
|
|
41
|
-
WHERE (
|
|
40
|
+
FROM OrderItems AS o
|
|
41
|
+
WHERE (p1.product_id = o.product_id) AND (o.product_id = $1)) AND EXISTS (SELECT
|
|
42
42
|
1
|
|
43
|
-
FROM
|
|
44
|
-
INNER JOIN
|
|
45
|
-
WHERE (
|
|
43
|
+
FROM OrderItems AS o1
|
|
44
|
+
INNER JOIN Orders AS o2 ON o1.order_id = o2.order_id
|
|
45
|
+
WHERE (p1.product_id = o1.product_id) AND (o2.order_date > $2))`;
|
|
46
46
|
|
|
47
47
|
const productJoin = `SELECT
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
FROM
|
|
53
|
-
LEFT JOIN
|
|
54
|
-
WHERE
|
|
48
|
+
p1.product_id,
|
|
49
|
+
p1.name,
|
|
50
|
+
p1.owner_id,
|
|
51
|
+
p1.status
|
|
52
|
+
FROM Products AS p1
|
|
53
|
+
LEFT JOIN Users AS u ON p1.owner_id = u.user_id
|
|
54
|
+
WHERE u.date_created > $1`;
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
const join2 = `SELECT
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
FROM
|
|
64
|
-
INNER JOIN
|
|
65
|
-
WHERE (
|
|
58
|
+
o1.order_item_id,
|
|
59
|
+
o1.order_id,
|
|
60
|
+
o1.product_id,
|
|
61
|
+
o1.price_id,
|
|
62
|
+
o1.amount
|
|
63
|
+
FROM OrderItems AS o1
|
|
64
|
+
INNER JOIN Products AS p ON o1.product_id = p.product_id
|
|
65
|
+
WHERE (o1.product_id = $1) OR (p.owner_id = $2)`;
|
|
66
66
|
|
|
67
67
|
export default function() {
|
|
68
68
|
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import QueryCompiler from "../../../compiler/QueryCompiler.js";
|
|
3
|
-
import ArrowToExpression from "../../../query/parser/ArrowToExpression.js";
|
|
4
|
-
import { ExpressionAs, Identifier, MemberExpression, NewObjectExpression, QuotedLiteral } from "../../../query/ast/Expressions.js";
|
|
5
|
-
import ExpressionToSql from "../../../query/ast/ExpressionToSql.js";
|
|
6
3
|
|
|
7
4
|
type ICustomer = { firstName: string; lastName: string; emailAddress: string; birthDate: Date };
|
|
8
5
|
|
|
@@ -15,10 +12,10 @@ export default function() {
|
|
|
15
12
|
|
|
16
13
|
let r = compiler.execute({ name }, (p) => ({ firstName, lastName, emailAddress }: ICustomer) => ({ emailAddress, name: `${firstName} ${lastName}` }));
|
|
17
14
|
|
|
18
|
-
assert.strictEqual(`FROM (
|
|
15
|
+
assert.strictEqual(`FROM (x1.emailAddress AS emailAddress,CONCAT(x1.firstName,' ',x1.lastName) AS name)`, r.text);
|
|
19
16
|
|
|
20
17
|
r = compiler.execute({ name }, (p) => ({ id }) => ({ error: `${id > 0 ? "Error" : ""}` }));
|
|
21
18
|
|
|
22
|
-
assert.strictEqual(`FROM (CONCAT((CASE WHEN
|
|
19
|
+
assert.strictEqual(`FROM (CONCAT((CASE WHEN x1.id > 0 THEN 'Error' ELSE '' END)) AS error)`, r.text);
|
|
23
20
|
|
|
24
21
|
}
|
|
@@ -10,37 +10,37 @@ export default function () {
|
|
|
10
10
|
|
|
11
11
|
let r = compiler.execute({ name }, (p) => (x) => x.firstName === p.name);
|
|
12
12
|
|
|
13
|
-
assert.equal(`
|
|
13
|
+
assert.equal(`x.firstName = $1`, r.text);
|
|
14
14
|
|
|
15
15
|
r = compiler.execute({ name }, (p) => (x) => x.firstName === p.name && x.lastName !== p.name);
|
|
16
16
|
|
|
17
|
-
assert.equal(`(
|
|
17
|
+
assert.equal(`(x.firstName = $1) AND (x.lastName <> $2)`, r.text);
|
|
18
18
|
|
|
19
19
|
r = compiler.execute({ name }, (p) => (x) => (x.firstName === p.name || x.middleName === p.name) && x.lastName !== p.name);
|
|
20
20
|
|
|
21
|
-
assert.equal(`((
|
|
21
|
+
assert.equal(`((x.firstName = $1) OR (x.middleName = $2)) AND (x.lastName <> $3)`, r.text);
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
const sqlServerCompiler = new QueryCompiler({
|
|
24
|
+
const sqlServerCompiler = new QueryCompiler({});
|
|
25
25
|
r = sqlServerCompiler.execute({ name }, (p) => (x) => x.firstName === p.name && x.lastName !== p.name);
|
|
26
26
|
|
|
27
|
-
assert.equal(`(
|
|
27
|
+
assert.equal(`(x.firstName = $1) AND (x.lastName <> $2)`, r.text);
|
|
28
28
|
|
|
29
29
|
r = compiler.execute({ name }, (p) => (x) => ( x.firstName ?? x.lastName ) === p.name);
|
|
30
30
|
|
|
31
|
-
assert.equal(`COALESCE(
|
|
31
|
+
assert.equal(`COALESCE(x.firstName, x.lastName) = $1`, r.text);
|
|
32
32
|
|
|
33
33
|
r = compiler.execute({ name }, (p) => (x) => Sql.text.like(x.firstName, p.name));
|
|
34
34
|
|
|
35
|
-
assert.equal(`(
|
|
35
|
+
assert.equal(`(x.firstName LIKE $1)`, r.text);
|
|
36
36
|
|
|
37
37
|
r = compiler.execute({ days: 1 }, (p) => (x) => Sql.date.addDays(x.birthDate, p.days));
|
|
38
38
|
|
|
39
|
-
assert.equal(`(
|
|
39
|
+
assert.equal(`(x.birthDate + ($1 * interval '1 day'))`, r.text);
|
|
40
40
|
|
|
41
41
|
r = compiler.execute({name}, (p) => (x) => Sql.text.startsWith(x.firstName, p.name));
|
|
42
42
|
|
|
43
|
-
assert.equal(`starts_with(
|
|
43
|
+
assert.equal(`starts_with(x.firstName, $1)`, r.text);
|
|
44
44
|
assert.equal("Akash", r.values[0]);
|
|
45
45
|
|
|
46
46
|
const code = "1235";
|
|
@@ -49,7 +49,7 @@ export default function () {
|
|
|
49
49
|
(p) => (x: KeyCode) =>
|
|
50
50
|
x.code === Sql.cast.asNumber(p.code) && x.key === Sql.cast.asText(p.key) );
|
|
51
51
|
|
|
52
|
-
assert.equal(`(
|
|
52
|
+
assert.equal(`(x.code = ($1 ::double)) AND (x.key = ($2 ::text))`, r.text);
|
|
53
53
|
|
|
54
54
|
}
|
|
55
55
|
|