@entity-access/entity-access 1.0.349 → 1.0.351

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.
Files changed (36) hide show
  1. package/dist/model/EntityQuery.d.ts.map +1 -1
  2. package/dist/model/EntityQuery.js +15 -13
  3. package/dist/model/EntityQuery.js.map +1 -1
  4. package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
  5. package/dist/query/ast/ExpressionToSql.js +18 -7
  6. package/dist/query/ast/ExpressionToSql.js.map +1 -1
  7. package/dist/query/ast/Expressions.d.ts +3 -0
  8. package/dist/query/ast/Expressions.d.ts.map +1 -1
  9. package/dist/query/ast/Expressions.js.map +1 -1
  10. package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
  11. package/dist/query/parser/ArrowToExpression.js +4 -1
  12. package/dist/query/parser/ArrowToExpression.js.map +1 -1
  13. package/dist/tests/db-tests/tests/insert-into.d.ts +3 -0
  14. package/dist/tests/db-tests/tests/insert-into.d.ts.map +1 -0
  15. package/dist/tests/db-tests/tests/insert-into.js +17 -0
  16. package/dist/tests/db-tests/tests/insert-into.js.map +1 -0
  17. package/dist/tests/db-tests/tests/select-parent.d.ts +3 -0
  18. package/dist/tests/db-tests/tests/select-parent.d.ts.map +1 -0
  19. package/dist/tests/db-tests/tests/select-parent.js +17 -0
  20. package/dist/tests/db-tests/tests/select-parent.js.map +1 -0
  21. package/dist/tests/model/ShoppingContext.d.ts +14 -0
  22. package/dist/tests/model/ShoppingContext.d.ts.map +1 -1
  23. package/dist/tests/model/ShoppingContext.js +46 -0
  24. package/dist/tests/model/ShoppingContext.js.map +1 -1
  25. package/dist/tests/model/createContext.js +7 -1
  26. package/dist/tests/model/createContext.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/src/model/EntityQuery.ts +16 -14
  30. package/src/query/ast/ExpressionToSql.ts +21 -7
  31. package/src/query/ast/Expressions.ts +3 -0
  32. package/src/query/parser/ArrowToExpression.ts +5 -1
  33. package/src/tests/db-tests/tests/insert-into.ts +24 -0
  34. package/src/tests/db-tests/tests/select-parent.ts +25 -0
  35. package/src/tests/model/ShoppingContext.ts +36 -0
  36. package/src/tests/model/createContext.ts +8 -1
@@ -268,9 +268,12 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
268
268
 
269
269
  const method = name[2];
270
270
 
271
+ const castMethod = name[1] === "cast" ? name[2] : void 0;
272
+
271
273
  const reWrittenCe = CallExpression.create({
272
274
  callee: Expression.identifier(name.join(".")),
273
- arguments: ce.arguments
275
+ arguments: ce.arguments,
276
+ castMethod
274
277
  });
275
278
 
276
279
 
@@ -290,6 +293,7 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
290
293
  }
291
294
 
292
295
  const left = CallExpression.create({
296
+ collectionMethod: method,
293
297
  callee: MemberExpression.create({
294
298
  target: mapCallee.target,
295
299
  property: Expression.identifier(method),
@@ -0,0 +1,24 @@
1
+ import assert from "assert";
2
+ import { TestConfig } from "../../TestConfig.js";
3
+ import { createContext } 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
+ await context.messages.asQuery()
15
+ .where(void 0, (p) => (x) => x.messageID > 100)
16
+ .select(void 0, (p) => (x) => ({
17
+ fromID: x.fromID,
18
+ toID: x.toID,
19
+ message: x.message
20
+ }))
21
+ .trace(console.log)
22
+ .insertInTo(context.archivedMessages);
23
+
24
+ }
@@ -0,0 +1,25 @@
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
+ const cats = await context.categories.where({ search: "headphones%"}, (p) => (x) => Sql.text.like(x.parent.lowerName, p.search)
15
+ || Sql.text.like(x.parent.parent.lowerName, p.search) )
16
+ .trace(console.log)
17
+ .toArray();
18
+
19
+ // assert.equal("Bluetooth", cat1.name);
20
+ assert.equal(2, cats.length);
21
+
22
+ // select nested with filter
23
+
24
+
25
+ }
@@ -38,6 +38,10 @@ export class ShoppingContext extends EntityContext {
38
38
  public emailAddresses = this.model.register(EmailAddress);
39
39
 
40
40
  public userCategoryTags = this.model.register(UserCategoryTag);
41
+
42
+ public messages = this.model.register(UserMessage);
43
+
44
+ public archivedMessages = this.model.register(ArchivedUserMessage);
41
45
  }
42
46
 
43
47
  @Table("Users")
@@ -392,4 +396,36 @@ export class OrderItem {
392
396
  public product: Product;
393
397
  public productPrice: ProductPrice;
394
398
 
399
+ }
400
+
401
+ @Table("UserMessages")
402
+ export class UserMessage {
403
+
404
+ @Column({ dataType: "BigInt", key: true, generated: "identity"})
405
+ messageID: number;
406
+
407
+ @Column({ dataType: "BigInt"})
408
+ fromID: number;
409
+
410
+ @Column({ dataType: "BigInt"})
411
+ toID: number;
412
+
413
+ @Column({ dataType: "Char"})
414
+ message: string;
415
+ }
416
+
417
+ @Table("ArchivedUserMessages")
418
+ export class ArchivedUserMessage {
419
+
420
+ @Column({ dataType: "BigInt", key: true, generated: "identity"})
421
+ messageID: number;
422
+
423
+ @Column({ dataType: "BigInt"})
424
+ fromID: number;
425
+
426
+ @Column({ dataType: "BigInt"})
427
+ toID: number;
428
+
429
+ @Column({ dataType: "Char"})
430
+ message: string;
395
431
  }
@@ -241,11 +241,18 @@ function addHeadPhones(context: ShoppingContext, now: Date, owner: User) {
241
241
  children: [
242
242
  context.categories.add({
243
243
  name: "Bluetooth",
244
- categoryID: `${headPhoneCategory}/blue-tooth`
244
+ categoryID: `${headPhoneCategory}/blue-tooth`,
245
+ children: [
246
+ context.categories.add({
247
+ name: "BT 200",
248
+ categoryID: `${headPhoneCategory}/blue-tooth/bt-200`,
249
+ })
250
+ ]
245
251
  })
246
252
  ]
247
253
  });
248
254
 
255
+
249
256
  const startDate = new Date();
250
257
  const active = true;
251
258