remult 3.4.0-next.9 → 3.4.0

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqlDatabase = void 0;
4
+ exports.jsonColumnStorageOf = jsonColumnStorageOf;
4
5
  exports.getRowAfterUpdate = getRowAfterUpdate;
5
6
  exports.buildFindSql = buildFindSql;
6
7
  exports.groupByImpl = groupByImpl;
@@ -82,6 +83,13 @@ var SqlDatabase = /** @class */ (function () {
82
83
  });
83
84
  });
84
85
  };
86
+ Object.defineProperty(SqlDatabase.prototype, "jsonColumnStorage", {
87
+ get: function () {
88
+ return this.sql.supportsJsonColumnType ? 'native' : 'text';
89
+ },
90
+ enumerable: false,
91
+ configurable: true
92
+ });
85
93
  /* @internal*/
86
94
  SqlDatabase.prototype._getSourceSql = function () {
87
95
  return this.sql;
@@ -107,26 +115,7 @@ var SqlDatabase = /** @class */ (function () {
107
115
  * @returns The entity data provider.
108
116
  */
109
117
  SqlDatabase.prototype.getEntityDataProvider = function (entity) {
110
- var e_1, _a;
111
118
  var _this = this;
112
- if (!this.sql.supportsJsonColumnType) {
113
- try {
114
- for (var _b = tslib_1.__values(entity.fields.toArray()), _c = _b.next(); !_c.done; _c = _b.next()) {
115
- var f = _c.value;
116
- if (f.valueConverter.fieldTypeInDb === 'json') {
117
- //@ts-ignore
118
- f.valueConverter = tslib_1.__assign(tslib_1.__assign({}, f.valueConverter), { toDb: valueConverters_js_1.ValueConverters.JsonString.toDb, fromDb: valueConverters_js_1.ValueConverters.JsonString.fromDb });
119
- }
120
- }
121
- }
122
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
123
- finally {
124
- try {
125
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
126
- }
127
- finally { if (e_1) throw e_1.error; }
128
- }
129
- }
130
119
  return new ActualSQLEntityDataProvider(entity, this, function (dbName) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
131
120
  return tslib_1.__generator(this, function (_a) {
132
121
  switch (_a.label) {
@@ -243,7 +232,7 @@ var SqlDatabase = /** @class */ (function () {
243
232
  _c = (_d.sent());
244
233
  _d.label = 2;
245
234
  case 2:
246
- b = new (_a.apply(filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest, _b.concat([_c])))();
235
+ b = new (_a.apply(filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest, _b.concat([_c, jsonColumnStorageOf(r)])))();
247
236
  b._addWhere = false;
248
237
  return [4 /*yield*/, (0, repository_internals_js_1.getRepositoryInternals)(r)._translateWhereToFilter(condition)];
249
238
  case 3: return [4 /*yield*/, (_d.sent()).__applyToConsumer(b)];
@@ -279,7 +268,7 @@ var SqlDatabase = /** @class */ (function () {
279
268
  case 3:
280
269
  _c = (_h.sent());
281
270
  _h.label = 4;
282
- case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), false, (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired]))];
271
+ case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), false, (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired, jsonColumnStorageForRaw(r, sql === null || sql === void 0 ? void 0 : sql.jsonAsString)]))];
283
272
  case 5:
284
273
  built = _h.sent();
285
274
  return [2 /*return*/, {
@@ -315,7 +304,10 @@ var SqlDatabase = /** @class */ (function () {
315
304
  case 3:
316
305
  _c = (_h.sent());
317
306
  _h.label = 4;
318
- case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), false, (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired, { aliasColumns: true }]))];
307
+ case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), false, (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired, {
308
+ aliasColumns: true,
309
+ jsonColumnStorage: jsonColumnStorageForRaw(r, sql === null || sql === void 0 ? void 0 : sql.jsonAsString),
310
+ }]))];
319
311
  case 5:
320
312
  built = _h.sent();
321
313
  return [2 /*return*/, {
@@ -347,7 +339,7 @@ var SqlDatabase = /** @class */ (function () {
347
339
  exports.SqlDatabase = SqlDatabase;
348
340
  var defaultMaxParametersInOneSqlStatement = 2000;
349
341
  function splitByMaxParameters(items, parametersInItem, maxParameters) {
350
- var e_2, _a;
342
+ var e_1, _a;
351
343
  var batches = [];
352
344
  var batch = [];
353
345
  var params = 0;
@@ -364,35 +356,35 @@ function splitByMaxParameters(items, parametersInItem, maxParameters) {
364
356
  params += n;
365
357
  }
366
358
  }
367
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
359
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
368
360
  finally {
369
361
  try {
370
362
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
371
363
  }
372
- finally { if (e_2) throw e_2.error; }
364
+ finally { if (e_1) throw e_1.error; }
373
365
  }
374
366
  if (batch.length)
375
367
  batches.push(batch);
376
368
  return batches;
377
369
  }
378
- function countInsertBindParameters(entity, e, row) {
379
- var e_3, _a;
370
+ function countInsertBindParameters(entity, e, row, storage) {
371
+ var e_2, _a;
380
372
  var n = 0;
381
373
  try {
382
374
  for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
383
375
  var x = _c.value;
384
376
  if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e))
385
377
  continue;
386
- if (x.valueConverter.toDb(row[x.key]) != undefined)
378
+ if ((0, valueConverters_js_1.toDbColumn)(x, row[x.key], storage) != undefined)
387
379
  n++;
388
380
  }
389
381
  }
390
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
382
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
391
383
  finally {
392
384
  try {
393
385
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
394
386
  }
395
- finally { if (e_3) throw e_3.error; }
387
+ finally { if (e_2) throw e_2.error; }
396
388
  }
397
389
  return n;
398
390
  }
@@ -507,7 +499,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
507
499
  select = 'select count(*) count from ' + e.$entityName;
508
500
  r = this.sql.createCommand();
509
501
  if (!where) return [3 /*break*/, 3];
510
- wc = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
502
+ wc = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e, this.sql.jsonColumnStorage);
511
503
  where.__applyToConsumer(wc);
512
504
  _a = select;
513
505
  return [4 /*yield*/, wc.resolveWhere()];
@@ -532,7 +524,8 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
532
524
  return [4 /*yield*/, this.init()];
533
525
  case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c.sent(), this.sql.createCommand(),
534
526
  this.sql._getSourceSql().orderByNullsFirst,
535
- this.sql._getSourceSql().getLimitSqlSyntax]))];
527
+ this.sql._getSourceSql().getLimitSqlSyntax,
528
+ this.sql.jsonColumnStorage]))];
536
529
  case 2: return [2 /*return*/, _c.sent()];
537
530
  }
538
531
  });
@@ -550,7 +543,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
550
543
  r = this.sql.createCommand();
551
544
  if (options && !options.orderBy)
552
545
  options.orderBy = sort_js_1.Sort.createUniqueSort(this.entity, new sort_js_1.Sort());
553
- return [4 /*yield*/, buildFindSql(this.entity, options, e, r, this.sql._getSourceSql().orderByNullsFirst, function (limit, offset) { return _this.strategy.getLimitSqlSyntax(limit, offset); })];
546
+ return [4 /*yield*/, buildFindSql(this.entity, options, e, r, this.sql._getSourceSql().orderByNullsFirst, function (limit, offset) { return _this.strategy.getLimitSqlSyntax(limit, offset); }, { jsonColumnStorage: this.sql.jsonColumnStorage })];
554
547
  case 2:
555
548
  _a = _b.sent(), select = _a.select, toResult = _a.toResult;
556
549
  return [4 /*yield*/, r.execute(select)];
@@ -564,7 +557,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
564
557
  });
565
558
  };
566
559
  ActualSQLEntityDataProvider.prototype.buildResultRow = function (colKeys, y, r) {
567
- return resultRow(colKeys, function (i) { return y[r.getColumnKeyInResultForIndexInSelect(i)]; });
560
+ return resultRow(colKeys, function (i) { return y[r.getColumnKeyInResultForIndexInSelect(i)]; }, this.sql.jsonColumnStorage);
568
561
  };
569
562
  ActualSQLEntityDataProvider.prototype.buildSelect = function (e, r, selectedFields, args) {
570
563
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -576,7 +569,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
576
569
  ActualSQLEntityDataProvider.prototype.update = function (id, data, options) {
577
570
  return tslib_1.__awaiter(this, void 0, void 0, function () {
578
571
  var e, r, statement, added, _a, _b, x, v, idFilter, f, _c, _d, colKeys, select, returning;
579
- var e_4, _e;
572
+ var e_3, _e;
580
573
  var _this = this;
581
574
  return tslib_1.__generator(this, function (_f) {
582
575
  switch (_f.label) {
@@ -592,7 +585,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
592
585
  if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e)) {
593
586
  }
594
587
  else if (data[x.key] !== undefined) {
595
- v = x.valueConverter.toDb(data[x.key]);
588
+ v = (0, valueConverters_js_1.toDbColumn)(x, data[x.key], this.sql.jsonColumnStorage);
596
589
  if (v !== undefined) {
597
590
  if (!added)
598
591
  added = true;
@@ -603,15 +596,15 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
603
596
  }
604
597
  }
605
598
  }
606
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
599
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
607
600
  finally {
608
601
  try {
609
602
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
610
603
  }
611
- finally { if (e_4) throw e_4.error; }
604
+ finally { if (e_3) throw e_3.error; }
612
605
  }
613
606
  idFilter = this.entity.idMetadata.getIdFilter(id);
614
- f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
607
+ f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e, this.sql.jsonColumnStorage);
615
608
  filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, idFilter).__applyToConsumer(f);
616
609
  _c = statement;
617
610
  return [4 /*yield*/, f.resolveWhere()];
@@ -663,7 +656,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
663
656
  case 1:
664
657
  e = _c.sent();
665
658
  r = this.sql.createCommand();
666
- f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
659
+ f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e, this.sql.jsonColumnStorage);
667
660
  filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, (_b = this.entity.idMetadata).getIdFilter.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(ids), false))).__applyToConsumer(f);
668
661
  statement = 'delete from ' + e.$entityName;
669
662
  _a = statement;
@@ -680,8 +673,8 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
680
673
  };
681
674
  ActualSQLEntityDataProvider.prototype.insert = function (data, options) {
682
675
  return tslib_1.__awaiter(this, void 0, void 0, function () {
683
- var e, maxParams, batches, result, batches_1, batches_1_1, batch, _a, _b, _c, _d, e_5_1;
684
- var e_5, _e;
676
+ var e, maxParams, batches, result, batches_1, batches_1_1, batch, _a, _b, _c, _d, e_4_1;
677
+ var e_4, _e;
685
678
  var _this = this;
686
679
  var _f;
687
680
  return tslib_1.__generator(this, function (_g) {
@@ -693,7 +686,9 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
693
686
  case 1:
694
687
  e = _g.sent();
695
688
  maxParams = (_f = this.strategy.maxParametersInOneSqlStatement) !== null && _f !== void 0 ? _f : defaultMaxParametersInOneSqlStatement;
696
- batches = splitByMaxParameters(data, function (row) { return countInsertBindParameters(_this.entity, e, row); }, maxParams);
689
+ batches = splitByMaxParameters(data, function (row) {
690
+ return countInsertBindParameters(_this.entity, e, row, _this.sql.jsonColumnStorage);
691
+ }, maxParams);
697
692
  result = [];
698
693
  _g.label = 2;
699
694
  case 2:
@@ -715,14 +710,14 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
715
710
  return [3 /*break*/, 3];
716
711
  case 6: return [3 /*break*/, 9];
717
712
  case 7:
718
- e_5_1 = _g.sent();
719
- e_5 = { error: e_5_1 };
713
+ e_4_1 = _g.sent();
714
+ e_4 = { error: e_4_1 };
720
715
  return [3 /*break*/, 9];
721
716
  case 8:
722
717
  try {
723
718
  if (batches_1_1 && !batches_1_1.done && (_e = batches_1.return)) _e.call(batches_1);
724
719
  }
725
- finally { if (e_5) throw e_5.error; }
720
+ finally { if (e_4) throw e_4.error; }
726
721
  return [7 /*endfinally*/];
727
722
  case 9: return [2 /*return*/, result];
728
723
  }
@@ -743,7 +738,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
743
738
  ActualSQLEntityDataProvider.prototype.insertBatch = function (batch, e, options) {
744
739
  return tslib_1.__awaiter(this, void 0, void 0, function () {
745
740
  var r, cols, _loop_1, _a, _b, x, colSql, vals, i, i, j, x, v, statement, _c, colKeys, select, source, wantRows, sql, lastId, ids, id;
746
- var e_6, _d;
741
+ var e_5, _d;
747
742
  var _this = this;
748
743
  var _e;
749
744
  return tslib_1.__generator(this, function (_f) {
@@ -754,7 +749,9 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
754
749
  _loop_1 = function (x) {
755
750
  if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e))
756
751
  return "continue";
757
- if (batch.some(function (row) { return x.valueConverter.toDb(row[x.key]) != undefined; }))
752
+ if (batch.some(function (row) {
753
+ return (0, valueConverters_js_1.toDbColumn)(x, row[x.key], _this.sql.jsonColumnStorage) != undefined;
754
+ }))
758
755
  cols.push(x);
759
756
  };
760
757
  try {
@@ -763,12 +760,12 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
763
760
  _loop_1(x);
764
761
  }
765
762
  }
766
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
763
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
767
764
  finally {
768
765
  try {
769
766
  if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
770
767
  }
771
- finally { if (e_6) throw e_6.error; }
768
+ finally { if (e_5) throw e_5.error; }
772
769
  }
773
770
  colSql = '';
774
771
  vals = '';
@@ -785,7 +782,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
785
782
  if (j)
786
783
  vals += ', ';
787
784
  x = cols[j];
788
- v = x.valueConverter.toDb(batch[i][x.key]);
785
+ v = (0, valueConverters_js_1.toDbColumn)(x, batch[i][x.key], this.sql.jsonColumnStorage);
789
786
  if (v != undefined)
790
787
  vals += (0, filter_consumer_bridge_to_sql_request_js_1.toDbSql)(r, x, v);
791
788
  else if (x.allowNull)
@@ -861,6 +858,17 @@ function wrapIdentifierOf(r) {
861
858
  return (_a = dp.wrapIdentifier) === null || _a === void 0 ? void 0 : _a.bind(dp);
862
859
  return undefined;
863
860
  }
861
+ function jsonColumnStorageOf(r) {
862
+ var dp = (0, repository_internals_js_1.getRepositoryInternals)(r)._dataProvider;
863
+ if ((0, isOfType_js_1.isOfType)(dp, 'jsonColumnStorage'))
864
+ return dp.jsonColumnStorage;
865
+ return 'native';
866
+ }
867
+ function jsonColumnStorageForRaw(r, jsonAsString) {
868
+ if (jsonAsString === undefined)
869
+ return jsonColumnStorageOf(r);
870
+ return jsonAsString ? 'text' : 'native';
871
+ }
864
872
  function limitSyntaxRequired() {
865
873
  throw new Error('A raw select with a limit needs limitSyntax, for example SqlDatabase.getDb()._getSourceSql().getLimitSqlSyntax');
866
874
  }
@@ -892,7 +900,7 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
892
900
  return dataProvider
893
901
  .find({
894
902
  where: new filter_interfaces_js_1.Filter(function (x) {
895
- var e_7, _a;
903
+ var e_6, _a;
896
904
  var _b;
897
905
  try {
898
906
  for (var _c = tslib_1.__values(meta.idMetadata.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -900,12 +908,12 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
900
908
  x.isEqualTo(field, (_b = data[field.key]) !== null && _b !== void 0 ? _b : idFilter[field.key]);
901
909
  }
902
910
  }
903
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
911
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
904
912
  finally {
905
913
  try {
906
914
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
907
915
  }
908
- finally { if (e_7) throw e_7.error; }
916
+ finally { if (e_6) throw e_6.error; }
909
917
  }
910
918
  }),
911
919
  })
@@ -916,37 +924,37 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
916
924
  });
917
925
  }
918
926
  /** The select that `find` runs, and the mapping of one result row to field values. With `aliasColumns`, every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
919
- function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitSyntax_1) {
927
+ function buildFindSql(entity_1, options_1, e_7, r_1, orderByNullsFirst_1, limitSyntax_1) {
920
928
  return tslib_1.__awaiter(this, arguments, void 0, function (entity, options, e, r, orderByNullsFirst, limitSyntax, _a) {
921
- var _b, colKeys, columns, select, where, _c, first, _d, _e, c, _f, _g, e_9_1, page;
922
- var e_9, _h;
923
- var _j = _a === void 0 ? {} : _a, _k = _j.aliasColumns, aliasColumns = _k === void 0 ? false : _k;
924
- return tslib_1.__generator(this, function (_l) {
925
- switch (_l.label) {
929
+ var _b, colKeys, columns, select, where, _c, first, _d, _e, c, _f, _g, e_8_1, page;
930
+ var e_8, _h;
931
+ var _j = _a === void 0 ? {} : _a, _k = _j.aliasColumns, aliasColumns = _k === void 0 ? false : _k, _l = _j.jsonColumnStorage, jsonColumnStorage = _l === void 0 ? 'native' : _l;
932
+ return tslib_1.__generator(this, function (_m) {
933
+ switch (_m.label) {
926
934
  case 0: return [4 /*yield*/, selectColumns(entity, e, r, options === null || options === void 0 ? void 0 : options.select, options === null || options === void 0 ? void 0 : options.args, aliasColumns)];
927
935
  case 1:
928
- _b = _l.sent(), colKeys = _b.colKeys, columns = _b.select;
936
+ _b = _m.sent(), colKeys = _b.colKeys, columns = _b.select;
929
937
  select = 'select ' + columns + '\n from ' + e.$entityName;
930
938
  if (!options) return [3 /*break*/, 14];
931
939
  if (!options.where) return [3 /*break*/, 3];
932
- where = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
940
+ where = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e, jsonColumnStorage);
933
941
  options.where.__applyToConsumer(where);
934
942
  _c = select;
935
943
  return [4 /*yield*/, where.resolveWhere()];
936
944
  case 2:
937
- select = _c + _l.sent();
938
- _l.label = 3;
945
+ select = _c + _m.sent();
946
+ _m.label = 3;
939
947
  case 3:
940
948
  if (options.limit) {
941
949
  options.orderBy = sort_js_1.Sort.createUniqueSort(entity, options.orderBy);
942
950
  }
943
951
  if (!options.orderBy) return [3 /*break*/, 13];
944
952
  first = true;
945
- _l.label = 4;
953
+ _m.label = 4;
946
954
  case 4:
947
- _l.trys.push([4, 11, 12, 13]);
955
+ _m.trys.push([4, 11, 12, 13]);
948
956
  _d = tslib_1.__values(options.orderBy.Segments), _e = _d.next();
949
- _l.label = 5;
957
+ _m.label = 5;
950
958
  case 5:
951
959
  if (!!_e.done) return [3 /*break*/, 10];
952
960
  c = _e.value;
@@ -962,8 +970,8 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
962
970
  return [3 /*break*/, 8];
963
971
  case 6: return [4 /*yield*/, e.$dbNameOf(c.field)];
964
972
  case 7:
965
- _g = _l.sent();
966
- _l.label = 8;
973
+ _g = _m.sent();
974
+ _m.label = 8;
967
975
  case 8:
968
976
  select = _f + _g;
969
977
  if (c.isDescending)
@@ -974,20 +982,20 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
974
982
  else
975
983
  select += ' nulls first';
976
984
  }
977
- _l.label = 9;
985
+ _m.label = 9;
978
986
  case 9:
979
987
  _e = _d.next();
980
988
  return [3 /*break*/, 5];
981
989
  case 10: return [3 /*break*/, 13];
982
990
  case 11:
983
- e_9_1 = _l.sent();
984
- e_9 = { error: e_9_1 };
991
+ e_8_1 = _m.sent();
992
+ e_8 = { error: e_8_1 };
985
993
  return [3 /*break*/, 13];
986
994
  case 12:
987
995
  try {
988
996
  if (_e && !_e.done && (_h = _d.return)) _h.call(_d);
989
997
  }
990
- finally { if (e_9) throw e_9.error; }
998
+ finally { if (e_8) throw e_8.error; }
991
999
  return [7 /*endfinally*/];
992
1000
  case 13:
993
1001
  if (options.limit) {
@@ -998,13 +1006,13 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
998
1006
  page = 1;
999
1007
  select += ' ' + limitSyntax(options.limit, (page - 1) * options.limit);
1000
1008
  }
1001
- _l.label = 14;
1009
+ _m.label = 14;
1002
1010
  case 14: return [2 /*return*/, {
1003
1011
  select: select,
1004
1012
  colKeys: colKeys,
1005
1013
  /** `valueAt` reads one column of a result row, by its position in the select or by its alias (the field key). */
1006
1014
  toResult: function (valueAt) {
1007
- return resultRow(colKeys, valueAt);
1015
+ return resultRow(colKeys, valueAt, jsonColumnStorage);
1008
1016
  },
1009
1017
  }];
1010
1018
  }
@@ -1013,8 +1021,8 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
1013
1021
  }
1014
1022
  function selectColumns(entity, e, r, selectedFields, args, aliasColumns) {
1015
1023
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1016
- var select, colKeys, _a, _b, x, sql, e_8_1;
1017
- var e_8, _c;
1024
+ var select, colKeys, _a, _b, x, sql, e_7_1;
1025
+ var e_7, _c;
1018
1026
  return tslib_1.__generator(this, function (_d) {
1019
1027
  switch (_d.label) {
1020
1028
  case 0:
@@ -1059,25 +1067,25 @@ function selectColumns(entity, e, r, selectedFields, args, aliasColumns) {
1059
1067
  return [3 /*break*/, 2];
1060
1068
  case 8: return [3 /*break*/, 11];
1061
1069
  case 9:
1062
- e_8_1 = _d.sent();
1063
- e_8 = { error: e_8_1 };
1070
+ e_7_1 = _d.sent();
1071
+ e_7 = { error: e_7_1 };
1064
1072
  return [3 /*break*/, 11];
1065
1073
  case 10:
1066
1074
  try {
1067
1075
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1068
1076
  }
1069
- finally { if (e_8) throw e_8.error; }
1077
+ finally { if (e_7) throw e_7.error; }
1070
1078
  return [7 /*endfinally*/];
1071
1079
  case 11: return [2 /*return*/, { colKeys: colKeys, select: select }];
1072
1080
  }
1073
1081
  });
1074
1082
  });
1075
1083
  }
1076
- function resultRow(colKeys, valueAt) {
1084
+ function resultRow(colKeys, valueAt, storage) {
1077
1085
  var result = {};
1078
1086
  colKeys.forEach(function (col, index) {
1079
1087
  try {
1080
- result[col.key] = col.valueConverter.fromDb(valueAt(index, col.key));
1088
+ result[col.key] = (0, valueConverters_js_1.fromDbColumn)(col, valueAt(index, col.key), storage);
1081
1089
  }
1082
1090
  catch (err) {
1083
1091
  throw new Error('Failed to load from db:' + col.key + '\r\n' + err);
@@ -1085,12 +1093,13 @@ function resultRow(colKeys, valueAt) {
1085
1093
  });
1086
1094
  return result;
1087
1095
  }
1088
- function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
1089
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1096
+ function groupByImpl(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1) {
1097
+ return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r, orderByNullFirst, limitSyntax, jsonColumnStorage) {
1090
1098
  var _a, select, toResult, result;
1099
+ if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
1091
1100
  return tslib_1.__generator(this, function (_b) {
1092
1101
  switch (_b.label) {
1093
- case 0: return [4 /*yield*/, buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax)];
1102
+ case 0: return [4 /*yield*/, buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax, jsonColumnStorage)];
1094
1103
  case 1:
1095
1104
  _a = _b.sent(), select = _a.select, toResult = _a.toResult;
1096
1105
  return [4 /*yield*/, r.execute(select)];
@@ -1104,8 +1113,8 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
1104
1113
  });
1105
1114
  }
1106
1115
  /** The select that `groupBy` runs, and the mapping of one result row back to a `GroupByResult`. Every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
1107
- function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1108
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1116
+ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1) {
1117
+ return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r, orderByNullFirst, limitSyntax, jsonColumnStorage) {
1109
1118
  function alias(name) {
1110
1119
  aliases.push(name);
1111
1120
  return e.wrapIdentifier(name);
@@ -1117,6 +1126,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1117
1126
  }
1118
1127
  var aliases, select, groupBy, groupByCols, processResultRow, _loop_2, _a, _b, x, _loop_3, GroupByOperators_1, GroupByOperators_1_1, operator, e_10_1, where, _c, orderBy, _d, _e, x, field, _f, e_11_1, page;
1119
1128
  var e_12, _g, e_10, _h, e_11, _j;
1129
+ if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
1120
1130
  return tslib_1.__generator(this, function (_k) {
1121
1131
  switch (_k.label) {
1122
1132
  case 0:
@@ -1142,7 +1152,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1142
1152
  groupByCols.push(e.$dbNameOf(x));
1143
1153
  }
1144
1154
  processResultRow.push(function (sqlResult, theResult) {
1145
- theResult[x.key] = x.valueConverter.fromDb(sqlResult);
1155
+ theResult[x.key] = (0, valueConverters_js_1.fromDbColumn)(x, sqlResult, jsonColumnStorage);
1146
1156
  });
1147
1157
  };
1148
1158
  try {
@@ -1186,7 +1196,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1186
1196
  if (turnToNumber)
1187
1197
  sqlResult = Number(sqlResult);
1188
1198
  if (operator === 'max' || operator === 'min')
1189
- sqlResult = x.valueConverter.fromDb(sqlResult);
1199
+ sqlResult = (0, valueConverters_js_1.fromDbColumn)(x, sqlResult, jsonColumnStorage);
1190
1200
  theResult[x.key] = tslib_1.__assign(tslib_1.__assign({}, theResult[x.key]), (_a = {}, _a[operator] = sqlResult, _a));
1191
1201
  });
1192
1202
  return [2 /*return*/];
@@ -1252,7 +1262,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1252
1262
  case 8:
1253
1263
  select += '\n from ' + e.$entityName;
1254
1264
  if (!(options === null || options === void 0 ? void 0 : options.where)) return [3 /*break*/, 10];
1255
- where = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
1265
+ where = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e, jsonColumnStorage);
1256
1266
  options === null || options === void 0 ? void 0 : options.where.__applyToConsumer(where);
1257
1267
  _c = select;
1258
1268
  return [4 /*yield*/, where.resolveWhere()];
@@ -1,16 +1,19 @@
1
1
  import type { FieldMetadata } from '../column-interfaces.js';
2
2
  import type { EntityMetadataOverloads, RepositoryOverloads } from '../remult3/RepositoryImplementation.js';
3
3
  import type { EntityFilter, EntityMetadata, MembersOnly } from '../remult3/remult3.js';
4
- import type { HasWrapIdentifier, SqlCommandWithParameters } from '../sql-command.js';
4
+ import type { HasWrapIdentifier, JsonColumnStorage, SqlCommandWithParameters } from '../sql-command.js';
5
5
  import type { Filter, FilterConsumer } from './filter-interfaces.js';
6
+ export declare const LIKE_ESCAPE_SQL = " escape '!'";
7
+ export declare function escapeLike(val: string): string;
6
8
  export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer {
7
9
  private r;
8
10
  private nameProvider;
11
+ private jsonColumnStorage;
9
12
  private where;
10
13
  _addWhere: boolean;
11
14
  promises: Promise<void>[];
12
15
  resolveWhere(): Promise<string>;
13
- constructor(r: SqlCommandWithParameters, nameProvider: EntityDbNamesBase);
16
+ constructor(r: SqlCommandWithParameters, nameProvider: EntityDbNamesBase, jsonColumnStorage?: JsonColumnStorage);
14
17
  custom(key: string, customItem: any): void;
15
18
  or(orElements: Filter[]): void;
16
19
  not(element: Filter): void;
@@ -27,6 +30,7 @@ export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer
27
30
  notContainsCaseInsensitive(col: FieldMetadata, val: any): void;
28
31
  startsWithCaseInsensitive(col: FieldMetadata, val: any): void;
29
32
  endsWithCaseInsensitive(col: FieldMetadata, val: any): void;
33
+ private like;
30
34
  private add;
31
35
  private addToWhere;
32
36
  databaseCustom(databaseCustom: CustomSqlFilterObject): void;
@@ -47,7 +51,8 @@ export type CustomSqlFilterBuilderFunction = (builder: CustomSqlFilterBuilder) =
47
51
  export declare class CustomSqlFilterBuilder implements SqlCommandWithParameters, HasWrapIdentifier {
48
52
  private r;
49
53
  wrapIdentifier: (name: string) => string;
50
- constructor(r: SqlCommandWithParameters, wrapIdentifier: (name: string) => string);
54
+ private jsonColumnStorage;
55
+ constructor(r: SqlCommandWithParameters, wrapIdentifier: (name: string) => string, jsonColumnStorage?: JsonColumnStorage);
51
56
  sql: string;
52
57
  /** @deprecated use `param` instead*/
53
58
  addParameterAndReturnSqlToken(val: any): string;