taon-type-sql 19.0.3 → 19.0.5

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.
@@ -1,9 +1,8 @@
1
1
  import { Log } from 'ng2-logger/browser';
2
2
 
3
+ // TODO I had to copy-paste the method implementations to every child class to avoid circular dependencies
3
4
  class QueryCondition {
4
5
  }
5
- ;
6
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/condition/query-condition.ts
7
6
 
8
7
  class QueryConditionChain extends QueryCondition {
9
8
  constructor(sibling, child, chainType) {
@@ -14,6 +13,7 @@ class QueryConditionChain extends QueryCondition {
14
13
  this._child = child;
15
14
  this._chainType = chainType;
16
15
  }
16
+ // TODO how to call this
17
17
  $() {
18
18
  this._parenthesis = true;
19
19
  return this;
@@ -29,8 +29,6 @@ class QueryConditionChain extends QueryCondition {
29
29
  return new QueryConditionChain(this, condition, 'or');
30
30
  }
31
31
  }
32
- ;
33
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/condition/query-condition-chain.ts
34
32
 
35
33
  class QueryColumnCondition extends QueryCondition {
36
34
  constructor(column, type, ...values) {
@@ -46,8 +44,6 @@ class QueryColumnCondition extends QueryCondition {
46
44
  return new QueryConditionChain(this, condition, 'or');
47
45
  }
48
46
  }
49
- ;
50
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/condition/query-column-condition.ts
51
47
 
52
48
  class QueryColumn {
53
49
  constructor(_table, _name, _modifiers = []) {
@@ -65,8 +61,6 @@ class QueryColumn {
65
61
  return new QueryColumnCondition(this, 'is-not-null');
66
62
  }
67
63
  }
68
- ;
69
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/query-column.ts
70
64
 
71
65
  class QueryOrdering {
72
66
  constructor(column, direction) {
@@ -82,8 +76,6 @@ class QueryOrdering {
82
76
  return this;
83
77
  }
84
78
  }
85
- ;
86
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/other/query-ordering.ts
87
79
 
88
80
  class QueryJoinCondition extends QueryCondition {
89
81
  constructor(column, type, otherColumn) {
@@ -99,8 +91,6 @@ class QueryJoinCondition extends QueryCondition {
99
91
  return new QueryConditionChain(this, condition, 'or');
100
92
  }
101
93
  }
102
- ;
103
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/condition/query-join-condition.ts
104
94
 
105
95
  class ValueColumn extends QueryColumn {
106
96
  constructor(table, name, modifiers = []) {
@@ -124,8 +114,6 @@ class ValueColumn extends QueryColumn {
124
114
  return new QueryColumnCondition(this, 'ne', value);
125
115
  }
126
116
  }
127
- ;
128
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/value-column.ts
129
117
 
130
118
  class ComparableColumn extends ValueColumn {
131
119
  constructor(table, name, modifiers = []) {
@@ -155,6 +143,7 @@ class ComparableColumn extends ValueColumn {
155
143
  notBetween(value1, value2) {
156
144
  return new QueryColumnCondition(this, 'not-between', value1, value2);
157
145
  }
146
+ // min/max exists for text columns too, not just numeric and date
158
147
  min() {
159
148
  return new this.constructor(this._table, this._name, this._modifiers.concat({ name: 'min' }));
160
149
  }
@@ -162,8 +151,6 @@ class ComparableColumn extends ValueColumn {
162
151
  return new this.constructor(this._table, this._name, this._modifiers.concat({ name: 'max' }));
163
152
  }
164
153
  }
165
- ;
166
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/comparable-column.ts
167
154
 
168
155
  class NumberColumn extends ComparableColumn {
169
156
  constructor(table, name, modifiers = []) {
@@ -180,9 +167,8 @@ class NumberColumn extends ComparableColumn {
180
167
  return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'avg' }));
181
168
  }
182
169
  }
183
- ;
184
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/number-column.ts
185
170
 
171
+ // This file is only needed because the QueryColumn can't implement its count method b. of circular dependencies
186
172
  class BasicColumn extends QueryColumn {
187
173
  constructor(table, name, modifiers = []) {
188
174
  super(table, name, modifiers);
@@ -191,8 +177,6 @@ class BasicColumn extends QueryColumn {
191
177
  return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
192
178
  }
193
179
  }
194
- ;
195
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/basic-column.ts
196
180
 
197
181
  class BooleanColumn extends ValueColumn {
198
182
  constructor(table, name, modifiers = []) {
@@ -203,8 +187,6 @@ class BooleanColumn extends ValueColumn {
203
187
  return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
204
188
  }
205
189
  }
206
- ;
207
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/boolean-column.ts
208
190
 
209
191
  class DateColumn extends ComparableColumn {
210
192
  constructor(table, name, modifiers = []) {
@@ -215,8 +197,6 @@ class DateColumn extends ComparableColumn {
215
197
  return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
216
198
  }
217
199
  }
218
- ;
219
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/date-column.ts
220
200
 
221
201
  class StringColumn extends ComparableColumn {
222
202
  constructor(table, name, modifiers = []) {
@@ -248,8 +228,6 @@ class StringColumn extends ComparableColumn {
248
228
  return new QueryColumnCondition(this, 'not-like', value);
249
229
  }
250
230
  }
251
- ;
252
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/column/string-column.ts
253
231
 
254
232
  class JoinedTablesChain {
255
233
  constructor(_table, _modifier, _parent) {
@@ -261,8 +239,6 @@ class JoinedTablesChain {
261
239
  return new JoinedTables(condition, this);
262
240
  }
263
241
  }
264
- ;
265
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/join/joined-tables-chain.ts
266
242
 
267
243
  class JoinedTables {
268
244
  constructor(_condition, _parent) {
@@ -282,8 +258,6 @@ class JoinedTables {
282
258
  return new JoinedTablesChain(table, 'full', this);
283
259
  }
284
260
  }
285
- ;
286
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/join/joined-tables.ts
287
261
 
288
262
  class SelectQuery {
289
263
  constructor(_queryProcessor, _tables) {
@@ -330,8 +304,6 @@ class SelectQuery {
330
304
  return this._queryProcessor(this);
331
305
  }
332
306
  }
333
- ;
334
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/query/select-query.ts
335
307
 
336
308
  class TableConditionQuery {
337
309
  constructor(_queryProcessor, _table, _conditions) {
@@ -355,8 +327,6 @@ class TableConditionQuery {
355
327
  return this._queryProcessor(this).then((rows) => rows[0]);
356
328
  }
357
329
  }
358
- ;
359
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/query/table-condition-query.ts
360
330
 
361
331
  class TableQuery {
362
332
  constructor(_queryProcessor, _table) {
@@ -398,6 +368,7 @@ class TableQuery {
398
368
  .then((rows) => rows[0]);
399
369
  }
400
370
  _whereId(id) {
371
+ // TODO remove assertions if $id typing is fixed
401
372
  let $id = this._table.$id;
402
373
  if ($id instanceof ValueColumn) {
403
374
  return this.where($id.eq(id));
@@ -407,8 +378,6 @@ class TableQuery {
407
378
  }
408
379
  }
409
380
  }
410
- ;
411
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/query/table-query.ts
412
381
 
413
382
  class QuerySource {
414
383
  constructor(_queryProcessor) {
@@ -425,12 +394,11 @@ class QuerySource {
425
394
  return new TableQuery(this._queryProcessor, table);
426
395
  }
427
396
  }
428
- ;
429
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/query-source.ts
430
397
 
431
398
  class QueryTable {
432
399
  constructor(_$name) {
433
400
  this._$name = _$name;
401
+ // abstract readonly $id; // FIXME I got a dozen incomprehensible type errors
434
402
  this.$all = new BasicColumn(this, '*');
435
403
  }
436
404
  innerJoin(table) {
@@ -446,8 +414,6 @@ class QueryTable {
446
414
  return new JoinedTablesChain(table, 'full', this);
447
415
  }
448
416
  }
449
- ;
450
- ({}); // @--end-of-file-for-module=taon-type-sql lib/builder/query-table.ts
451
417
 
452
418
  function number(param) {
453
419
  let result = Number(param);
@@ -485,8 +451,6 @@ function string(param) {
485
451
  return param.valueOf();
486
452
  throw new Error('Invalid string parameter in SQL query: ' + param);
487
453
  }
488
- ;
489
- ({}); // @--end-of-file-for-module=taon-type-sql lib/converter/type-converter.ts
490
454
 
491
455
  function createQueryConverter(paramConverter, options, engine) {
492
456
  return convertQuery;
@@ -676,6 +640,7 @@ function createQueryConverter(paramConverter, options, engine) {
676
640
  preprocessParams(condition);
677
641
  });
678
642
  }
643
+ // this is only needed, so that the $1, $2... numbering is not reversed
679
644
  function preprocessParams(condition) {
680
645
  if (condition._sibling) {
681
646
  preprocessParams(condition._sibling);
@@ -766,8 +731,6 @@ function createQueryConverter(paramConverter, options, engine) {
766
731
  return param;
767
732
  }
768
733
  }
769
- ;
770
- ({}); // @--end-of-file-for-module=taon-type-sql lib/converter/query-converter.ts
771
734
 
772
735
  function convertSubstitutionParam(param) {
773
736
  if (param == null)
@@ -786,6 +749,8 @@ function convertSubstitutionParam(param) {
786
749
  }
787
750
  return `'${JSON.stringify(param)}'`;
788
751
  }
752
+ // node mysql doesn't have an typeCast equivalent solution for the other direction
753
+ // node-postgres: https://github.com/brianc/node-postgres/issues/442
789
754
  function convertEscapedParam(param) {
790
755
  if (typeof param === 'object' && !(param == null || param instanceof String || param instanceof Number ||
791
756
  param instanceof Boolean || param instanceof Date)) {
@@ -793,8 +758,6 @@ function convertEscapedParam(param) {
793
758
  }
794
759
  return param;
795
760
  }
796
- ;
797
- ({}); // @--end-of-file-for-module=taon-type-sql lib/converter/param-converter.ts
798
761
 
799
762
  let pgParamConverter = (index) => '$' + index;
800
763
  let mySqlParamConverter = (index) => '?';
@@ -808,14 +771,10 @@ function convertQueryToParameterizedSQL(query, options, engine) {
808
771
  let sql = createQueryConverter((param) => convertSingleParam(param, params, paramConverter), options, engine)(query);
809
772
  return { sql, params };
810
773
  }
811
- ;
812
- ({}); // @--end-of-file-for-module=taon-type-sql lib/converter/parameterized-converter.ts
813
774
 
814
775
  function convertQueryToSQL(query, options, engine) {
815
776
  return createQueryConverter((param) => convertSubstitutionParam(param), options, engine)(query);
816
777
  }
817
- ;
818
- ({}); // @--end-of-file-for-module=taon-type-sql lib/converter/sql-converter.ts
819
778
 
820
779
  const log = Log.create('query processor');
821
780
  const DEFAULT_OPTIONS = {
@@ -845,29 +804,52 @@ function createQueryProcessor(client, _options = {}, engine = 'pg') {
845
804
  lineBreak: options.lineBreaks ? '\n' : ' ',
846
805
  nameEscape: _options.identifierQuote || (engine === 'mysql' ? '`' : '"')
847
806
  };
807
+ // function processSql(query: any, sql: string, params: any[] | undefined, callback: any): Promise<any> {
808
+ // if (options.logging) log.i(sql);
809
+ // if (options.logger) options.logger(sql, params);
810
+ // return new Promise((resolve, reject) => {
811
+ // callback(sql, params, (err: any, result: any) => {
812
+ // if (err) reject(err);
813
+ // else resolve(convertResult(query, result, engine));
814
+ // });
815
+ // });
816
+ // }
817
+ // function executeSql(sql: string, params: any[] | undefined, cb: any) {
818
+ // if (engine === 'pg') {
819
+ // client.query(sql, params || cb, params ? cb : undefined);
820
+ // } else if (engine === 'mysql') {
821
+ // client.query({
822
+ // sql,
823
+ // values: params,
824
+ // typeCast: mySqlTypeCast
825
+ // }, cb);
826
+ // } else throw new Error('Unknown DB engine: ' + engine);
827
+ // }
848
828
  return (query) => {
849
829
  if (options.parameterized) {
850
830
  let { sql, params } = convertQueryToParameterizedSQL(query, queryOptions, engine);
831
+ // if (Helpers.isWebSQL || Helpers.isNode) {
851
832
  return client.query(sql, params);
833
+ // }
834
+ // return processSql(query, sql, params, (sql: string, params: any[], cb: any) => executeSql(sql, params, cb));
852
835
  }
853
836
  else {
854
837
  let sql = convertQueryToSQL(query, queryOptions, engine);
838
+ // if (Helpers.isWebSQL || Helpers.isNode) {
855
839
  return client.query(sql, undefined);
840
+ // }
841
+ // return processSql(query, sql, undefined, (sql: string, params: undefined, cb: any) => executeSql(sql, undefined, cb));
856
842
  }
857
843
  };
858
844
  }
859
- ;
860
- ({}); // @--end-of-file-for-module=taon-type-sql lib/client/query-processor.ts
861
845
 
862
846
  class MySqlQuerySource extends QuerySource {
863
847
  constructor(client, options = {}) {
864
848
  super(createQueryProcessor(client, options, 'mysql'));
865
849
  }
866
850
  }
867
- ;
868
- ({}); // @--end-of-file-for-module=taon-type-sql lib/client/mysql.ts
869
851
 
870
- ({}); // @--end-of-file-for-module=taon-type-sql lib/index.ts
852
+ // Builder:
871
853
 
872
854
  /**
873
855
  * Generated bundle index. Do not edit.