@entity-access/entity-access 1.0.55 → 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.
Files changed (127) hide show
  1. package/dist/compiler/NamingConventions.d.ts +7 -0
  2. package/dist/compiler/NamingConventions.d.ts.map +1 -0
  3. package/dist/compiler/NamingConventions.js +7 -0
  4. package/dist/compiler/NamingConventions.js.map +1 -0
  5. package/dist/compiler/QueryCompiler.d.ts +2 -2
  6. package/dist/compiler/QueryCompiler.d.ts.map +1 -1
  7. package/dist/compiler/QueryCompiler.js +8 -3
  8. package/dist/compiler/QueryCompiler.js.map +1 -1
  9. package/dist/decorators/Column.d.ts.map +1 -1
  10. package/dist/decorators/Column.js +3 -0
  11. package/dist/decorators/Column.js.map +1 -1
  12. package/dist/decorators/IColumn.d.ts +5 -0
  13. package/dist/decorators/IColumn.d.ts.map +1 -1
  14. package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
  15. package/dist/drivers/base/BaseDriver.js +7 -7
  16. package/dist/drivers/base/BaseDriver.js.map +1 -1
  17. package/dist/drivers/postgres/PostgreSqlDriver.js +1 -1
  18. package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
  19. package/dist/drivers/sql-server/ExpressionToSqlServer.d.ts.map +1 -1
  20. package/dist/drivers/sql-server/ExpressionToSqlServer.js +2 -2
  21. package/dist/drivers/sql-server/ExpressionToSqlServer.js.map +1 -1
  22. package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts +1 -1
  23. package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts.map +1 -1
  24. package/dist/drivers/sql-server/SqlServerQueryCompiler.js +6 -2
  25. package/dist/drivers/sql-server/SqlServerQueryCompiler.js.map +1 -1
  26. package/dist/entity-query/EntityType.d.ts +7 -5
  27. package/dist/entity-query/EntityType.d.ts.map +1 -1
  28. package/dist/entity-query/EntityType.js +31 -14
  29. package/dist/entity-query/EntityType.js.map +1 -1
  30. package/dist/eternity/EternityStorage.d.ts +1 -1
  31. package/dist/eternity/EternityStorage.d.ts.map +1 -1
  32. package/dist/eternity/EternityStorage.js +4 -4
  33. package/dist/eternity/EternityStorage.js.map +1 -1
  34. package/dist/migrations/Migrations.d.ts.map +1 -1
  35. package/dist/migrations/Migrations.js +5 -4
  36. package/dist/migrations/Migrations.js.map +1 -1
  37. package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
  38. package/dist/migrations/postgres/PostgresAutomaticMigrations.js +17 -14
  39. package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
  40. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +12 -12
  41. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
  42. package/dist/model/EntityContext.js.map +1 -1
  43. package/dist/model/EntityModel.d.ts +4 -1
  44. package/dist/model/EntityModel.d.ts.map +1 -1
  45. package/dist/model/EntityModel.js +36 -5
  46. package/dist/model/EntityModel.js.map +1 -1
  47. package/dist/model/EntityQuery.d.ts.map +1 -1
  48. package/dist/model/EntityQuery.js +7 -7
  49. package/dist/model/EntityQuery.js.map +1 -1
  50. package/dist/model/SourceExpression.d.ts.map +1 -1
  51. package/dist/model/SourceExpression.js +3 -4
  52. package/dist/model/SourceExpression.js.map +1 -1
  53. package/dist/model/changes/ChangeEntry.js +2 -2
  54. package/dist/model/changes/ChangeEntry.js.map +1 -1
  55. package/dist/model/changes/ChangeSet.js +1 -2
  56. package/dist/model/changes/ChangeSet.js.map +1 -1
  57. package/dist/model/verification/VerificationSession.d.ts.map +1 -1
  58. package/dist/model/verification/VerificationSession.js +6 -6
  59. package/dist/model/verification/VerificationSession.js.map +1 -1
  60. package/dist/query/ast/DebugStringVisitor.d.ts +1 -2
  61. package/dist/query/ast/DebugStringVisitor.d.ts.map +1 -1
  62. package/dist/query/ast/DebugStringVisitor.js +0 -3
  63. package/dist/query/ast/DebugStringVisitor.js.map +1 -1
  64. package/dist/query/ast/ExpressionToSql.d.ts +1 -2
  65. package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
  66. package/dist/query/ast/ExpressionToSql.js +16 -14
  67. package/dist/query/ast/ExpressionToSql.js.map +1 -1
  68. package/dist/query/ast/Expressions.d.ts +15 -20
  69. package/dist/query/ast/Expressions.d.ts.map +1 -1
  70. package/dist/query/ast/Expressions.js +17 -19
  71. package/dist/query/ast/Expressions.js.map +1 -1
  72. package/dist/query/ast/IStringTransformer.d.ts +2 -3
  73. package/dist/query/ast/IStringTransformer.d.ts.map +1 -1
  74. package/dist/query/ast/IStringTransformer.js +4 -6
  75. package/dist/query/ast/IStringTransformer.js.map +1 -1
  76. package/dist/query/ast/Visitor.d.ts +1 -2
  77. package/dist/query/ast/Visitor.d.ts.map +1 -1
  78. package/dist/query/ast/Visitor.js +0 -5
  79. package/dist/query/ast/Visitor.js.map +1 -1
  80. package/dist/query/expander/QueryExpander.js +2 -2
  81. package/dist/query/expander/QueryExpander.js.map +1 -1
  82. package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
  83. package/dist/query/parser/ArrowToExpression.js +2 -2
  84. package/dist/query/parser/ArrowToExpression.js.map +1 -1
  85. package/dist/tests/eternity/eternity-tests.d.ts.map +1 -1
  86. package/dist/tests/eternity/eternity-tests.js +1 -1
  87. package/dist/tests/eternity/eternity-tests.js.map +1 -1
  88. package/dist/tests/expressions/left-joins/child-joins.js +41 -41
  89. package/dist/tests/expressions/left-joins/child-joins.js.map +1 -1
  90. package/dist/tests/expressions/select/select.d.ts.map +1 -1
  91. package/dist/tests/expressions/select/select.js +2 -2
  92. package/dist/tests/expressions/select/select.js.map +1 -1
  93. package/dist/tests/expressions/simple/parse-arrow.js +10 -10
  94. package/dist/tests/expressions/simple/parse-arrow.js.map +1 -1
  95. package/dist/tsconfig.tsbuildinfo +1 -1
  96. package/package.json +1 -1
  97. package/src/compiler/NamingConventions.ts +6 -0
  98. package/src/compiler/QueryCompiler.ts +7 -5
  99. package/src/decorators/Column.ts +3 -0
  100. package/src/decorators/IColumn.ts +7 -0
  101. package/src/drivers/base/BaseDriver.ts +9 -9
  102. package/src/drivers/postgres/PostgreSqlDriver.ts +1 -1
  103. package/src/drivers/sql-server/ExpressionToSqlServer.ts +2 -2
  104. package/src/drivers/sql-server/SqlServerQueryCompiler.ts +5 -2
  105. package/src/entity-query/EntityType.ts +34 -13
  106. package/src/eternity/EternityStorage.ts +3 -3
  107. package/src/migrations/Migrations.ts +5 -3
  108. package/src/migrations/postgres/PostgresAutomaticMigrations.ts +17 -14
  109. package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +12 -12
  110. package/src/model/EntityContext.ts +1 -1
  111. package/src/model/EntityModel.ts +41 -7
  112. package/src/model/EntityQuery.ts +7 -7
  113. package/src/model/SourceExpression.ts +3 -4
  114. package/src/model/changes/ChangeEntry.ts +2 -2
  115. package/src/model/changes/ChangeSet.ts +1 -1
  116. package/src/model/verification/VerificationSession.ts +6 -7
  117. package/src/query/ast/DebugStringVisitor.ts +1 -5
  118. package/src/query/ast/ExpressionToSql.ts +18 -15
  119. package/src/query/ast/Expressions.ts +33 -34
  120. package/src/query/ast/IStringTransformer.ts +4 -4
  121. package/src/query/ast/Visitor.ts +1 -7
  122. package/src/query/expander/QueryExpander.ts +4 -4
  123. package/src/query/parser/ArrowToExpression.ts +2 -2
  124. package/src/tests/eternity/eternity-tests.ts +2 -1
  125. package/src/tests/expressions/left-joins/child-joins.ts +41 -41
  126. package/src/tests/expressions/select/select.ts +2 -5
  127. package/src/tests/expressions/simple/parse-arrow.ts +10 -10
@@ -29,9 +29,9 @@ export abstract class Expression {
29
29
  return ArrayExpression.create({ elements });
30
30
  }
31
31
 
32
- static as(expression: Expression, alias: QuotedLiteral | string) {
32
+ static as(expression: Expression, alias: Identifier | string) {
33
33
  if (typeof alias === "string") {
34
- alias = Expression.quotedLiteral(alias);
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: QuotedLiteral;
159
- fields: QuotedLiteral[];
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 | QuotedLiteral | ExpressionAs | TableLiteral;
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 | QuotedLiteral | ExpressionAs)[];
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 | QuotedLiteral | ExpressionAs | TableLiteral;
265
- as: QuotedLiteral | ParameterExpression;
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: QuotedLiteral[];
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
- static propertyChain(... properties: string[]): Expression {
329
- const literal = properties.pop();
330
- const property = QuotedLiteral.create({ literal });
331
- if (properties.length === 0) {
332
- return property;
333
- }
334
- return MemberExpression.create({
335
- target: QuotedLiteral.propertyChain(... properties),
336
- property
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
- readonly type = "QuotedLiteral";
341
- public literal: string;
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: QuotedLiteral;
346
+ alias: Identifier;
348
347
  }
349
348
 
350
349
  export class TableLiteral extends Expression {
351
350
  readonly type = "TableLiteral";
352
- schema: QuotedLiteral;
353
- name: QuotedLiteral;
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 | QuotedLiteral;
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 | QuotedLiteral;
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, quotedLiteral: (n: string) => string ) {
13
- return new QueryParameter(name, quotedLiteral);
12
+ static create(name: () => string) {
13
+ return new QueryParameter(name);
14
14
  }
15
15
 
16
- constructor(public name: () => string, public quotedLiteral: (n: string) => string) {}
16
+ constructor(public name: () => string) {}
17
17
 
18
18
  toString() {
19
- return this.quotedLiteral(this.name());
19
+ return this.name();
20
20
  }
21
21
  }
22
22
 
@@ -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, QuotedLiteral, ReturnUpdated, SelectStatement, StringLiteral, TableLiteral, TemplateElement, TemplateLiteral, UnionAllStatement, UpdateStatement, ValuesStatement } from "./Expressions.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, 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
  }
@@ -95,11 +95,11 @@ export class QueryExpander {
95
95
  joinWhere = Expression.equal(
96
96
  Expression.member(
97
97
  parent.sourceParameter,
98
- Expression.quotedLiteral(fk.columnName)
98
+ Expression.identifier(fk.columnName)
99
99
  ),
100
100
  Expression.member(
101
101
  select.sourceParameter,
102
- Expression.quotedLiteral(model.keys[0].columnName)
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.quotedLiteral(fk.columnName)
124
+ Expression.identifier(fk.columnName)
125
125
  ),
126
126
  Expression.member(
127
127
  select.sourceParameter,
128
- Expression.quotedLiteral(relation.relatedEntity.keys[0].columnName)
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, QuotedLiteral, StringLiteral, TemplateLiteral } from "../ast/Expressions.js";
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: QuotedLiteral.create({ literal: iterator.key.name}),
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
- "p1"."productID",
9
- "p1"."name",
10
- "p1"."ownerID",
11
- "p1"."status"
12
- FROM "Products" AS "p1"
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 "OrderItems" AS "o"
16
- WHERE ("p1"."productID" = "o"."productID") AND ("o"."productID" = $1))`;
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
- "p1"."productID",
20
- "p1"."name",
21
- "p1"."ownerID",
22
- "p1"."status"
23
- FROM "Products" AS "p1"
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 "OrderItems" AS "o"
27
- WHERE ("p1"."productID" = "o"."productID") AND ("o"."productID" = $1)) AND EXISTS (SELECT
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 "OrderItems" AS "o1"
30
- WHERE ("p1"."productID" = "o1"."productID") AND ("o1"."amount" > $2))`;
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
- "p1"."productID",
34
- "p1"."name",
35
- "p1"."ownerID",
36
- "p1"."status"
37
- FROM "Products" AS "p1"
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 "OrderItems" AS "o"
41
- WHERE ("p1"."productID" = "o"."productID") AND ("o"."productID" = $1)) AND EXISTS (SELECT
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 "OrderItems" AS "o1"
44
- INNER JOIN "Orders" AS "o2" ON "o1"."orderID" = "o2"."orderID"
45
- WHERE ("p1"."productID" = "o1"."productID") AND ("o2"."orderDate" > $2))`;
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
- "p1"."productID",
49
- "p1"."name",
50
- "p1"."ownerID",
51
- "p1"."status"
52
- FROM "Products" AS "p1"
53
- LEFT JOIN "Users" AS "u" ON "p1"."ownerID" = "u"."userID"
54
- WHERE "u"."dateCreated" > $1`;
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
- "o1"."orderItemID",
59
- "o1"."orderID",
60
- "o1"."productID",
61
- "o1"."priceID",
62
- "o1"."amount"
63
- FROM "OrderItems" AS "o1"
64
- INNER JOIN "Products" AS "p" ON "o1"."productID" = "p"."productID"
65
- WHERE ("o1"."productID" = $1) OR ("p"."ownerID" = $2)`;
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 ("x1"."emailAddress" AS "emailAddress",CONCAT("x1"."firstName",$1,"x1"."lastName") AS "name")`, r.text);
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 "x1"."id" > $1 THEN $2 ELSE $3 END)) AS "error")`, r.text);
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(`"x"."firstName" = $1`, r.text);
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(`("x"."firstName" = $1) AND ("x"."lastName" <> $2)`, r.text);
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(`(("x"."firstName" = $1) OR ("x"."middleName" = $2)) AND ("x"."lastName" <> $3)`, r.text);
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({ quotedLiteral: (x) => `[${x}]`});
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(`([x].[firstName] = $1) AND ([x].[lastName] <> $2)`, r.text);
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("x"."firstName", "x"."lastName") = $1`, r.text);
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(`("x"."firstName" LIKE $1)`, r.text);
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(`("x"."birthDate" + ($1 * interval '1 day'))`, r.text);
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("x"."firstName", $1)`, r.text);
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(`("x"."code" = ($1 ::double)) AND ("x"."key" = ($2 ::text))`, r.text);
52
+ assert.equal(`(x.code = ($1 ::double)) AND (x.key = ($2 ::text))`, r.text);
53
53
 
54
54
  }
55
55