remult 3.4.0-next.7 → 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, defaultOrderBy: false }]))];
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
  });
@@ -548,7 +541,9 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
548
541
  case 1:
549
542
  e = _b.sent();
550
543
  r = this.sql.createCommand();
551
- return [4 /*yield*/, buildFindSql(this.entity, options, e, r, this.sql._getSourceSql().orderByNullsFirst, function (limit, offset) { return _this.strategy.getLimitSqlSyntax(limit, offset); })];
544
+ if (options && !options.orderBy)
545
+ options.orderBy = sort_js_1.Sort.createUniqueSort(this.entity, new sort_js_1.Sort());
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 })];
552
547
  case 2:
553
548
  _a = _b.sent(), select = _a.select, toResult = _a.toResult;
554
549
  return [4 /*yield*/, r.execute(select)];
@@ -562,7 +557,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
562
557
  });
563
558
  };
564
559
  ActualSQLEntityDataProvider.prototype.buildResultRow = function (colKeys, y, r) {
565
- return resultRow(colKeys, function (i) { return y[r.getColumnKeyInResultForIndexInSelect(i)]; });
560
+ return resultRow(colKeys, function (i) { return y[r.getColumnKeyInResultForIndexInSelect(i)]; }, this.sql.jsonColumnStorage);
566
561
  };
567
562
  ActualSQLEntityDataProvider.prototype.buildSelect = function (e, r, selectedFields, args) {
568
563
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -574,7 +569,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
574
569
  ActualSQLEntityDataProvider.prototype.update = function (id, data, options) {
575
570
  return tslib_1.__awaiter(this, void 0, void 0, function () {
576
571
  var e, r, statement, added, _a, _b, x, v, idFilter, f, _c, _d, colKeys, select, returning;
577
- var e_4, _e;
572
+ var e_3, _e;
578
573
  var _this = this;
579
574
  return tslib_1.__generator(this, function (_f) {
580
575
  switch (_f.label) {
@@ -590,7 +585,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
590
585
  if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e)) {
591
586
  }
592
587
  else if (data[x.key] !== undefined) {
593
- v = x.valueConverter.toDb(data[x.key]);
588
+ v = (0, valueConverters_js_1.toDbColumn)(x, data[x.key], this.sql.jsonColumnStorage);
594
589
  if (v !== undefined) {
595
590
  if (!added)
596
591
  added = true;
@@ -601,15 +596,15 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
601
596
  }
602
597
  }
603
598
  }
604
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
599
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
605
600
  finally {
606
601
  try {
607
602
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
608
603
  }
609
- finally { if (e_4) throw e_4.error; }
604
+ finally { if (e_3) throw e_3.error; }
610
605
  }
611
606
  idFilter = this.entity.idMetadata.getIdFilter(id);
612
- 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);
613
608
  filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, idFilter).__applyToConsumer(f);
614
609
  _c = statement;
615
610
  return [4 /*yield*/, f.resolveWhere()];
@@ -661,7 +656,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
661
656
  case 1:
662
657
  e = _c.sent();
663
658
  r = this.sql.createCommand();
664
- 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);
665
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);
666
661
  statement = 'delete from ' + e.$entityName;
667
662
  _a = statement;
@@ -678,8 +673,8 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
678
673
  };
679
674
  ActualSQLEntityDataProvider.prototype.insert = function (data, options) {
680
675
  return tslib_1.__awaiter(this, void 0, void 0, function () {
681
- var e, maxParams, batches, result, batches_1, batches_1_1, batch, _a, _b, _c, _d, e_5_1;
682
- 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;
683
678
  var _this = this;
684
679
  var _f;
685
680
  return tslib_1.__generator(this, function (_g) {
@@ -691,7 +686,9 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
691
686
  case 1:
692
687
  e = _g.sent();
693
688
  maxParams = (_f = this.strategy.maxParametersInOneSqlStatement) !== null && _f !== void 0 ? _f : defaultMaxParametersInOneSqlStatement;
694
- 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);
695
692
  result = [];
696
693
  _g.label = 2;
697
694
  case 2:
@@ -713,14 +710,14 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
713
710
  return [3 /*break*/, 3];
714
711
  case 6: return [3 /*break*/, 9];
715
712
  case 7:
716
- e_5_1 = _g.sent();
717
- e_5 = { error: e_5_1 };
713
+ e_4_1 = _g.sent();
714
+ e_4 = { error: e_4_1 };
718
715
  return [3 /*break*/, 9];
719
716
  case 8:
720
717
  try {
721
718
  if (batches_1_1 && !batches_1_1.done && (_e = batches_1.return)) _e.call(batches_1);
722
719
  }
723
- finally { if (e_5) throw e_5.error; }
720
+ finally { if (e_4) throw e_4.error; }
724
721
  return [7 /*endfinally*/];
725
722
  case 9: return [2 /*return*/, result];
726
723
  }
@@ -741,7 +738,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
741
738
  ActualSQLEntityDataProvider.prototype.insertBatch = function (batch, e, options) {
742
739
  return tslib_1.__awaiter(this, void 0, void 0, function () {
743
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;
744
- var e_6, _d;
741
+ var e_5, _d;
745
742
  var _this = this;
746
743
  var _e;
747
744
  return tslib_1.__generator(this, function (_f) {
@@ -752,7 +749,9 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
752
749
  _loop_1 = function (x) {
753
750
  if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e))
754
751
  return "continue";
755
- 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
+ }))
756
755
  cols.push(x);
757
756
  };
758
757
  try {
@@ -761,12 +760,12 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
761
760
  _loop_1(x);
762
761
  }
763
762
  }
764
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
763
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
765
764
  finally {
766
765
  try {
767
766
  if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
768
767
  }
769
- finally { if (e_6) throw e_6.error; }
768
+ finally { if (e_5) throw e_5.error; }
770
769
  }
771
770
  colSql = '';
772
771
  vals = '';
@@ -783,7 +782,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
783
782
  if (j)
784
783
  vals += ', ';
785
784
  x = cols[j];
786
- v = x.valueConverter.toDb(batch[i][x.key]);
785
+ v = (0, valueConverters_js_1.toDbColumn)(x, batch[i][x.key], this.sql.jsonColumnStorage);
787
786
  if (v != undefined)
788
787
  vals += (0, filter_consumer_bridge_to_sql_request_js_1.toDbSql)(r, x, v);
789
788
  else if (x.allowNull)
@@ -859,6 +858,17 @@ function wrapIdentifierOf(r) {
859
858
  return (_a = dp.wrapIdentifier) === null || _a === void 0 ? void 0 : _a.bind(dp);
860
859
  return undefined;
861
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
+ }
862
872
  function limitSyntaxRequired() {
863
873
  throw new Error('A raw select with a limit needs limitSyntax, for example SqlDatabase.getDb()._getSourceSql().getLimitSqlSyntax');
864
874
  }
@@ -890,7 +900,7 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
890
900
  return dataProvider
891
901
  .find({
892
902
  where: new filter_interfaces_js_1.Filter(function (x) {
893
- var e_7, _a;
903
+ var e_6, _a;
894
904
  var _b;
895
905
  try {
896
906
  for (var _c = tslib_1.__values(meta.idMetadata.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -898,12 +908,12 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
898
908
  x.isEqualTo(field, (_b = data[field.key]) !== null && _b !== void 0 ? _b : idFilter[field.key]);
899
909
  }
900
910
  }
901
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
911
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
902
912
  finally {
903
913
  try {
904
914
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
905
915
  }
906
- finally { if (e_7) throw e_7.error; }
916
+ finally { if (e_6) throw e_6.error; }
907
917
  }
908
918
  }),
909
919
  })
@@ -914,11 +924,11 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
914
924
  });
915
925
  }
916
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. */
917
- 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) {
918
928
  return tslib_1.__awaiter(this, arguments, void 0, function (entity, options, e, r, orderByNullsFirst, limitSyntax, _a) {
919
- var _b, colKeys, columns, select, where, _c, first, _d, _e, c, _f, _g, e_9_1, page;
920
- var e_9, _h;
921
- var _j = _a === void 0 ? {} : _a, _k = _j.aliasColumns, aliasColumns = _k === void 0 ? false : _k, _l = _j.defaultOrderBy, defaultOrderBy = _l === void 0 ? true : _l;
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;
922
932
  return tslib_1.__generator(this, function (_m) {
923
933
  switch (_m.label) {
924
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,7 +937,7 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
927
937
  select = 'select ' + columns + '\n from ' + e.$entityName;
928
938
  if (!options) return [3 /*break*/, 14];
929
939
  if (!options.where) return [3 /*break*/, 3];
930
- 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);
931
941
  options.where.__applyToConsumer(where);
932
942
  _c = select;
933
943
  return [4 /*yield*/, where.resolveWhere()];
@@ -938,9 +948,6 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
938
948
  if (options.limit) {
939
949
  options.orderBy = sort_js_1.Sort.createUniqueSort(entity, options.orderBy);
940
950
  }
941
- if (!options.orderBy && defaultOrderBy) {
942
- options.orderBy = sort_js_1.Sort.createUniqueSort(entity, new sort_js_1.Sort());
943
- }
944
951
  if (!options.orderBy) return [3 /*break*/, 13];
945
952
  first = true;
946
953
  _m.label = 4;
@@ -981,14 +988,14 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
981
988
  return [3 /*break*/, 5];
982
989
  case 10: return [3 /*break*/, 13];
983
990
  case 11:
984
- e_9_1 = _m.sent();
985
- e_9 = { error: e_9_1 };
991
+ e_8_1 = _m.sent();
992
+ e_8 = { error: e_8_1 };
986
993
  return [3 /*break*/, 13];
987
994
  case 12:
988
995
  try {
989
996
  if (_e && !_e.done && (_h = _d.return)) _h.call(_d);
990
997
  }
991
- finally { if (e_9) throw e_9.error; }
998
+ finally { if (e_8) throw e_8.error; }
992
999
  return [7 /*endfinally*/];
993
1000
  case 13:
994
1001
  if (options.limit) {
@@ -1005,7 +1012,7 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
1005
1012
  colKeys: colKeys,
1006
1013
  /** `valueAt` reads one column of a result row, by its position in the select or by its alias (the field key). */
1007
1014
  toResult: function (valueAt) {
1008
- return resultRow(colKeys, valueAt);
1015
+ return resultRow(colKeys, valueAt, jsonColumnStorage);
1009
1016
  },
1010
1017
  }];
1011
1018
  }
@@ -1014,8 +1021,8 @@ function buildFindSql(entity_1, options_1, e_8, r_1, orderByNullsFirst_1, limitS
1014
1021
  }
1015
1022
  function selectColumns(entity, e, r, selectedFields, args, aliasColumns) {
1016
1023
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1017
- var select, colKeys, _a, _b, x, sql, e_8_1;
1018
- var e_8, _c;
1024
+ var select, colKeys, _a, _b, x, sql, e_7_1;
1025
+ var e_7, _c;
1019
1026
  return tslib_1.__generator(this, function (_d) {
1020
1027
  switch (_d.label) {
1021
1028
  case 0:
@@ -1060,25 +1067,25 @@ function selectColumns(entity, e, r, selectedFields, args, aliasColumns) {
1060
1067
  return [3 /*break*/, 2];
1061
1068
  case 8: return [3 /*break*/, 11];
1062
1069
  case 9:
1063
- e_8_1 = _d.sent();
1064
- e_8 = { error: e_8_1 };
1070
+ e_7_1 = _d.sent();
1071
+ e_7 = { error: e_7_1 };
1065
1072
  return [3 /*break*/, 11];
1066
1073
  case 10:
1067
1074
  try {
1068
1075
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1069
1076
  }
1070
- finally { if (e_8) throw e_8.error; }
1077
+ finally { if (e_7) throw e_7.error; }
1071
1078
  return [7 /*endfinally*/];
1072
1079
  case 11: return [2 /*return*/, { colKeys: colKeys, select: select }];
1073
1080
  }
1074
1081
  });
1075
1082
  });
1076
1083
  }
1077
- function resultRow(colKeys, valueAt) {
1084
+ function resultRow(colKeys, valueAt, storage) {
1078
1085
  var result = {};
1079
1086
  colKeys.forEach(function (col, index) {
1080
1087
  try {
1081
- 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);
1082
1089
  }
1083
1090
  catch (err) {
1084
1091
  throw new Error('Failed to load from db:' + col.key + '\r\n' + err);
@@ -1086,12 +1093,13 @@ function resultRow(colKeys, valueAt) {
1086
1093
  });
1087
1094
  return result;
1088
1095
  }
1089
- function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
1090
- 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) {
1091
1098
  var _a, select, toResult, result;
1099
+ if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
1092
1100
  return tslib_1.__generator(this, function (_b) {
1093
1101
  switch (_b.label) {
1094
- case 0: return [4 /*yield*/, buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax)];
1102
+ case 0: return [4 /*yield*/, buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax, jsonColumnStorage)];
1095
1103
  case 1:
1096
1104
  _a = _b.sent(), select = _a.select, toResult = _a.toResult;
1097
1105
  return [4 /*yield*/, r.execute(select)];
@@ -1105,8 +1113,8 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
1105
1113
  });
1106
1114
  }
1107
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. */
1108
- function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1109
- 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) {
1110
1118
  function alias(name) {
1111
1119
  aliases.push(name);
1112
1120
  return e.wrapIdentifier(name);
@@ -1118,6 +1126,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1118
1126
  }
1119
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;
1120
1128
  var e_12, _g, e_10, _h, e_11, _j;
1129
+ if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
1121
1130
  return tslib_1.__generator(this, function (_k) {
1122
1131
  switch (_k.label) {
1123
1132
  case 0:
@@ -1143,7 +1152,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1143
1152
  groupByCols.push(e.$dbNameOf(x));
1144
1153
  }
1145
1154
  processResultRow.push(function (sqlResult, theResult) {
1146
- theResult[x.key] = x.valueConverter.fromDb(sqlResult);
1155
+ theResult[x.key] = (0, valueConverters_js_1.fromDbColumn)(x, sqlResult, jsonColumnStorage);
1147
1156
  });
1148
1157
  };
1149
1158
  try {
@@ -1187,7 +1196,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1187
1196
  if (turnToNumber)
1188
1197
  sqlResult = Number(sqlResult);
1189
1198
  if (operator === 'max' || operator === 'min')
1190
- sqlResult = x.valueConverter.fromDb(sqlResult);
1199
+ sqlResult = (0, valueConverters_js_1.fromDbColumn)(x, sqlResult, jsonColumnStorage);
1191
1200
  theResult[x.key] = tslib_1.__assign(tslib_1.__assign({}, theResult[x.key]), (_a = {}, _a[operator] = sqlResult, _a));
1192
1201
  });
1193
1202
  return [2 /*return*/];
@@ -1253,7 +1262,7 @@ function buildGroupBySql(options, e, r, orderByNullFirst, limitSyntax) {
1253
1262
  case 8:
1254
1263
  select += '\n from ' + e.$entityName;
1255
1264
  if (!(options === null || options === void 0 ? void 0 : options.where)) return [3 /*break*/, 10];
1256
- 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);
1257
1266
  options === null || options === void 0 ? void 0 : options.where.__applyToConsumer(where);
1258
1267
  _c = select;
1259
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;