@entity-access/entity-access 1.0.301 → 1.0.302
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/postgres/PostgreSqlMethodTransformer.js +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +62 -14
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.js +6 -0
- package/dist/query/parser/ArrowToExpression.js.map +1 -1
- package/dist/tests/db-tests/tests/select-items-sum.d.ts +3 -0
- package/dist/tests/db-tests/tests/select-items-sum.d.ts.map +1 -0
- package/dist/tests/db-tests/tests/select-items-sum.js +30 -0
- package/dist/tests/db-tests/tests/select-items-sum.js.map +1 -0
- package/dist/tests/model/ShoppingContext.d.ts +1 -0
- package/dist/tests/model/ShoppingContext.d.ts.map +1 -1
- package/dist/tests/model/ShoppingContext.js +4 -0
- package/dist/tests/model/ShoppingContext.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +1 -1
- package/src/query/ast/ExpressionToSql.ts +73 -16
- package/src/query/parser/ArrowToExpression.ts +7 -0
- package/src/tests/db-tests/tests/select-items-sum.ts +38 -0
- package/src/tests/model/ShoppingContext.ts +3 -0
|
@@ -215,6 +215,8 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
215
215
|
// we need to sanitize callee
|
|
216
216
|
this.sanitize(callee);
|
|
217
217
|
|
|
218
|
+
// change Sql.coll. with arrow functions to move it inside
|
|
219
|
+
|
|
218
220
|
return CallExpression.create({
|
|
219
221
|
callee: callee ? this.visit(callee) : void 0,
|
|
220
222
|
arguments: args ? args.map((x) => this.visit(x)) : []
|
|
@@ -302,6 +304,11 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
|
|
|
302
304
|
throw new Error(`Unknown identifier ${name}`);
|
|
303
305
|
}
|
|
304
306
|
return;
|
|
307
|
+
case "CallExpression":
|
|
308
|
+
for (const iterator of node.arguments) {
|
|
309
|
+
this.visit(iterator as bpe.Expression);
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
305
312
|
case "MemberExpression":
|
|
306
313
|
case "OptionalMemberExpression":
|
|
307
314
|
return this.sanitize(node.object);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { TestConfig } from "../../TestConfig.js";
|
|
3
|
+
import { createContext, headPhoneCategory } from "../../model/createContext.js";
|
|
4
|
+
import Sql from "../../../sql/Sql.js";
|
|
5
|
+
|
|
6
|
+
export default async function(this: TestConfig) {
|
|
7
|
+
|
|
8
|
+
if (!this.db) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const context = await createContext(this.driver);
|
|
13
|
+
|
|
14
|
+
let report;
|
|
15
|
+
// report = await context.users.all()
|
|
16
|
+
// .where({}, (p) => (x) => x.orders.some((oi) => oi.customerID > 0))
|
|
17
|
+
// .map({}, (p) => (x) => ({
|
|
18
|
+
// total: Sql.coll.sum(x.orders.map((o) => Sql.coll.sum(o.orderItems.map((oi) => oi.amount))))
|
|
19
|
+
// })
|
|
20
|
+
// )
|
|
21
|
+
// .trace(console.log)
|
|
22
|
+
// .first();
|
|
23
|
+
|
|
24
|
+
// assert.notEqual(null, report);
|
|
25
|
+
|
|
26
|
+
report = await context.users.all()
|
|
27
|
+
.where({}, (p) => (x) => x.orders.some((oi) => oi.customerID > 0))
|
|
28
|
+
.map({}, (p) => (x) => ({
|
|
29
|
+
total: Sql.coll.sum(x.orders
|
|
30
|
+
.filter((o) => o.status === "pending")
|
|
31
|
+
.map((o) => Sql.coll.sum(o.orderItems.map((oi) => oi.amount))))
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
.trace(console.log)
|
|
35
|
+
.first();
|
|
36
|
+
|
|
37
|
+
assert.notEqual(null, report);
|
|
38
|
+
}
|
|
@@ -342,6 +342,9 @@ export class Order {
|
|
|
342
342
|
@Column({ dataType: "Char", length: 200, nullable: true})
|
|
343
343
|
public purchaseOrder: string;
|
|
344
344
|
|
|
345
|
+
@Column({ dataType: "Char", length: 20, default: () => "pending"})
|
|
346
|
+
public status: string;
|
|
347
|
+
|
|
345
348
|
public orderItems: OrderItem[];
|
|
346
349
|
|
|
347
350
|
public customer: User;
|