@sqb/connect 4.14.1 → 4.15.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.
Files changed (47) hide show
  1. package/esm/client/adapter.js +2 -1
  2. package/esm/client/cursor-stream.js +9 -4
  3. package/esm/client/cursor.js +22 -17
  4. package/esm/client/extensions.js +5 -1
  5. package/esm/client/field-info-map.js +5 -1
  6. package/esm/client/helpers.js +19 -12
  7. package/esm/client/sqb-client.js +32 -27
  8. package/esm/client/sqb-connection.js +41 -36
  9. package/esm/client/types.js +5 -1
  10. package/esm/index.js +40 -32
  11. package/esm/orm/backward.js +19 -12
  12. package/esm/orm/base-entity.js +10 -6
  13. package/esm/orm/commands/command.helper.js +34 -28
  14. package/esm/orm/commands/count.command.js +10 -6
  15. package/esm/orm/commands/create.command.js +18 -14
  16. package/esm/orm/commands/delete.command.js +10 -6
  17. package/esm/orm/commands/find.command.js +34 -30
  18. package/esm/orm/commands/row-converter.js +7 -3
  19. package/esm/orm/commands/update.command.js +18 -14
  20. package/esm/orm/decorators/column.decorator.js +10 -7
  21. package/esm/orm/decorators/embedded.decorator.js +7 -4
  22. package/esm/orm/decorators/entity.decorator.js +56 -53
  23. package/esm/orm/decorators/events.decorator.js +27 -19
  24. package/esm/orm/decorators/foreignkey.decorator.js +7 -4
  25. package/esm/orm/decorators/index.decorator.js +9 -6
  26. package/esm/orm/decorators/link.decorator.js +11 -8
  27. package/esm/orm/decorators/primarykey.decorator.js +11 -8
  28. package/esm/orm/decorators/transform.decorator.js +11 -7
  29. package/esm/orm/model/association-field-metadata.js +8 -4
  30. package/esm/orm/model/association-node.js +6 -2
  31. package/esm/orm/model/association.js +20 -16
  32. package/esm/orm/model/column-field-metadata.js +8 -4
  33. package/esm/orm/model/embedded-field-metadata.js +7 -4
  34. package/esm/orm/model/entity-metadata.js +50 -47
  35. package/esm/orm/model/field-metadata.js +2 -1
  36. package/esm/orm/model/index-metadata.js +2 -1
  37. package/esm/orm/model/link-chain.js +8 -4
  38. package/esm/orm/orm.const.js +6 -3
  39. package/esm/orm/orm.type.js +2 -1
  40. package/esm/orm/repository.class.js +26 -22
  41. package/esm/orm/util/apply-mixins.js +4 -1
  42. package/esm/orm/util/extract-keyvalues.js +9 -6
  43. package/esm/orm/util/orm.helper.js +20 -10
  44. package/esm/orm/util/parse-fields-projection.js +11 -6
  45. package/esm/orm/util/serialize-field.js +13 -10
  46. package/package.json +28 -22
  47. package/cjs/package.json +0 -3
@@ -1,16 +1,22 @@
1
- import { And, Eq, Exists, Field, InnerJoin, isCompOperator, isLogicalOperator, LeftOuterJoin, op, OperatorType, Raw, Select, } from '@sqb/builder';
2
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
3
- import { EntityMetadata } from '../model/entity-metadata.js';
4
- import { isAssociationField, isColumnField, isEmbeddedField } from '../util/orm.helper.js';
5
- export async function joinAssociationGetFirst(joinInfos, association, parentAlias, innerJoin) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinAssociationGetFirst = joinAssociationGetFirst;
4
+ exports.joinAssociationGetLast = joinAssociationGetLast;
5
+ exports.joinAssociation = joinAssociation;
6
+ exports.prepareFilter = prepareFilter;
7
+ const builder_1 = require("@sqb/builder");
8
+ const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
9
+ const entity_metadata_js_1 = require("../model/entity-metadata.js");
10
+ const orm_helper_js_1 = require("../util/orm.helper.js");
11
+ async function joinAssociationGetFirst(joinInfos, association, parentAlias, innerJoin) {
6
12
  const joins = await joinAssociation(joinInfos, association, parentAlias, innerJoin);
7
13
  return joins[0];
8
14
  }
9
- export async function joinAssociationGetLast(joinInfos, association, parentAlias, innerJoin) {
15
+ async function joinAssociationGetLast(joinInfos, association, parentAlias, innerJoin) {
10
16
  const joins = await joinAssociation(joinInfos, association, parentAlias, innerJoin);
11
17
  return joins[joins.length - 1];
12
18
  }
13
- export async function joinAssociation(joinInfos, association, parentAlias, innerJoin) {
19
+ async function joinAssociation(joinInfos, association, parentAlias, innerJoin) {
14
20
  let joinInfo;
15
21
  let node = association;
16
22
  const result = [];
@@ -23,9 +29,9 @@ export async function joinAssociation(joinInfos, association, parentAlias, inner
23
29
  const targetCol = await node.resolveTargetProperty();
24
30
  const joinAlias = 'J' + (joinInfos.length + 1);
25
31
  const join = innerJoin
26
- ? InnerJoin(targetEntity.tableName + ' as ' + joinAlias)
27
- : LeftOuterJoin(targetEntity.tableName + ' as ' + joinAlias);
28
- join.on(Eq(Field(joinAlias + '.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), Field(parentAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
32
+ ? (0, builder_1.InnerJoin)(targetEntity.tableName + ' as ' + joinAlias)
33
+ : (0, builder_1.LeftOuterJoin)(targetEntity.tableName + ' as ' + joinAlias);
34
+ join.on((0, builder_1.Eq)((0, builder_1.Field)(joinAlias + '.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), (0, builder_1.Field)(parentAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
29
35
  if (node.conditions)
30
36
  await prepareFilter(targetEntity, node.conditions, join._conditions, joinAlias);
31
37
  joinInfo = {
@@ -45,12 +51,12 @@ export async function joinAssociation(joinInfos, association, parentAlias, inner
45
51
  }
46
52
  return result;
47
53
  }
48
- export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
54
+ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
49
55
  let srcOp;
50
- if (isLogicalOperator(filter) && filter._operatorType === trgOp._operatorType)
56
+ if ((0, builder_1.isLogicalOperator)(filter) && filter._operatorType === trgOp._operatorType)
51
57
  srcOp = filter;
52
58
  else {
53
- srcOp = And();
59
+ srcOp = (0, builder_1.And)();
54
60
  if (Array.isArray(filter))
55
61
  srcOp.add(...filter);
56
62
  else
@@ -58,14 +64,14 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
58
64
  }
59
65
  const associationPathCache = {};
60
66
  for (const item of srcOp._items) {
61
- if (isLogicalOperator(item)) {
67
+ if ((0, builder_1.isLogicalOperator)(item)) {
62
68
  const ctor = Object.getPrototypeOf(item).constructor;
63
69
  const logOp = new ctor();
64
70
  await prepareFilter(entityDef, item, logOp, tableAlias);
65
71
  trgOp.add(logOp);
66
72
  continue;
67
73
  }
68
- if (isCompOperator(item)) {
74
+ if ((0, builder_1.isCompOperator)(item)) {
69
75
  if (typeof item._left === 'string') {
70
76
  const itemPath = item._left.split('.');
71
77
  const l = itemPath.length;
@@ -91,38 +97,38 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
91
97
  }
92
98
  for (i; i < l; i++) {
93
99
  pt = itemPath[i];
94
- const col = EntityMetadata.getField(_curEntity, pt);
100
+ const col = entity_metadata_js_1.EntityMetadata.getField(_curEntity, pt);
95
101
  if (!col)
96
102
  throw new Error(`Unknown property (${item._left}) defined in filter`);
97
103
  /** if last item on path */
98
104
  if (i === l - 1) {
99
- if (!isColumnField(col))
105
+ if (!(0, orm_helper_js_1.isColumnField)(col))
100
106
  throw new Error(`Invalid column expression (${item._left}) defined in filter`);
101
107
  const ctor = Object.getPrototypeOf(item).constructor;
102
- currentOp.add(new ctor(Field(_curAlias + '.' + _curPrefix + col.fieldName + _curSuffix, col.dataType, col.isArray), item._right));
108
+ currentOp.add(new ctor((0, builder_1.Field)(_curAlias + '.' + _curPrefix + col.fieldName + _curSuffix, col.dataType, col.isArray), item._right));
103
109
  }
104
110
  else {
105
111
  /** if not last item on path */
106
- if (isColumnField(col))
112
+ if ((0, orm_helper_js_1.isColumnField)(col))
107
113
  throw new Error(`Invalid column (${item._left}) defined in filter`);
108
- if (isEmbeddedField(col)) {
109
- _curEntity = await EmbeddedFieldMetadata.resolveType(col);
114
+ if ((0, orm_helper_js_1.isEmbeddedField)(col)) {
115
+ _curEntity = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
110
116
  _curPrefix = _curPrefix + (col.fieldNamePrefix || '');
111
117
  _curSuffix = (col.fieldNameSuffix || '') + _curSuffix;
112
118
  continue;
113
119
  }
114
- if (!isAssociationField(col))
120
+ if (!(0, orm_helper_js_1.isAssociationField)(col))
115
121
  throw new Error(`Invalid column (${item._left}) defined in filter`);
116
122
  let node;
117
123
  _curEntity = await col.association.resolveTarget();
118
124
  if (!subSelect) {
119
125
  const keyCol = await col.association.resolveSourceProperty();
120
126
  const targetCol = await col.association.resolveTargetProperty();
121
- subSelect = Select(Raw('1')).from(_curEntity.tableName + ' K');
122
- subSelect.where(Eq(Field('K.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), Field(tableAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
123
- currentOp.add(Exists(subSelect));
124
- if (currentOp._operatorType !== OperatorType.and) {
125
- currentOp = op.or();
127
+ subSelect = (0, builder_1.Select)((0, builder_1.Raw)('1')).from(_curEntity.tableName + ' K');
128
+ subSelect.where((0, builder_1.Eq)((0, builder_1.Field)('K.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), (0, builder_1.Field)(tableAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
129
+ currentOp.add((0, builder_1.Exists)(subSelect));
130
+ if (currentOp._operatorType !== builder_1.OperatorType.and) {
131
+ currentOp = builder_1.op.or();
126
132
  subSelect.where(currentOp);
127
133
  }
128
134
  else
@@ -140,7 +146,7 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
140
146
  const sourceColumn = await node.resolveSourceProperty();
141
147
  const targetColumn = await node.resolveTargetProperty();
142
148
  const joinAlias = 'J' + ((subSelect?._joins?.length || 0) + 1);
143
- subSelect.join(InnerJoin(targetEntity.tableName + ' ' + joinAlias).on(Eq(Field(joinAlias + '.' + targetColumn.fieldName, targetColumn.dataType, targetColumn.isArray), Field(_curAlias + '.' + sourceColumn.fieldName, sourceColumn.dataType, sourceColumn.isArray))));
149
+ subSelect.join((0, builder_1.InnerJoin)(targetEntity.tableName + ' ' + joinAlias).on((0, builder_1.Eq)((0, builder_1.Field)(joinAlias + '.' + targetColumn.fieldName, targetColumn.dataType, targetColumn.isArray), (0, builder_1.Field)(_curAlias + '.' + sourceColumn.fieldName, sourceColumn.dataType, sourceColumn.isArray))));
144
150
  _curEntity = targetEntity;
145
151
  _curAlias = joinAlias;
146
152
  node = node.next;
@@ -1,6 +1,9 @@
1
- import { And, Count, Select } from '@sqb/builder';
2
- import { prepareFilter } from './command.helper.js';
3
- export class CountCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CountCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const command_helper_js_1 = require("./command.helper.js");
6
+ class CountCommand {
4
7
  // istanbul ignore next
5
8
  constructor() {
6
9
  throw new Error('This class is abstract');
@@ -9,10 +12,10 @@ export class CountCommand {
9
12
  const { connection, entity, filter, params } = args;
10
13
  let where;
11
14
  if (filter) {
12
- where = And();
13
- await prepareFilter(entity, filter, where, 'T');
15
+ where = (0, builder_1.And)();
16
+ await (0, command_helper_js_1.prepareFilter)(entity, filter, where, 'T');
14
17
  }
15
- const query = Select(Count()).from(entity.tableName + ' T');
18
+ const query = (0, builder_1.Select)((0, builder_1.Count)()).from(entity.tableName + ' T');
16
19
  if (where)
17
20
  query.where(where);
18
21
  // Execute query
@@ -24,3 +27,4 @@ export class CountCommand {
24
27
  return (resp && resp.rows && resp.rows[0][0]) || 0;
25
28
  }
26
29
  }
30
+ exports.CountCommand = CountCommand;
@@ -1,9 +1,12 @@
1
- import { Insert, Param } from '@sqb/builder';
2
- import { ColumnFieldMetadata } from '../model/column-field-metadata.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
- import { EntityMetadata } from '../model/entity-metadata.js';
5
- import { isColumnField, isEmbeddedField } from '../util/orm.helper.js';
6
- export class CreateCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const column_field_metadata_js_1 = require("../model/column-field-metadata.js");
6
+ const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
7
+ const entity_metadata_js_1 = require("../model/entity-metadata.js");
8
+ const orm_helper_js_1 = require("../util/orm.helper.js");
9
+ class CreateCommand {
7
10
  // istanbul ignore next
8
11
  constructor() {
9
12
  throw new Error('This class is abstract');
@@ -24,9 +27,9 @@ export class CreateCommand {
24
27
  await this._prepareParams(ctx, entity, args.values);
25
28
  if (!ctx.colCount)
26
29
  throw new Error('No field given to create new entity instance');
27
- const query = Insert(tableName, ctx.queryValues);
30
+ const query = (0, builder_1.Insert)(tableName, ctx.queryValues);
28
31
  if (args.returning) {
29
- const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(entity);
32
+ const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(entity);
30
33
  if (primaryIndexColumns.length)
31
34
  query.returning(...primaryIndexColumns.map(col => col.fieldName));
32
35
  }
@@ -38,7 +41,7 @@ export class CreateCommand {
38
41
  if (args.returning && qr.fields && qr.rows?.length) {
39
42
  const keyValues = {};
40
43
  for (const f of qr.fields.values()) {
41
- const el = EntityMetadata.getColumnFieldByFieldName(entity, f.fieldName);
44
+ const el = entity_metadata_js_1.EntityMetadata.getColumnFieldByFieldName(entity, f.fieldName);
42
45
  if (el)
43
46
  keyValues[el.name] = qr.rows[0][f.index];
44
47
  }
@@ -51,7 +54,7 @@ export class CreateCommand {
51
54
  suffix = suffix || '';
52
55
  for (const col of Object.values(entity.fields)) {
53
56
  v = values[col.name];
54
- if (isColumnField(col)) {
57
+ if ((0, orm_helper_js_1.isColumnField)(col)) {
55
58
  if (col.noInsert)
56
59
  continue;
57
60
  if (v == null && col.default !== undefined) {
@@ -65,10 +68,10 @@ export class CreateCommand {
65
68
  }
66
69
  continue;
67
70
  }
68
- ColumnFieldMetadata.checkEnumValue(col, v);
71
+ column_field_metadata_js_1.ColumnFieldMetadata.checkEnumValue(col, v);
69
72
  const fieldName = prefix + col.fieldName + suffix;
70
73
  const k = ('I$_' + fieldName).substring(0, 30);
71
- ctx.queryValues[fieldName] = Param({
74
+ ctx.queryValues[fieldName] = (0, builder_1.Param)({
72
75
  name: k,
73
76
  dataType: col.dataType,
74
77
  isArray: col.isArray,
@@ -76,10 +79,11 @@ export class CreateCommand {
76
79
  ctx.queryParams[k] = v;
77
80
  ctx.colCount++;
78
81
  }
79
- else if (v != null && isEmbeddedField(col)) {
80
- const type = await EmbeddedFieldMetadata.resolveType(col);
82
+ else if (v != null && (0, orm_helper_js_1.isEmbeddedField)(col)) {
83
+ const type = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
81
84
  await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
82
85
  }
83
86
  }
84
87
  }
85
88
  }
89
+ exports.CreateCommand = CreateCommand;
@@ -1,6 +1,9 @@
1
- import { And, Delete } from '@sqb/builder';
2
- import { prepareFilter } from './command.helper.js';
3
- export class DeleteCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeleteCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const command_helper_js_1 = require("./command.helper.js");
6
+ class DeleteCommand {
4
7
  // istanbul ignore next
5
8
  constructor() {
6
9
  throw new Error('This class is abstract');
@@ -9,10 +12,10 @@ export class DeleteCommand {
9
12
  const { connection, entity, filter, params } = args;
10
13
  let where;
11
14
  if (filter) {
12
- where = And();
13
- await prepareFilter(entity, filter, where);
15
+ where = (0, builder_1.And)();
16
+ await (0, command_helper_js_1.prepareFilter)(entity, filter, where);
14
17
  }
15
- const query = Delete(entity.tableName + ' T');
18
+ const query = (0, builder_1.Delete)(entity.tableName + ' T');
16
19
  if (where)
17
20
  query.where(...where._items);
18
21
  // Execute query
@@ -24,3 +27,4 @@ export class DeleteCommand {
24
27
  return (resp && resp.rowsAffected) || 0;
25
28
  }
26
29
  }
30
+ exports.DeleteCommand = DeleteCommand;
@@ -1,13 +1,16 @@
1
- import { And, In, Param, Select } from '@sqb/builder';
2
- import { AssociationNode } from '../model/association-node.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
- import { EntityMetadata } from '../model/entity-metadata.js';
5
- import { isAssociationField, isColumnField, isEmbeddedField } from '../util/orm.helper.js';
6
- import { parseFieldsProjection } from '../util/parse-fields-projection.js';
7
- import { joinAssociationGetLast, prepareFilter } from './command.helper.js';
8
- import { RowConverter } from './row-converter.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FindCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const association_node_js_1 = require("../model/association-node.js");
6
+ const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
7
+ const entity_metadata_js_1 = require("../model/entity-metadata.js");
8
+ const orm_helper_js_1 = require("../util/orm.helper.js");
9
+ const parse_fields_projection_js_1 = require("../util/parse-fields-projection.js");
10
+ const command_helper_js_1 = require("./command.helper.js");
11
+ const row_converter_js_1 = require("./row-converter.js");
9
12
  const SORT_ORDER_PATTERN = /^([-+])?(.*)$/;
10
- export class FindCommand {
13
+ class FindCommand {
11
14
  constructor(selectEntity, outputEntity) {
12
15
  this.maxEagerFetch = 100000;
13
16
  this.maxSubQueries = 5;
@@ -15,15 +18,15 @@ export class FindCommand {
15
18
  this.resultAlias = 'T';
16
19
  this._joins = [];
17
20
  this._selectColumns = {};
18
- this._filter = And();
21
+ this._filter = (0, builder_1.And)();
19
22
  this.mainEntity = selectEntity;
20
23
  this.resultEntity = outputEntity;
21
- this.converter = new RowConverter(outputEntity.ctor);
24
+ this.converter = new row_converter_js_1.RowConverter(outputEntity.ctor);
22
25
  }
23
26
  static async create(source, opts = {}) {
24
27
  let command;
25
28
  let listingEntity;
26
- if (source instanceof AssociationNode) {
29
+ if (source instanceof association_node_js_1.AssociationNode) {
27
30
  const node = source;
28
31
  listingEntity = await node.resolveTarget();
29
32
  const resultEntity = await node.getLast().resolveTarget();
@@ -31,7 +34,7 @@ export class FindCommand {
31
34
  if (node.conditions)
32
35
  await command.filter(node.conditions);
33
36
  if (node.next) {
34
- const join = await joinAssociationGetLast(command._joins, node.next, command.mainAlias);
37
+ const join = await (0, command_helper_js_1.joinAssociationGetLast)(command._joins, node.next, command.mainAlias);
35
38
  command.resultAlias = join.joinAlias;
36
39
  }
37
40
  }
@@ -67,14 +70,14 @@ export class FindCommand {
67
70
  const entity = opts.entity || this._getEntityFromAlias(tableAlias);
68
71
  const converter = opts.converter || this.converter;
69
72
  const projection = typeof opts.projection === 'string' || Array.isArray(opts.projection)
70
- ? parseFieldsProjection(opts.projection)
73
+ ? (0, parse_fields_projection_js_1.parseFieldsProjection)(opts.projection)
71
74
  : opts.projection;
72
75
  const defaultFields = !projection || !Object.values(projection).find(p => !p.sign);
73
76
  const sortFields = opts.sort && opts.sort.length ? opts.sort.map(x => x.toLowerCase()) : undefined;
74
77
  const prefix = opts.prefix || '';
75
78
  const suffix = opts.suffix || '';
76
79
  for (const key of Object.keys(entity.fields)) {
77
- const col = EntityMetadata.getField(entity, key);
80
+ const col = entity_metadata_js_1.EntityMetadata.getField(entity, key);
78
81
  if (!col || col.hidden)
79
82
  continue;
80
83
  const colNameLower = col.name.toLowerCase();
@@ -89,7 +92,7 @@ export class FindCommand {
89
92
  continue;
90
93
  }
91
94
  // Add field to select list if field is a column
92
- if (isColumnField(col)) {
95
+ if ((0, orm_helper_js_1.isColumnField)(col)) {
93
96
  const fieldAlias = this._selectColumn(tableAlias, col, prefix, suffix);
94
97
  // Add column to converter
95
98
  converter.addValueProperty({
@@ -100,8 +103,8 @@ export class FindCommand {
100
103
  });
101
104
  continue;
102
105
  }
103
- if (isEmbeddedField(col)) {
104
- const typ = await EmbeddedFieldMetadata.resolveType(col);
106
+ if ((0, orm_helper_js_1.isEmbeddedField)(col)) {
107
+ const typ = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
105
108
  const subConverter = converter.addObjectProperty({
106
109
  name: col.name,
107
110
  type: typ.ctor,
@@ -117,10 +120,10 @@ export class FindCommand {
117
120
  });
118
121
  continue;
119
122
  }
120
- if (isAssociationField(col)) {
123
+ if ((0, orm_helper_js_1.isAssociationField)(col)) {
121
124
  // OtO relation
122
125
  if (!col.association.returnsMany()) {
123
- const joinInfo = await joinAssociationGetLast(this._joins, col.association, tableAlias);
126
+ const joinInfo = await (0, command_helper_js_1.joinAssociationGetLast)(this._joins, col.association, tableAlias);
124
127
  const subConverter = converter.addObjectProperty({
125
128
  name: col.name,
126
129
  type: joinInfo.targetEntity.ctor,
@@ -147,7 +150,7 @@ export class FindCommand {
147
150
  maxEagerFetch: this.maxEagerFetch,
148
151
  });
149
152
  findCommand.converter.parent = this.converter;
150
- await findCommand.filter(In(targetCol.name, Param(parentField)));
153
+ await findCommand.filter((0, builder_1.In)(targetCol.name, (0, builder_1.Param)(parentField)));
151
154
  const sort = sortFields && extractSubFields(colNameLower, sortFields);
152
155
  await findCommand.addFields({
153
156
  projection: p?.projection,
@@ -179,7 +182,7 @@ export class FindCommand {
179
182
  return fieldAlias;
180
183
  }
181
184
  async filter(filter) {
182
- await prepareFilter(this.mainEntity, filter, this._filter);
185
+ await (0, command_helper_js_1.prepareFilter)(this.mainEntity, filter, this._filter);
183
186
  }
184
187
  async sort(sortFields) {
185
188
  const out = [];
@@ -195,20 +198,20 @@ export class FindCommand {
195
198
  if (elName.includes('.')) {
196
199
  const a = elName.split('.');
197
200
  while (a.length > 1) {
198
- const col = EntityMetadata.getField(_entityDef, a.shift() || '');
199
- if (isEmbeddedField(col)) {
200
- _entityDef = await EmbeddedFieldMetadata.resolveType(col);
201
+ const col = entity_metadata_js_1.EntityMetadata.getField(_entityDef, a.shift() || '');
202
+ if ((0, orm_helper_js_1.isEmbeddedField)(col)) {
203
+ _entityDef = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
201
204
  if (col.fieldNamePrefix)
202
205
  prefix += col.fieldNamePrefix;
203
206
  if (col.fieldNameSuffix)
204
207
  suffix = col.fieldNameSuffix + suffix;
205
208
  }
206
- else if (isAssociationField(col)) {
209
+ else if ((0, orm_helper_js_1.isAssociationField)(col)) {
207
210
  if (col.association.returnsMany()) {
208
211
  elName = '';
209
212
  break;
210
213
  }
211
- const joinInfo = await joinAssociationGetLast(this._joins, col.association, tableAlias);
214
+ const joinInfo = await (0, command_helper_js_1.joinAssociationGetLast)(this._joins, col.association, tableAlias);
212
215
  tableAlias = joinInfo.joinAlias;
213
216
  _entityDef = joinInfo.targetEntity;
214
217
  }
@@ -219,10 +222,10 @@ export class FindCommand {
219
222
  continue;
220
223
  elName = a.shift() || '';
221
224
  }
222
- const col = EntityMetadata.getField(_entityDef, elName);
225
+ const col = entity_metadata_js_1.EntityMetadata.getField(_entityDef, elName);
223
226
  if (!col)
224
227
  throw new Error(`Unknown field (${elName}) declared in sort property`);
225
- if (!isColumnField(col))
228
+ if (!(0, orm_helper_js_1.isColumnField)(col))
226
229
  throw new Error(`Can not sort by "${elName}", because it is not a data column`);
227
230
  const dir = m[1] || '+';
228
231
  out.push((dir || '') + tableAlias + '.' + prefix + col.fieldName + suffix);
@@ -234,7 +237,7 @@ export class FindCommand {
234
237
  const columnSqls = Object.keys(this._selectColumns).map(x => this._selectColumns[x].statement);
235
238
  if (!columnSqls.length)
236
239
  columnSqls.push('1');
237
- const query = Select(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
240
+ const query = (0, builder_1.Select)(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
238
241
  if (args.distinct)
239
242
  query.distinct();
240
243
  query.where(...this._filter._items);
@@ -276,6 +279,7 @@ export class FindCommand {
276
279
  throw new Error(`Unknown table alias "${tableAlias}"`);
277
280
  }
278
281
  }
282
+ exports.FindCommand = FindCommand;
279
283
  function extractSubFields(colNameLower, fields) {
280
284
  if (!(fields && fields.length))
281
285
  return;
@@ -1,8 +1,11 @@
1
- import { DataType } from '@sqb/builder';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RowConverter = void 0;
4
+ const builder_1 = require("@sqb/builder");
2
5
  const isValueProperty = (prop) => prop.fieldAlias && !prop.converter;
3
6
  const isObjectProperty = (prop) => prop.converter && !prop.findCommand;
4
7
  const isNestedProperty = (prop) => prop.converter && prop.findCommand;
5
- export class RowConverter {
8
+ class RowConverter {
6
9
  constructor(resultType, parent) {
7
10
  this.resultType = resultType;
8
11
  this.parent = parent;
@@ -81,7 +84,7 @@ export class RowConverter {
81
84
  v = prop.parse(v, elKey);
82
85
  if (v != null) {
83
86
  result = result || {};
84
- if (prop.dataType === DataType.JSON && typeof v === 'string')
87
+ if (prop.dataType === builder_1.DataType.JSON && typeof v === 'string')
85
88
  v = JSON.parse(v);
86
89
  result[elKey] = v;
87
90
  }
@@ -179,3 +182,4 @@ export class RowConverter {
179
182
  this.parent._checkCircularDep(t);
180
183
  }
181
184
  }
185
+ exports.RowConverter = RowConverter;
@@ -1,9 +1,12 @@
1
- import { And, Param, Update } from '@sqb/builder';
2
- import { ColumnFieldMetadata } from '../model/column-field-metadata.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
- import { isColumnField, isEmbeddedField } from '../util/orm.helper.js';
5
- import { prepareFilter } from './command.helper.js';
6
- export class UpdateCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const column_field_metadata_js_1 = require("../model/column-field-metadata.js");
6
+ const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
7
+ const orm_helper_js_1 = require("../util/orm.helper.js");
8
+ const command_helper_js_1 = require("./command.helper.js");
9
+ class UpdateCommand {
7
10
  // istanbul ignore next
8
11
  constructor() {
9
12
  throw new Error('This class is abstract');
@@ -27,7 +30,7 @@ export class UpdateCommand {
27
30
  return 0;
28
31
  if (args.filter)
29
32
  await this._prepareFilter(ctx, args.filter);
30
- const query = Update(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
33
+ const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
31
34
  const qr = await args.connection.execute(query, {
32
35
  params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
33
36
  objectRows: false,
@@ -37,8 +40,8 @@ export class UpdateCommand {
37
40
  }
38
41
  static async _prepareFilter(ctx, filter) {
39
42
  if (filter) {
40
- const where = And();
41
- await prepareFilter(ctx.entity, filter, where);
43
+ const where = (0, builder_1.And)();
44
+ await (0, command_helper_js_1.prepareFilter)(ctx.entity, filter, where);
42
45
  ctx.queryFilter.push(...where._items);
43
46
  }
44
47
  }
@@ -50,7 +53,7 @@ export class UpdateCommand {
50
53
  v = values[col.name];
51
54
  if (v === undefined)
52
55
  continue;
53
- if (isColumnField(col)) {
56
+ if ((0, orm_helper_js_1.isColumnField)(col)) {
54
57
  if (col.noUpdate)
55
58
  continue;
56
59
  if (typeof col.serialize === 'function')
@@ -59,10 +62,10 @@ export class UpdateCommand {
59
62
  throw new Error(`${entity.name}.${col.name} is required and can't be null`);
60
63
  if (v === undefined)
61
64
  continue;
62
- ColumnFieldMetadata.checkEnumValue(col, v);
65
+ column_field_metadata_js_1.ColumnFieldMetadata.checkEnumValue(col, v);
63
66
  const fieldName = prefix + col.fieldName + suffix;
64
67
  const k = ('I$_' + fieldName).substring(0, 30);
65
- ctx.queryValues[fieldName] = Param({
68
+ ctx.queryValues[fieldName] = (0, builder_1.Param)({
66
69
  name: k,
67
70
  dataType: col.dataType,
68
71
  isArray: col.isArray,
@@ -70,10 +73,11 @@ export class UpdateCommand {
70
73
  ctx.queryParams[k] = v;
71
74
  ctx.colCount++;
72
75
  }
73
- else if (v != null && isEmbeddedField(col)) {
74
- const type = await EmbeddedFieldMetadata.resolveType(col);
76
+ else if (v != null && (0, orm_helper_js_1.isEmbeddedField)(col)) {
77
+ const type = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
75
78
  await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
76
79
  }
77
80
  }
78
81
  }
79
82
  }
83
+ exports.UpdateCommand = UpdateCommand;
@@ -1,14 +1,17 @@
1
- import { EntityMetadata } from '../model/entity-metadata.js';
2
- import { DECORATOR_FACTORY } from '../orm.const.js';
3
- export function Column(arg0) {
4
- return Column[DECORATOR_FACTORY](arg0);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Column = Column;
4
+ const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
+ const orm_const_js_1 = require("../orm.const.js");
6
+ function Column(arg0) {
7
+ return Column[orm_const_js_1.DECORATOR_FACTORY](arg0);
5
8
  }
6
- Column[DECORATOR_FACTORY] = function (arg0) {
9
+ Column[orm_const_js_1.DECORATOR_FACTORY] = function (arg0) {
7
10
  return (target, propertyKey) => {
8
11
  if (typeof propertyKey !== 'string')
9
12
  throw new Error('Symbol properties are not accepted');
10
13
  const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
11
- const entity = EntityMetadata.define(target.constructor);
14
+ const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
12
15
  if (!options.type) {
13
16
  const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
14
17
  if (typ === Array) {
@@ -18,6 +21,6 @@ Column[DECORATOR_FACTORY] = function (arg0) {
18
21
  else
19
22
  options.type = typ;
20
23
  }
21
- EntityMetadata.defineColumnField(entity, propertyKey, options);
24
+ entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey, options);
22
25
  };
23
26
  };
@@ -1,12 +1,15 @@
1
- import { EntityMetadata } from '../model/entity-metadata.js';
2
- export function Embedded(type, options) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Embedded = Embedded;
4
+ const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
+ function Embedded(type, options) {
3
6
  return (target, propertyKey) => {
4
7
  if (typeof propertyKey !== 'string')
5
8
  throw new Error('Symbol properties are not accepted');
6
9
  type = type || Reflect.getMetadata('design:type', target, propertyKey);
7
10
  if (typeof type !== 'function')
8
11
  throw new Error('"type" must be defined');
9
- const entity = EntityMetadata.define(target.constructor);
10
- EntityMetadata.defineEmbeddedField(entity, propertyKey, type, options);
12
+ const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
13
+ entity_metadata_js_1.EntityMetadata.defineEmbeddedField(entity, propertyKey, type, options);
11
14
  };
12
15
  }