@sqb/connect 4.11.3 → 4.12.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 (56) hide show
  1. package/README.md +9 -24
  2. package/cjs/client/cursor-stream.js +6 -3
  3. package/cjs/client/cursor.js +8 -6
  4. package/cjs/client/field-info-map.js +3 -3
  5. package/cjs/client/sqb-client.js +2 -3
  6. package/cjs/client/sqb-connection.js +14 -13
  7. package/cjs/orm/commands/command.helper.js +7 -8
  8. package/cjs/orm/commands/create.command.js +4 -5
  9. package/cjs/orm/commands/find.command.js +18 -29
  10. package/cjs/orm/commands/row-converter.js +6 -6
  11. package/cjs/orm/commands/update.command.js +3 -4
  12. package/cjs/orm/decorators/column.decorator.js +1 -1
  13. package/cjs/orm/decorators/embedded.decorator.js +1 -1
  14. package/cjs/orm/decorators/entity.decorator.js +2 -2
  15. package/cjs/orm/decorators/link.decorator.js +1 -1
  16. package/cjs/orm/decorators/transform.decorator.js +2 -4
  17. package/cjs/orm/model/association-field-metadata.js +1 -1
  18. package/cjs/orm/model/association.js +2 -4
  19. package/cjs/orm/model/column-field-metadata.js +1 -1
  20. package/cjs/orm/model/embedded-field-metadata.js +1 -1
  21. package/cjs/orm/model/entity-metadata.js +7 -7
  22. package/cjs/orm/model/link-chain.js +2 -2
  23. package/cjs/orm/repository.class.js +8 -9
  24. package/cjs/orm/util/apply-mixins.js +6 -4
  25. package/cjs/orm/util/extract-keyvalues.js +1 -1
  26. package/cjs/orm/util/serialize-field.js +10 -10
  27. package/esm/client/cursor-stream.js +6 -3
  28. package/esm/client/cursor.js +8 -6
  29. package/esm/client/field-info-map.js +3 -3
  30. package/esm/client/helpers.js +1 -1
  31. package/esm/client/sqb-client.js +2 -3
  32. package/esm/client/sqb-connection.js +15 -14
  33. package/esm/orm/commands/command.helper.js +8 -9
  34. package/esm/orm/commands/create.command.js +4 -5
  35. package/esm/orm/commands/find.command.js +18 -29
  36. package/esm/orm/commands/row-converter.js +6 -6
  37. package/esm/orm/commands/update.command.js +3 -4
  38. package/esm/orm/decorators/column.decorator.js +1 -1
  39. package/esm/orm/decorators/embedded.decorator.js +1 -1
  40. package/esm/orm/decorators/entity.decorator.js +2 -2
  41. package/esm/orm/decorators/link.decorator.js +1 -1
  42. package/esm/orm/decorators/transform.decorator.js +2 -4
  43. package/esm/orm/model/association-field-metadata.js +1 -1
  44. package/esm/orm/model/association.js +2 -4
  45. package/esm/orm/model/column-field-metadata.js +1 -1
  46. package/esm/orm/model/embedded-field-metadata.js +1 -1
  47. package/esm/orm/model/entity-metadata.js +7 -7
  48. package/esm/orm/model/link-chain.js +2 -2
  49. package/esm/orm/repository.class.js +8 -9
  50. package/esm/orm/util/apply-mixins.js +6 -4
  51. package/esm/orm/util/extract-keyvalues.js +1 -1
  52. package/esm/orm/util/serialize-field.js +10 -10
  53. package/package.json +8 -7
  54. package/types/orm/decorators/entity.decorator.d.ts +2 -2
  55. package/types/orm/orm.type.d.ts +1 -1
  56. package/types/orm/repository.class.d.ts +2 -1
package/README.md CHANGED
@@ -18,12 +18,12 @@ SQB is an extensible, multi-dialect SQL query builder and Database connection wr
18
18
 
19
19
  ## Main goals
20
20
 
21
- - Single code base for any sql based database
22
- - Powerful and simplified query coding scheme
23
- - Fast applications with low memory requirements
24
- - Let applications work with large data tables efficiently
25
- - Support latest JavaScript language standards
26
- - Lightweight and extensible framework.
21
+ - Single code base for any sql based database
22
+ - Powerful and simplified query coding scheme
23
+ - Fast applications with low memory requirements
24
+ - Let applications work with large data tables efficiently
25
+ - Support latest JavaScript language standards
26
+ - Lightweight and extensible framework.
27
27
 
28
28
  You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
29
29
 
@@ -39,40 +39,25 @@ $ npm install @sqb/connect --save
39
39
 
40
40
  ## Node Compatibility
41
41
 
42
- - node >= 16.x
42
+ - node >= 16.x
43
43
 
44
44
  ### License
45
45
 
46
46
  SQB is available under [MIT](LICENSE) license.
47
47
 
48
48
  [npm-image]: https://img.shields.io/npm/v/@sqb/connect.svg
49
-
50
49
  [npm-url]: https://npmjs.org/package/@sqb/connect
51
-
52
50
  [travis-image]: https://img.shields.io/travis/sqbjs/@sqb/connect/master.svg
53
-
54
51
  [travis-url]: https://travis-ci.org/sqbjs/@sqb/connect
55
-
56
52
  [coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/connect/master.svg
57
-
58
53
  [coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/connect
59
-
60
54
  [downloads-image]: https://img.shields.io/npm/dm/@sqb/connect.svg
61
-
62
55
  [downloads-url]: https://npmjs.org/package/@sqb/connect
63
-
64
56
  [gitter-image]: https://badges.gitter.im/sqbjs/@sqb/connect.svg
65
-
66
57
  [gitter-url]: https://gitter.im/sqbjs/@sqb/connect?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
67
-
68
58
  [dependencies-image]: https://david-dm.org/sqbjs/@sqb/connect/status.svg
69
-
70
- [dependencies-url]:https://david-dm.org/sqbjs/@sqb/connect
71
-
59
+ [dependencies-url]: https://david-dm.org/sqbjs/@sqb/connect
72
60
  [devdependencies-image]: https://david-dm.org/sqbjs/@sqb/connect/dev-status.svg
73
-
74
- [devdependencies-url]:https://david-dm.org/sqbjs/@sqb/connect?type=dev
75
-
61
+ [devdependencies-url]: https://david-dm.org/sqbjs/@sqb/connect?type=dev
76
62
  [quality-image]: http://npm.packagequality.com/shield/@sqb/connect.png
77
-
78
63
  [quality-url]: http://packagequality.com/#?package=@sqb/connect
@@ -18,7 +18,7 @@ class CursorStream extends stream_1.Readable {
18
18
  this.close().catch(() => false);
19
19
  });
20
20
  cursor.once('close', () => this.emit('close'));
21
- cursor.on('error', (err) => this.emit('error', err));
21
+ cursor.on('error', err => this.emit('error', err));
22
22
  }
23
23
  /**
24
24
  * Returns if stream is closed.
@@ -47,7 +47,9 @@ class CursorStream extends stream_1.Readable {
47
47
  this.emit('end');
48
48
  return;
49
49
  }
50
- this._cursor.next().then(row => {
50
+ this._cursor
51
+ .next()
52
+ .then(row => {
51
53
  if (this._eof)
52
54
  return this.push(null);
53
55
  let buf = '';
@@ -74,7 +76,8 @@ class CursorStream extends stream_1.Readable {
74
76
  buf += ',';
75
77
  this.push(buf + JSON.stringify(row));
76
78
  }
77
- }).catch(err => {
79
+ })
80
+ .catch(err => {
78
81
  /* istanbul ignore next */
79
82
  if (typeof this.destroy == 'function')
80
83
  this.destroy(err);
@@ -179,7 +179,8 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
179
179
  if (step < 0 && !this._cache)
180
180
  throw new Error('To move cursor back, it needs cache to be enabled');
181
181
  const _this = this;
182
- await this._taskQueue.enqueue(async function () {
182
+ await this._taskQueue
183
+ .enqueue(async function () {
183
184
  /* If moving backward */
184
185
  if (step < 0) {
185
186
  /* Seek cache */
@@ -212,7 +213,8 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
212
213
  return;
213
214
  await _this._fetchRows();
214
215
  }
215
- }).toPromise();
216
+ })
217
+ .toPromise();
216
218
  if (!silent)
217
219
  this.emit('move', this.row, this._rowNum);
218
220
  return this._rowNum;
@@ -227,12 +229,12 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
227
229
  if (rows && rows.length) {
228
230
  debug('Fetched %d rows from database', rows.length);
229
231
  // Normalize rows
230
- rows = this._request.objectRows ?
231
- (0, helpers_js_1.normalizeRowsToObjectRows)(this._fields, this._intlcur.rowType, rows, this._request) :
232
- (0, helpers_js_1.normalizeRowsToArrayRows)(this._fields, this._intlcur.rowType, rows, this._request);
232
+ rows = this._request.objectRows
233
+ ? (0, helpers_js_1.normalizeRowsToObjectRows)(this._fields, this._intlcur.rowType, rows, this._request)
234
+ : (0, helpers_js_1.normalizeRowsToArrayRows)(this._fields, this._intlcur.rowType, rows, this._request);
233
235
  (0, helpers_js_1.callFetchHooks)(rows, this._request);
234
236
  for (const [idx, row] of rows.entries()) {
235
- this.emit('fetch', row, (this._rowNum + idx + 1));
237
+ this.emit('fetch', row, this._rowNum + idx + 1);
236
238
  }
237
239
  /* Add rows to cache */
238
240
  if (this._cache) {
@@ -7,13 +7,13 @@ class FieldInfoMap {
7
7
  enumerable: false,
8
8
  configurable: false,
9
9
  writable: true,
10
- value: {}
10
+ value: {},
11
11
  });
12
12
  Object.defineProperty(this, '_arr', {
13
13
  enumerable: false,
14
14
  configurable: false,
15
15
  writable: true,
16
- value: []
16
+ value: [],
17
17
  });
18
18
  }
19
19
  add(field) {
@@ -28,7 +28,7 @@ class FieldInfoMap {
28
28
  enumerable: false,
29
29
  configurable: false,
30
30
  writable: true,
31
- value: _obj
31
+ value: _obj,
32
32
  });
33
33
  }
34
34
  get(k) {
@@ -50,7 +50,7 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
50
50
  create: () => adapter.connect(cfg),
51
51
  destroy: instance => instance.close(),
52
52
  reset: async (instance) => instance.reset(),
53
- validate: instance => instance.test()
53
+ validate: instance => instance.test(),
54
54
  };
55
55
  this._pool = (0, lightning_pool_1.createPool)(poolFactory, poolOptions);
56
56
  this._pool.on('closing', () => this.emit('closing'));
@@ -159,8 +159,7 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
159
159
  return this._entities[name];
160
160
  }
161
161
  toString() {
162
- return '[object ' + Object.getPrototypeOf(this).constructor.name + '(' +
163
- this.dialect + ')]';
162
+ return '[object ' + Object.getPrototypeOf(this).constructor.name + '(' + this.dialect + ')]';
164
163
  }
165
164
  [inspect]() {
166
165
  return this.toString();
@@ -78,7 +78,7 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
78
78
  await this.emitAsyncSerial('close');
79
79
  const intlcon = this._intlcon;
80
80
  this._intlcon = undefined;
81
- this.client.pool.release(intlcon, (e) => {
81
+ this.client.pool.release(intlcon, e => {
82
82
  if (e)
83
83
  this.client.emit('error', e);
84
84
  });
@@ -135,7 +135,7 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
135
135
  if (!response)
136
136
  throw new Error('Database adapter returned an empty response');
137
137
  const result = {
138
- executeTime: Date.now() - startTime
138
+ executeTime: Date.now() - startTime,
139
139
  };
140
140
  if (request.showSql)
141
141
  result.query = request;
@@ -147,13 +147,13 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
147
147
  result.fields = (0, helpers_js_1.wrapAdapterFields)(response.fields, request.fieldNaming);
148
148
  result.rowType = response.rowType;
149
149
  if (response.rows) {
150
- result.rows = request.objectRows ?
151
- (0, helpers_js_1.normalizeRowsToObjectRows)(result.fields, response.rowType, response.rows, request) :
152
- (0, helpers_js_1.normalizeRowsToArrayRows)(result.fields, response.rowType, response.rows, request);
150
+ result.rows = request.objectRows
151
+ ? (0, helpers_js_1.normalizeRowsToObjectRows)(result.fields, response.rowType, response.rows, request)
152
+ : (0, helpers_js_1.normalizeRowsToArrayRows)(result.fields, response.rowType, response.rows, request);
153
153
  (0, helpers_js_1.callFetchHooks)(result.rows, request);
154
154
  }
155
155
  else if (response.cursor) {
156
- const cursor = result.cursor = new cursor_js_1.Cursor(this, result.fields, response.cursor, request);
156
+ const cursor = (result.cursor = new cursor_js_1.Cursor(this, result.fields, response.cursor, request));
157
157
  const hook = () => cursor.close();
158
158
  cursor.once('close', () => this.off('close', hook));
159
159
  this.on('close', hook);
@@ -226,8 +226,9 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
226
226
  const request = {
227
227
  dialect: this.client.dialect,
228
228
  sql: '',
229
- autoCommit: this.inTransaction ? false :
230
- (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.autoCommit, this._options?.autoCommit, defaults.autoCommit), true),
229
+ autoCommit: this.inTransaction
230
+ ? false
231
+ : (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.autoCommit, this._options?.autoCommit, defaults.autoCommit), true),
231
232
  cursor: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.cursor, defaults.cursor), false),
232
233
  objectRows: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.objectRows, defaults.objectRows), true),
233
234
  ignoreNulls: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.ignoreNulls, defaults.ignoreNulls), false),
@@ -237,19 +238,18 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
237
238
  showSql: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.showSql, defaults.showSql), false),
238
239
  prettyPrint: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.prettyPrint, defaults.prettyPrint), false),
239
240
  action: (0, putil_varhelpers_1.coerceToString)(options.action),
240
- fetchAsString: options.fetchAsString
241
+ fetchAsString: options.fetchAsString,
241
242
  };
242
243
  request.ignoreNulls = request.ignoreNulls && request.objectRows;
243
244
  if (query instanceof builder_1.classes.Query) {
244
245
  if (this._intlcon.onGenerateQuery)
245
246
  this._intlcon.onGenerateQuery(request, query);
246
- const q = query
247
- .generate({
247
+ const q = query.generate({
248
248
  dialect: request.dialect,
249
249
  dialectVersion: request.dialectVersion,
250
250
  params: options.params,
251
251
  strictParams: true,
252
- prettyPrint: request.prettyPrint
252
+ prettyPrint: request.prettyPrint,
253
253
  });
254
254
  request.sql = q.sql;
255
255
  request.params = q.params;
@@ -261,7 +261,8 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
261
261
  if (query.listenerCount('fetch'))
262
262
  request.fetchHooks = query.listeners('fetch');
263
263
  }
264
- else { // noinspection SuspiciousTypeOfGuard
264
+ else {
265
+ // noinspection SuspiciousTypeOfGuard
265
266
  if (typeof query === 'string') {
266
267
  request.sql = query;
267
268
  request.params = options.params;
@@ -27,8 +27,9 @@ async function joinAssociation(joinInfos, association, parentAlias, innerJoin) {
27
27
  const keyCol = await node.resolveSourceProperty();
28
28
  const targetCol = await node.resolveTargetProperty();
29
29
  const joinAlias = 'J' + (joinInfos.length + 1);
30
- const join = innerJoin ? (0, builder_1.InnerJoin)(targetEntity.tableName + ' as ' + joinAlias) :
31
- (0, builder_1.LeftOuterJoin)(targetEntity.tableName + ' as ' + joinAlias);
30
+ const join = innerJoin
31
+ ? (0, builder_1.InnerJoin)(targetEntity.tableName + ' as ' + joinAlias)
32
+ : (0, builder_1.LeftOuterJoin)(targetEntity.tableName + ' as ' + joinAlias);
32
33
  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)));
33
34
  if (node.conditions)
34
35
  await prepareFilter(targetEntity, node.conditions, join._conditions, joinAlias);
@@ -37,7 +38,7 @@ async function joinAssociation(joinInfos, association, parentAlias, innerJoin) {
37
38
  sourceEntity,
38
39
  targetEntity,
39
40
  joinAlias,
40
- join
41
+ join,
41
42
  };
42
43
  joinInfos.push(joinInfo);
43
44
  }
@@ -107,8 +108,7 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
107
108
  if (!subSelect) {
108
109
  const keyCol = await col.association.resolveSourceProperty();
109
110
  const targetCol = await col.association.resolveTargetProperty();
110
- subSelect = (0, builder_1.Select)((0, builder_1.Raw)('1'))
111
- .from(_curEntity.tableName + ' K');
111
+ subSelect = (0, builder_1.Select)((0, builder_1.Raw)('1')).from(_curEntity.tableName + ' K');
112
112
  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)));
113
113
  trgOp.add((0, builder_1.Exists)(subSelect));
114
114
  trgOp = subSelect._where;
@@ -124,9 +124,8 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
124
124
  const targetEntity = await node.resolveTarget();
125
125
  const sourceColumn = await node.resolveSourceProperty();
126
126
  const targetColumn = await node.resolveTargetProperty();
127
- const joinAlias = 'J' + (((subSelect?._joins?.length) || 0) + 1);
128
- subSelect.join((0, builder_1.InnerJoin)(targetEntity.tableName + ' ' + joinAlias)
129
- .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))));
127
+ const joinAlias = 'J' + ((subSelect?._joins?.length || 0) + 1);
128
+ 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))));
130
129
  _curEntity = targetEntity;
131
130
  _curAlias = joinAlias;
132
131
  node = node.next;
@@ -21,7 +21,7 @@ class CreateCommand {
21
21
  entity,
22
22
  queryParams: {},
23
23
  queryValues: {},
24
- colCount: 0
24
+ colCount: 0,
25
25
  };
26
26
  // Prepare
27
27
  await this._prepareParams(ctx, entity, args.values);
@@ -36,7 +36,7 @@ class CreateCommand {
36
36
  const qr = await args.connection.execute(query, {
37
37
  params: ctx.queryParams,
38
38
  objectRows: false,
39
- cursor: false
39
+ cursor: false,
40
40
  });
41
41
  if (args.returning && qr.fields && qr.rows?.length) {
42
42
  const keyValues = {};
@@ -58,8 +58,7 @@ class CreateCommand {
58
58
  if (col.noInsert)
59
59
  continue;
60
60
  if (v == null && col.default !== undefined) {
61
- v = typeof col.default === 'function' ?
62
- col.default(values) : col.default;
61
+ v = typeof col.default === 'function' ? col.default(values) : col.default;
63
62
  }
64
63
  if (typeof col.serialize === 'function')
65
64
  v = col.serialize(v, col.name);
@@ -74,7 +73,7 @@ class CreateCommand {
74
73
  ctx.queryValues[fieldName] = (0, builder_1.Param)({
75
74
  name: k,
76
75
  dataType: col.dataType,
77
- isArray: col.isArray
76
+ isArray: col.isArray,
78
77
  });
79
78
  ctx.queryParams[k] = v;
80
79
  ctx.colCount++;
@@ -59,7 +59,7 @@ class FindCommand {
59
59
  pick: args.pick,
60
60
  include: args.include,
61
61
  omit: args.omit,
62
- sort: args.sort
62
+ sort: args.sort,
63
63
  });
64
64
  if (args.filter)
65
65
  await command.filter(args.filter);
@@ -71,12 +71,9 @@ class FindCommand {
71
71
  const tableAlias = opts.tableAlias || this.resultAlias;
72
72
  const entity = opts.entity || this._getEntityFromAlias(tableAlias);
73
73
  const converter = opts.converter || this.converter;
74
- const _pick = opts.pick ?
75
- opts.pick.map(x => x.toLowerCase()) : undefined;
76
- const _omit = opts.omit ?
77
- opts.omit.map(x => x.toLowerCase()) : undefined;
78
- const _include = opts.include ?
79
- opts.include.map(x => x.toLowerCase()) : undefined;
74
+ const _pick = opts.pick ? opts.pick.map(x => x.toLowerCase()) : undefined;
75
+ const _omit = opts.omit ? opts.omit.map(x => x.toLowerCase()) : undefined;
76
+ const _include = opts.include ? opts.include.map(x => x.toLowerCase()) : undefined;
80
77
  let requestedFields;
81
78
  if (_pick)
82
79
  requestedFields = [..._pick];
@@ -90,8 +87,7 @@ class FindCommand {
90
87
  }
91
88
  if (_include)
92
89
  requestedFields.push(..._include);
93
- const sortFields = opts.sort && opts.sort.length ?
94
- opts.sort.map(x => x.toLowerCase()) : undefined;
90
+ const sortFields = opts.sort && opts.sort.length ? opts.sort.map(x => x.toLowerCase()) : undefined;
95
91
  const prefix = opts.prefix || '';
96
92
  const suffix = opts.suffix || '';
97
93
  for (const key of Object.keys(entity.fields)) {
@@ -113,7 +109,7 @@ class FindCommand {
113
109
  name: col.name,
114
110
  fieldAlias,
115
111
  dataType: col.dataType,
116
- parse: col.parse
112
+ parse: col.parse,
117
113
  });
118
114
  continue;
119
115
  }
@@ -121,7 +117,7 @@ class FindCommand {
121
117
  const typ = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
122
118
  const subConverter = converter.addObjectProperty({
123
119
  name: col.name,
124
- type: typ.ctor
120
+ type: typ.ctor,
125
121
  }).converter;
126
122
  await this.addFields({
127
123
  tableAlias,
@@ -129,8 +125,7 @@ class FindCommand {
129
125
  entity: typ,
130
126
  prefix: col.fieldNamePrefix,
131
127
  suffix: col.fieldNameSuffix,
132
- pick: _pick?.includes(colNameLower) ? undefined :
133
- extractSubFields(colNameLower, _pick),
128
+ pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
134
129
  include: extractSubFields(colNameLower, _include),
135
130
  omit: extractSubFields(colNameLower, _omit),
136
131
  sort: extractSubFields(colNameLower, sortFields),
@@ -143,15 +138,14 @@ class FindCommand {
143
138
  const joinInfo = await (0, command_helper_js_1.joinAssociationGetLast)(this._joins, col.association, tableAlias);
144
139
  const subConverter = converter.addObjectProperty({
145
140
  name: col.name,
146
- type: joinInfo.targetEntity.ctor
141
+ type: joinInfo.targetEntity.ctor,
147
142
  }).converter;
148
143
  // Add join fields to select columns list
149
144
  await this.addFields({
150
145
  tableAlias: joinInfo.joinAlias,
151
146
  converter: subConverter,
152
147
  entity: joinInfo.targetEntity,
153
- pick: _pick?.includes(colNameLower) ? undefined :
154
- extractSubFields(colNameLower, _pick),
148
+ pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
155
149
  include: extractSubFields(colNameLower, _include),
156
150
  omit: extractSubFields(colNameLower, _omit),
157
151
  sort: extractSubFields(colNameLower, sortFields),
@@ -167,14 +161,13 @@ class FindCommand {
167
161
  const parentField = this._selectColumn(tableAlias, sourceCol);
168
162
  const findCommand = await FindCommand.create(col.association, {
169
163
  maxSubQueries: this.maxSubQueries - 1,
170
- maxEagerFetch: this.maxEagerFetch
164
+ maxEagerFetch: this.maxEagerFetch,
171
165
  });
172
166
  findCommand.converter.parent = this.converter;
173
167
  await findCommand.filter((0, builder_1.In)(targetCol.name, (0, builder_1.Param)(parentField)));
174
168
  const sort = sortFields && extractSubFields(colNameLower, sortFields);
175
169
  await findCommand.addFields({
176
- pick: _pick?.includes(colNameLower) ? undefined :
177
- extractSubFields(colNameLower, _pick),
170
+ pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
178
171
  include: extractSubFields(colNameLower, _include),
179
172
  omit: extractSubFields(colNameLower, _omit),
180
173
  sort,
@@ -189,20 +182,18 @@ class FindCommand {
189
182
  findCommand,
190
183
  parentField,
191
184
  keyField,
192
- sort: extractSubFields(colNameLower, sortFields)
185
+ sort: extractSubFields(colNameLower, sortFields),
193
186
  });
194
187
  }
195
188
  }
196
189
  }
197
190
  }
198
191
  _selectColumn(tableAlias, el, prefix, suffix) {
199
- const fieldName = (prefix || '').toLowerCase() +
200
- el.fieldName.toUpperCase() +
201
- (suffix || '').toLowerCase();
192
+ const fieldName = (prefix || '').toLowerCase() + el.fieldName.toUpperCase() + (suffix || '').toLowerCase();
202
193
  const fieldAlias = (tableAlias + '_' + fieldName).substring(0, 30);
203
194
  this._selectColumns[fieldAlias] = {
204
195
  field: el,
205
- statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias
196
+ statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias,
206
197
  };
207
198
  return fieldAlias;
208
199
  }
@@ -259,12 +250,10 @@ class FindCommand {
259
250
  }
260
251
  async execute(args) {
261
252
  // Generate select query
262
- const columnSqls = Object.keys(this._selectColumns)
263
- .map(x => this._selectColumns[x].statement);
253
+ const columnSqls = Object.keys(this._selectColumns).map(x => this._selectColumns[x].statement);
264
254
  if (!columnSqls.length)
265
255
  columnSqls.push('1');
266
- const query = (0, builder_1.Select)(...columnSqls)
267
- .from(this.mainEntity.tableName + ' as ' + this.mainAlias);
256
+ const query = (0, builder_1.Select)(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
268
257
  if (args.distinct)
269
258
  query.distinct();
270
259
  query.where(...this._filter._items);
@@ -283,7 +272,7 @@ class FindCommand {
283
272
  params: args?.params,
284
273
  fetchRows: args?.limit,
285
274
  objectRows: false,
286
- cursor: false
275
+ cursor: false,
287
276
  });
288
277
  // Create objects
289
278
  if (resp.rows && resp.fields) {
@@ -22,7 +22,7 @@ class RowConverter {
22
22
  const item = {
23
23
  fieldAlias: args.fieldAlias,
24
24
  dataType: args.dataType,
25
- parse: args.parse
25
+ parse: args.parse,
26
26
  };
27
27
  this._properties[args.name] = item;
28
28
  return item;
@@ -33,7 +33,7 @@ class RowConverter {
33
33
  const converter = new RowConverter(args.type, this);
34
34
  const item = {
35
35
  converter,
36
- type: args.type
36
+ type: args.type,
37
37
  };
38
38
  this._properties[args.name] = item;
39
39
  return item;
@@ -48,7 +48,7 @@ class RowConverter {
48
48
  keyField: args.keyField,
49
49
  findCommand: args.findCommand,
50
50
  sort: args.sort,
51
- paramValues: []
51
+ paramValues: [],
52
52
  };
53
53
  this._properties[args.name] = item;
54
54
  return item;
@@ -129,7 +129,7 @@ class RowConverter {
129
129
  if (!(prop.paramValues && prop.paramValues.length))
130
130
  continue;
131
131
  const resultType = this.resultType;
132
- const promise = async function (p) {
132
+ const promise = (async function (p) {
133
133
  const findCommand = p.findCommand;
134
134
  let fld;
135
135
  const map = new Map();
@@ -151,7 +151,7 @@ class RowConverter {
151
151
  arr.push(obj);
152
152
  });
153
153
  }
154
- }
154
+ },
155
155
  });
156
156
  if (r.length > findCommand.maxEagerFetch)
157
157
  throw new Error(`Number of returning rows for "${propKey}" exceeds maxEagerFetch limit`);
@@ -171,7 +171,7 @@ class RowConverter {
171
171
  }
172
172
  }
173
173
  }
174
- }(prop);
174
+ })(prop);
175
175
  promises.push(promise);
176
176
  }
177
177
  else if (isObjectProperty(prop)) {
@@ -30,12 +30,11 @@ class UpdateCommand {
30
30
  return 0;
31
31
  if (args.filter)
32
32
  await this._prepareFilter(ctx, args.filter);
33
- const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues)
34
- .where(...ctx.queryFilter);
33
+ const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
35
34
  const qr = await args.connection.execute(query, {
36
35
  params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
37
36
  objectRows: false,
38
- cursor: false
37
+ cursor: false,
39
38
  });
40
39
  return qr.rowsAffected || 0;
41
40
  }
@@ -69,7 +68,7 @@ class UpdateCommand {
69
68
  ctx.queryValues[fieldName] = (0, builder_1.Param)({
70
69
  name: k,
71
70
  dataType: col.dataType,
72
- isArray: col.isArray
71
+ isArray: col.isArray,
73
72
  });
74
73
  ctx.queryParams[k] = v;
75
74
  ctx.colCount++;
@@ -9,7 +9,7 @@ function Column(arg0) {
9
9
  const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
10
10
  const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
11
11
  if (!options.type) {
12
- const typ = Reflect.getMetadata("design:type", entity.ctor.prototype, propertyKey);
12
+ const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
13
13
  if (typ === Array) {
14
14
  options.type = String;
15
15
  options.isArray = true;
@@ -6,7 +6,7 @@ function Embedded(type, options) {
6
6
  return (target, propertyKey) => {
7
7
  if (typeof propertyKey !== 'string')
8
8
  throw new Error('Symbol properties are not accepted');
9
- type = type || Reflect.getMetadata("design:type", target, propertyKey);
9
+ type = type || Reflect.getMetadata('design:type', target, propertyKey);
10
10
  if (typeof type !== 'function')
11
11
  throw new Error('"type" must be defined');
12
12
  const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
@@ -115,7 +115,7 @@ exports.Entity = Entity;
115
115
  }
116
116
  };
117
117
  const pickKeys = keys.map(x => x.toLowerCase());
118
- const filter = (k) => pickKeys.includes(k.toLowerCase());
118
+ const filter = k => pickKeys.includes(k.toLowerCase());
119
119
  (0, apply_mixins_js_1.applyMixins)(PickEntityClass, classRef, filter);
120
120
  const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
121
121
  if (srcMeta) {
@@ -132,7 +132,7 @@ exports.Entity = Entity;
132
132
  }
133
133
  };
134
134
  const omitKeys = keys.map(x => x.toLowerCase());
135
- const filter = (k) => !omitKeys.includes(k.toLowerCase());
135
+ const filter = k => !omitKeys.includes(k.toLowerCase());
136
136
  (0, apply_mixins_js_1.applyMixins)(OmitEntityClass, classRef, filter);
137
137
  const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
138
138
  if (srcMeta) {
@@ -9,7 +9,7 @@ function Link(options) {
9
9
  const fn = (target, propertyKey) => {
10
10
  if (typeof propertyKey !== 'string')
11
11
  throw new TypeError('Symbol properties are not allowed');
12
- const reflectType = Reflect.getMetadata("design:type", target, propertyKey);
12
+ const reflectType = Reflect.getMetadata('design:type', target, propertyKey);
13
13
  if (!root) {
14
14
  if (reflectType === Array)
15
15
  throw new TypeError(`Can't get type information while it is an array. Please define entity type`);
@@ -7,8 +7,7 @@ function Parse(fn) {
7
7
  if (typeof propertyKey !== 'string')
8
8
  throw new Error('You can define a Column for only string properties');
9
9
  const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
10
- entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey)
11
- .parse = fn;
10
+ entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
12
11
  };
13
12
  }
14
13
  exports.Parse = Parse;
@@ -17,8 +16,7 @@ function Serialize(fn) {
17
16
  if (typeof propertyKey !== 'string')
18
17
  throw new Error('You can define a Column for only string properties');
19
18
  const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
20
- entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey)
21
- .serialize = fn;
19
+ entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
22
20
  };
23
21
  }
24
22
  exports.Serialize = Serialize;
@@ -10,7 +10,7 @@ var AssociationFieldMetadata;
10
10
  kind: 'association',
11
11
  entity,
12
12
  name,
13
- association
13
+ association,
14
14
  };
15
15
  if (options)
16
16
  AssociationFieldMetadata.assign(result, options);