@balena/abstract-sql-compiler 10.5.0-build-joshbwlng-date-trunc-51521852f16d12fdcd22b51d24bf6a2cea3247e3-1 → 11.0.0-build-11-x-db9cd30f6ec498e5293df9e060f5531cd960b1cc-1

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 (61) hide show
  1. package/.versionbot/CHANGELOG.yml +24 -15
  2. package/CHANGELOG.md +4 -6
  3. package/out/AbstractSQLCompiler.d.ts +7 -6
  4. package/out/AbstractSQLCompiler.js +45 -57
  5. package/out/AbstractSQLCompiler.js.map +1 -1
  6. package/out/AbstractSQLOptimiser.d.ts +1 -1
  7. package/out/AbstractSQLOptimiser.js +9 -56
  8. package/out/AbstractSQLOptimiser.js.map +1 -1
  9. package/out/AbstractSQLRules2SQL.d.ts +2 -2
  10. package/out/AbstractSQLRules2SQL.js +208 -231
  11. package/out/AbstractSQLRules2SQL.js.map +1 -1
  12. package/out/AbstractSQLSchemaOptimiser.d.ts +2 -2
  13. package/out/AbstractSQLSchemaOptimiser.js +14 -21
  14. package/out/AbstractSQLSchemaOptimiser.js.map +1 -1
  15. package/out/referenced-fields.d.ts +1 -1
  16. package/out/referenced-fields.js +17 -24
  17. package/out/referenced-fields.js.map +1 -1
  18. package/package.json +4 -4
  19. package/src/AbstractSQLCompiler.ts +23 -18
  20. package/src/AbstractSQLOptimiser.ts +7 -22
  21. package/src/AbstractSQLRules2SQL.ts +8 -13
  22. package/src/AbstractSQLSchemaOptimiser.ts +6 -5
  23. package/src/referenced-fields.ts +4 -4
  24. package/test/abstract-sql/aggregate-json.ts +1 -1
  25. package/test/abstract-sql/aggregate.ts +25 -10
  26. package/test/abstract-sql/and-or-boolean-optimisations.ts +1 -1
  27. package/test/abstract-sql/case-when-else.ts +5 -2
  28. package/test/abstract-sql/cast.ts +1 -1
  29. package/test/abstract-sql/coalesce.ts +1 -1
  30. package/test/abstract-sql/comparisons.ts +1 -1
  31. package/test/abstract-sql/dates.ts +10 -27
  32. package/test/abstract-sql/duration.ts +1 -1
  33. package/test/abstract-sql/empty-query-optimisations.ts +2 -2
  34. package/test/abstract-sql/functions_wrapper.ts +1 -1
  35. package/test/abstract-sql/get-referenced-fields.ts +1 -1
  36. package/test/abstract-sql/get-rule-referenced-fields.ts +1 -1
  37. package/test/abstract-sql/insert-query.ts +1 -1
  38. package/test/abstract-sql/is-distinct.ts +1 -1
  39. package/test/abstract-sql/joins.ts +1 -1
  40. package/test/abstract-sql/json.ts +1 -1
  41. package/test/abstract-sql/math.ts +1 -1
  42. package/test/abstract-sql/nested-in-optimisations.ts +1 -1
  43. package/test/abstract-sql/not-not-optimisations.ts +1 -1
  44. package/test/abstract-sql/schema-checks.ts +1 -1
  45. package/test/abstract-sql/schema-informative-reference.ts +1 -1
  46. package/test/abstract-sql/schema-rule-optimization.ts +1 -1
  47. package/test/abstract-sql/schema-rule-to-check.ts +1 -1
  48. package/test/abstract-sql/schema-views.ts +37 -2
  49. package/test/abstract-sql/test.ts +1 -1
  50. package/test/abstract-sql/text.ts +1 -1
  51. package/test/odata/expand.ts +3 -3
  52. package/test/odata/filterby.ts +8 -4
  53. package/test/odata/orderby.ts +2 -2
  54. package/test/odata/paging.ts +2 -2
  55. package/test/odata/resource_parsing.ts +5 -5
  56. package/test/odata/select.ts +2 -2
  57. package/test/odata/stress.ts +2 -2
  58. package/test/odata/test.ts +24 -20
  59. package/test/sbvr/pilots.ts +3 -3
  60. package/test/sbvr/reference-type.ts +3 -3
  61. package/test/sbvr/test.ts +12 -10
@@ -6,24 +6,28 @@ export const enum Engines {
6
6
  /* eslint-enable @typescript-eslint/no-shadow */
7
7
  }
8
8
 
9
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
10
- import type { Binding, SqlResult } from './AbstractSQLRules2SQL';
11
- import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL';
12
- export { Binding, SqlResult } from './AbstractSQLRules2SQL';
9
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
10
+ import type { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
11
+ import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL.js';
12
+ export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
13
13
  import type { SbvrType } from '@balena/sbvr-types';
14
- import sbvrTypes from '@balena/sbvr-types';
15
- import { optimizeSchema, generateRuleSlug } from './AbstractSQLSchemaOptimiser';
14
+ import $sbvrTypes from '@balena/sbvr-types';
15
+ const { default: sbvrTypes } = $sbvrTypes;
16
+ import {
17
+ optimizeSchema,
18
+ generateRuleSlug,
19
+ } from './AbstractSQLSchemaOptimiser.js';
16
20
  import type {
17
21
  ReferencedFields,
18
22
  RuleReferencedFields,
19
23
  ModifiedFields,
20
- } from './referenced-fields';
24
+ } from './referenced-fields.js';
21
25
  import {
22
26
  getReferencedFields,
23
27
  getRuleReferencedFields,
24
28
  getModifiedFields,
25
29
  insertAffectedIdsBinds,
26
- } from './referenced-fields';
30
+ } from './referenced-fields.js';
27
31
 
28
32
  export type { ReferencedFields, RuleReferencedFields, ModifiedFields };
29
33
 
@@ -174,9 +178,7 @@ export type NumberTypeNodes = StrictNumberTypeNodes | UnknownTypeNodes;
174
178
 
175
179
  export type FieldNode = ['Field', string];
176
180
  export type ReferencedFieldNode = ['ReferencedField', string, string];
177
- export type DateTruncNode =
178
- | ['DateTrunc', TextTypeNodes, DateTypeNodes]
179
- | ['DateTrunc', TextTypeNodes, DateTypeNodes, TextTypeNodes];
181
+ export type DateTruncNode = ['DateTrunc', TextTypeNodes, DateTypeNodes];
180
182
  export type ToDateNode = ['ToDate', DateTypeNodes];
181
183
  export type ToTimeNode = ['ToTime', DateTypeNodes];
182
184
  export type CurrentTimestampNode = ['CurrentTimestamp'];
@@ -256,6 +258,7 @@ export type UnknownTypeNodes =
256
258
  | NullNode
257
259
  | FieldNode
258
260
  | ReferencedFieldNode
261
+ | EqualsAnyNode
259
262
  | BindNode
260
263
  | CastNode
261
264
  | CaseNode
@@ -494,6 +497,7 @@ export interface AbstractSqlTable {
494
497
  primitive: false | string;
495
498
  triggers?: Trigger[];
496
499
  checks?: Check[];
500
+ viewDefinition?: Omit<Definition, 'binds'>;
497
501
  definition?: Definition;
498
502
  modifyFields?: AbstractSqlTable['fields'];
499
503
  modifyName?: AbstractSqlTable['name'];
@@ -812,18 +816,19 @@ $$;`);
812
816
  if (typeof table === 'string') {
813
817
  return;
814
818
  }
815
- const { definition } = table;
816
- if (definition != null) {
819
+ const { definition, viewDefinition } = table;
820
+ if (viewDefinition != null && definition != null) {
821
+ throw new Error('Cannot have both a definition and a viewDefinition');
822
+ }
823
+ if (definition != null || viewDefinition != null) {
817
824
  if (table.fields.some(({ computed }) => computed != null)) {
818
825
  throw new Error(
819
826
  `Using computed fields alongside a custom table definition is unsupported, found for table resourceName: '${table.resourceName}', name: '${table.name}'`,
820
827
  );
821
828
  }
822
- if (definition.binds != null && definition.binds.length > 0) {
823
- // If there are any binds then it's a dynamic definition and cannot become a view
824
- return;
825
- }
826
- let definitionAbstractSql = definition.abstractSql;
829
+ }
830
+ if (viewDefinition != null) {
831
+ let definitionAbstractSql = viewDefinition.abstractSql;
827
832
  // If there are any resource nodes then it's a dynamic definition and cannot become a view
828
833
  if (containsNode(definitionAbstractSql, isResourceNode)) {
829
834
  return;
@@ -25,6 +25,7 @@ import type {
25
25
  CrossJoinNode,
26
26
  CurrentDateNode,
27
27
  CurrentTimestampNode,
28
+ DateTruncNode,
28
29
  DeleteQueryNode,
29
30
  DivideNode,
30
31
  DurationNode,
@@ -70,7 +71,6 @@ import type {
70
71
  ReferencedFieldNode,
71
72
  ReplaceNode,
72
73
  StrictBooleanTypeNodes,
73
- StrictDateTypeNodes,
74
74
  StrictNumberTypeNodes,
75
75
  StrictTextTypeNodes,
76
76
  RightJoinNode,
@@ -104,9 +104,9 @@ import type {
104
104
  EscapeForLikeNode,
105
105
  EqualsAnyNode,
106
106
  NotInNode,
107
- } from './AbstractSQLCompiler';
108
- import { isFieldTypeNode } from './AbstractSQLCompiler';
109
- import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL';
107
+ } from './AbstractSQLCompiler.js';
108
+ import { isFieldTypeNode } from './AbstractSQLCompiler.js';
109
+ import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL.js';
110
110
 
111
111
  const {
112
112
  isAbstractSqlQuery,
@@ -217,6 +217,7 @@ const UnknownValue: MetaMatchFn<UnknownTypeNodes> = (args) => {
217
217
  case 'Null':
218
218
  case 'Field':
219
219
  case 'ReferencedField':
220
+ case 'EqualsAny':
220
221
  case 'Bind':
221
222
  case 'Cast':
222
223
  case 'Case':
@@ -297,9 +298,7 @@ const BooleanValue = MatchValue<BooleanTypeNodes>(
297
298
  isBooleanValue as typeof AbstractSQLRules2SQL.isBooleanValue,
298
299
  );
299
300
 
300
- const isDateValue = (type: unknown): type is 'Now' | StrictDateTypeNodes[0] => {
301
- return type === 'Now' || AbstractSQLRules2SQL.isDateValue(type);
302
- };
301
+ const { isDateValue } = AbstractSQLRules2SQL;
303
302
  const DateValue = MatchValue(isDateValue);
304
303
 
305
304
  const { isJSONValue } = AbstractSQLRules2SQL;
@@ -885,16 +884,7 @@ const typeRules = {
885
884
  Floor: matchArgs<FloorNode>('Floor', NumericValue),
886
885
  Ceiling: matchArgs<CeilingNode>('Ceiling', NumericValue),
887
886
  ToDate: matchArgs<ToDateNode>('ToDate', DateValue),
888
- DateTrunc: (args) => {
889
- checkMinArgs('DateTrunc', args, 2);
890
- const precision = TextValue(getAbstractSqlQuery(args, 0));
891
- const date = DateValue(getAbstractSqlQuery(args, 1));
892
- const timeZone =
893
- args.length === 3 ? TextValue(getAbstractSqlQuery(args, 2)) : undefined;
894
- return timeZone
895
- ? ['DateTrunc', precision, date, timeZone]
896
- : ['DateTrunc', precision, date];
897
- },
887
+ DateTrunc: matchArgs<DateTruncNode>('DateTrunc', TextValue, DateValue),
898
888
  ToTime: matchArgs<ToTimeNode>('ToTime', DateValue),
899
889
  ExtractJSONPathAsText: (args): ExtractJSONPathAsTextNode => {
900
890
  checkMinArgs('ExtractJSONPathAsText', args, 1);
@@ -1531,11 +1521,6 @@ const typeRules = {
1531
1521
  EscapeForLike: matchArgs<EscapeForLikeNode>('EscapeForLike', TextValue),
1532
1522
 
1533
1523
  // Virtual functions
1534
- Now: rewriteMatch(
1535
- 'Now',
1536
- [],
1537
- Helper<MatchFn<CurrentTimestampNode>>(() => ['CurrentTimestamp']),
1538
- ),
1539
1524
  Contains: rewriteMatch(
1540
1525
  'Contains',
1541
1526
  [TextValue, TextValue],
@@ -1,4 +1,5 @@
1
- import sbvrTypes from '@balena/sbvr-types';
1
+ import $sbvrTypes from '@balena/sbvr-types';
2
+ const { default: sbvrTypes } = $sbvrTypes;
2
3
  import type {
3
4
  AbstractSqlQuery,
4
5
  AbstractSqlType,
@@ -17,8 +18,8 @@ import type {
17
18
  StrictDurationTypeNodes,
18
19
  StrictTextArrayTypeNodes,
19
20
  StrictJSONTypeNodes,
20
- } from './AbstractSQLCompiler';
21
- import { Engines, isFieldTypeNode } from './AbstractSQLCompiler';
21
+ } from './AbstractSQLCompiler.js';
22
+ import { Engines, isFieldTypeNode } from './AbstractSQLCompiler.js';
22
23
 
23
24
  export type Binding =
24
25
  | [string, any]
@@ -75,6 +76,7 @@ const UnknownValue: MetaMatchFn = (args, indent) => {
75
76
  case 'Null':
76
77
  case 'Field':
77
78
  case 'ReferencedField':
79
+ case 'EqualsAny':
78
80
  case 'Bind':
79
81
  case 'Cast':
80
82
  case 'Case':
@@ -174,8 +176,7 @@ export const isBooleanValue = (
174
176
  type === 'Like' ||
175
177
  type === 'IsNotDistinctFrom' ||
176
178
  type === 'IsDistinctFrom' ||
177
- type === 'StartsWith' ||
178
- type === 'EqualsAny'
179
+ type === 'StartsWith'
179
180
  );
180
181
  };
181
182
  const BooleanValue = MatchValue(isBooleanValue);
@@ -1207,7 +1208,7 @@ const typeRules: Record<string, MatchFn> = {
1207
1208
  return `DATE(${date})`;
1208
1209
  },
1209
1210
  DateTrunc: (args, indent) => {
1210
- checkMinArgs('DateTrunc', args, 2);
1211
+ checkArgs('DateTrunc', args, 2);
1211
1212
  const precision = TextValue(getAbstractSqlQuery(args, 0), indent);
1212
1213
  const date = DateValue(getAbstractSqlQuery(args, 1), indent);
1213
1214
  // Postgres generated timestamps have a microseconds precision
@@ -1215,13 +1216,7 @@ const typeRules: Record<string, MatchFn> = {
1215
1216
  // js timestamps that have only milliseconds precision
1216
1217
  // thus supporting for truncating to a given precision
1217
1218
  if (engine === Engines.postgres) {
1218
- const timeZone =
1219
- args.length === 3
1220
- ? TextValue(getAbstractSqlQuery(args, 2), indent)
1221
- : undefined;
1222
- return timeZone
1223
- ? `DATE_TRUNC(${precision}, ${date}, ${timeZone})`
1224
- : `DATE_TRUNC(${precision}, ${date})`;
1219
+ return `DATE_TRUNC(${precision}, ${date})`;
1225
1220
  } else if (
1226
1221
  // not postgresql ==> no need to truncate ==> return timestamp as is (milliseconds precision)
1227
1222
  precision === "'milliseconds'" ||
@@ -4,17 +4,18 @@ export const enum Engines {
4
4
  websql = 'websql',
5
5
  }
6
6
 
7
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
8
- export { Binding, SqlResult } from './AbstractSQLRules2SQL';
9
- import sbvrTypes from '@balena/sbvr-types';
7
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
8
+ export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
9
+ import $sbvrTypes from '@balena/sbvr-types';
10
+ const { default: sbvrTypes } = $sbvrTypes;
10
11
  import type {
11
12
  AbstractSqlModel,
12
13
  AbstractSqlQuery,
13
14
  AbstractSqlType,
14
15
  BooleanTypeNodes,
15
16
  WhereNode,
16
- } from './AbstractSQLCompiler';
17
- import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler';
17
+ } from './AbstractSQLCompiler.js';
18
+ import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler.js';
18
19
 
19
20
  const countFroms = (n: AbstractSqlType[]) => {
20
21
  let count = 0;
@@ -48,7 +48,7 @@ import type {
48
48
  ToJSONNode,
49
49
  UnionQueryNode,
50
50
  WhereNode,
51
- } from './AbstractSQLCompiler';
51
+ } from './AbstractSQLCompiler.js';
52
52
  import {
53
53
  isAliasNode,
54
54
  isFromNode,
@@ -56,9 +56,9 @@ import {
56
56
  isSelectQueryNode,
57
57
  isTableNode,
58
58
  isWhereNode,
59
- } from './AbstractSQLCompiler';
60
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
61
- import { isAbstractSqlQuery } from './AbstractSQLRules2SQL';
59
+ } from './AbstractSQLCompiler.js';
60
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
61
+ import { isAbstractSqlQuery } from './AbstractSQLRules2SQL.js';
62
62
 
63
63
  export interface ReferencedFields {
64
64
  [alias: string]: string[];
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('AggregateJSON', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Count', () => {
5
5
  test(['SelectQuery', ['Select', [['Count', '*']]]], (result, sqlEquals) => {
@@ -33,7 +33,10 @@ describe('Sum', () => {
33
33
 
34
34
  describe('Subtract now timestamp from now timestamp', () => {
35
35
  test(
36
- ['SelectQuery', ['Select', [['Subtract', ['Now'], ['Now']]]]],
36
+ [
37
+ 'SelectQuery',
38
+ ['Select', [['Subtract', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
39
+ ],
37
40
  (result, sqlEquals) => {
38
41
  it('Subtract now timestamp from now timestamp', () => {
39
42
  sqlEquals(result, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
@@ -46,7 +49,10 @@ describe('Subtract Duration from now timestamp', () => {
46
49
  test(
47
50
  [
48
51
  'SelectQuery',
49
- ['Select', [['Subtract', ['Now'], ['Duration', { day: 1 }]]]],
52
+ [
53
+ 'Select',
54
+ [['Subtract', ['CurrentTimestamp'], ['Duration', { day: 1 }]]],
55
+ ],
50
56
  ],
51
57
  (result, sqlEquals) => {
52
58
  it('Subtract Duration from now timestamp', () => {
@@ -58,16 +64,25 @@ describe('Subtract Duration from now timestamp', () => {
58
64
 
59
65
  // this is not allowed
60
66
  describe('Add now timestamp to now timestamp should fail', () => {
61
- test.fail(['SelectQuery', ['Select', [['Add', ['Now'], ['Now']]]]], (err) => {
62
- it('Add now timestamp to now timestamp should fail', () => {
63
- expect(err).to.be.an('error');
64
- });
65
- });
67
+ test.fail(
68
+ [
69
+ 'SelectQuery',
70
+ ['Select', [['Add', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
71
+ ],
72
+ (err) => {
73
+ it('Add now timestamp to now timestamp should fail', () => {
74
+ expect(err).to.be.an('error');
75
+ });
76
+ },
77
+ );
66
78
  });
67
79
 
68
80
  describe('Add Duration to now timestamp', () => {
69
81
  test(
70
- ['SelectQuery', ['Select', [['Add', ['Now'], ['Duration', { day: 1 }]]]]],
82
+ [
83
+ 'SelectQuery',
84
+ ['Select', [['Add', ['CurrentTimestamp'], ['Duration', { day: 1 }]]]],
85
+ ],
71
86
  (result, sqlEquals) => {
72
87
  it('Add Duration to now timestamp', () => {
73
88
  sqlEquals(result, `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`);
@@ -85,7 +100,7 @@ describe('Substract DateTrunc datefield from now timestamp', () => {
85
100
  [
86
101
  [
87
102
  'Subtract',
88
- ['Now'],
103
+ ['CurrentTimestamp'],
89
104
  [
90
105
  'DateTrunc',
91
106
  ['EmbeddedText', 'milliseconds'],
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Unnecessary booleans should be removed', () => {
5
5
  test(
@@ -1,5 +1,8 @@
1
- import type { CaseNode, SelectQueryNode } from '../../src/AbstractSQLCompiler';
2
- import test from './test';
1
+ import type {
2
+ CaseNode,
3
+ SelectQueryNode,
4
+ } from '../../out/AbstractSQLCompiler.js';
5
+ import test from './test.js';
3
6
 
4
7
  const buildSelect = (withElse: boolean): SelectQueryNode => {
5
8
  let caseNode: CaseNode = [
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Cast', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Coalesce', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Between', () => {
5
5
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Year', () => {
4
4
  test(
@@ -127,29 +127,6 @@ describe('DateTrunc', () => {
127
127
  });
128
128
  },
129
129
  );
130
-
131
- test(
132
- [
133
- 'SelectQuery',
134
- [
135
- 'Select',
136
- [
137
- [
138
- 'DateTrunc',
139
- ['EmbeddedText', 'year'],
140
- ['Date', '2022-10-10'],
141
- ['EmbeddedText', 'UTC'],
142
- ],
143
- ],
144
- ],
145
- ],
146
- [['Date', '2022-10-10']],
147
- (result, sqlEquals) => {
148
- it('should produce a valid DateTrunc statement', () => {
149
- sqlEquals(result, `SELECT DATE_TRUNC('year', $1, 'UTC')`);
150
- });
151
- },
152
- );
153
130
  });
154
131
 
155
132
  describe('ToTime', () => {
@@ -359,7 +336,13 @@ describe('SubtractDateDate', () => {
359
336
  'SelectQuery',
360
337
  [
361
338
  'Select',
362
- [['Multiply', ['SubtractDateDate', ['Now'], ['Now']], ['Number', 4]]],
339
+ [
340
+ [
341
+ 'Multiply',
342
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
343
+ ['Number', 4],
344
+ ],
345
+ ],
363
346
  ],
364
347
  ],
365
348
  (result, sqlEquals) => {
@@ -377,7 +360,7 @@ describe('SubtractDateDate', () => {
377
360
  [
378
361
  [
379
362
  'Multiply',
380
- ['SubtractDateDate', ['Now'], ['Now']],
363
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
381
364
  ['Subtract', ['Number', 4], ['Number', 5]],
382
365
  ],
383
366
  ],
@@ -403,7 +386,7 @@ describe('SubtractDateDate', () => {
403
386
  'SubtractDateDate',
404
387
  [
405
388
  'AddDateDuration',
406
- ['Now'],
389
+ ['CurrentTimestamp'],
407
390
  [
408
391
  'Duration',
409
392
  {
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Totalseconds', () => {
4
4
  test(
@@ -1,7 +1,7 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import type { SelectQueryNode } from '../../src/AbstractSQLCompiler';
2
+ import type { SelectQueryNode } from '../../out/AbstractSQLCompiler.js';
3
3
 
4
- import test from './test';
4
+ import test from './test.js';
5
5
 
6
6
  describe('Empty queries should be optimized', () => {
7
7
  const emptyQuery: SelectQueryNode = [
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Date trunc function on ReferencedField for milliseconds', () => {
5
5
  test(
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../src/AbstractSQLCompiler';
2
+ import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
3
3
 
4
4
  describe('getReferencedFields', () => {
5
5
  it('should work with selected fields', () => {
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../src/AbstractSQLCompiler';
2
+ import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
3
3
 
4
4
  describe('getRuleReferencedFields', () => {
5
5
  it('should work with single table NOT EXISTS', () => {
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Insert boolean value', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('IsDistinctFrom', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  const joinTest = (
5
5
  joinType: 'Join' | 'RightJoin' | 'LeftJoin' | 'FullJoin',
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('ExtractJSONPathAsText', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Add', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Nested OR EQUALs should create a single IN statement', () => {
5
5
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('NOT(NOT(...)) should cancel each other out', () => {
5
5
  test(['Not', ['Not', ['Boolean', true]]], [], (result, sqlEquals) => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  it('an empty abstractSql model should produce an empty schema', () => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  describe('generate informative reference schema', () => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  const generateSchema = (
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  const generateSchema = (
@@ -1,7 +1,7 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
- it('a table with a static definition should produce a view', () => {
4
+ it('a table with a static definition should not produce a view', () => {
5
5
  expect(
6
6
  AbstractSQLCompiler.postgres.compileSchema({
7
7
  synonyms: {},
@@ -30,6 +30,41 @@ it('a table with a static definition should produce a view', () => {
30
30
  .to.have.property('createSchema')
31
31
  .that.deep.equals([
32
32
  `\
33
+ CREATE TABLE IF NOT EXISTS "test" (
34
+ "id" INTEGER NULL PRIMARY KEY
35
+ );`,
36
+ ]);
37
+ });
38
+
39
+ it('a table with a view definition should produce a view', () => {
40
+ expect(
41
+ AbstractSQLCompiler.postgres.compileSchema({
42
+ synonyms: {},
43
+ relationships: {},
44
+ tables: {
45
+ test: {
46
+ name: 'test',
47
+ resourceName: 'test',
48
+ idField: 'id',
49
+ fields: [
50
+ {
51
+ fieldName: 'id',
52
+ dataType: 'Integer',
53
+ index: 'PRIMARY KEY',
54
+ },
55
+ ],
56
+ indexes: [],
57
+ primitive: false,
58
+ viewDefinition: { abstractSql: ['Table', 'other table'] },
59
+ },
60
+ },
61
+ rules: [],
62
+ lfInfo: { rules: {} },
63
+ }),
64
+ )
65
+ .to.have.property('createSchema')
66
+ .that.deep.equals([
67
+ `\
33
68
  CREATE OR REPLACE VIEW "test" AS (
34
69
  SELECT *
35
70
  FROM "other table"
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
 
3
3
  import { expect } from 'chai';
4
4
  import _ from 'lodash';
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Concatenate', () => {
4
4
  test(