@sqb/connect 4.0.7 → 4.0.10

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 (89) hide show
  1. package/package.json +6 -7
  2. package/dist/client/Adapter.d.ts +0 -57
  3. package/dist/client/Adapter.js +0 -2
  4. package/dist/client/Cursor.d.ts +0 -116
  5. package/dist/client/Cursor.js +0 -250
  6. package/dist/client/CursorStream.d.ts +0 -29
  7. package/dist/client/CursorStream.js +0 -98
  8. package/dist/client/FieldInfoMap.d.ts +0 -10
  9. package/dist/client/FieldInfoMap.js +0 -33
  10. package/dist/client/SqbClient.d.ts +0 -70
  11. package/dist/client/SqbClient.js +0 -165
  12. package/dist/client/SqbConnection.d.ts +0 -74
  13. package/dist/client/SqbConnection.js +0 -272
  14. package/dist/client/extensions.d.ts +0 -4
  15. package/dist/client/extensions.js +0 -14
  16. package/dist/client/helpers.d.ts +0 -9
  17. package/dist/client/helpers.js +0 -133
  18. package/dist/client/types.d.ts +0 -189
  19. package/dist/client/types.js +0 -5
  20. package/dist/index.d.ts +0 -28
  21. package/dist/index.js +0 -37
  22. package/dist/orm/base-entity.class.d.ts +0 -16
  23. package/dist/orm/base-entity.class.js +0 -56
  24. package/dist/orm/commands/command.helper.d.ts +0 -14
  25. package/dist/orm/commands/command.helper.js +0 -140
  26. package/dist/orm/commands/count.command.d.ts +0 -11
  27. package/dist/orm/commands/count.command.js +0 -30
  28. package/dist/orm/commands/create.command.d.ts +0 -20
  29. package/dist/orm/commands/create.command.js +0 -83
  30. package/dist/orm/commands/destroy.command.d.ts +0 -11
  31. package/dist/orm/commands/destroy.command.js +0 -30
  32. package/dist/orm/commands/find.command.d.ts +0 -44
  33. package/dist/orm/commands/find.command.js +0 -308
  34. package/dist/orm/commands/row-converter.d.ts +0 -55
  35. package/dist/orm/commands/row-converter.js +0 -187
  36. package/dist/orm/commands/update.command.d.ts +0 -22
  37. package/dist/orm/commands/update.command.js +0 -82
  38. package/dist/orm/decorators/column.decorator.d.ts +0 -4
  39. package/dist/orm/decorators/column.decorator.js +0 -14
  40. package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
  41. package/dist/orm/decorators/embedded.decorator.js +0 -17
  42. package/dist/orm/decorators/entity.decorator.d.ts +0 -6
  43. package/dist/orm/decorators/entity.decorator.js +0 -23
  44. package/dist/orm/decorators/events.decorator.d.ts +0 -6
  45. package/dist/orm/decorators/events.decorator.js +0 -76
  46. package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
  47. package/dist/orm/decorators/foreignkey.decorator.js +0 -13
  48. package/dist/orm/decorators/index.decorator.d.ts +0 -3
  49. package/dist/orm/decorators/index.decorator.js +0 -22
  50. package/dist/orm/decorators/link.decorator.d.ts +0 -23
  51. package/dist/orm/decorators/link.decorator.js +0 -88
  52. package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
  53. package/dist/orm/decorators/primarykey.decorator.js +0 -23
  54. package/dist/orm/decorators/transform.decorator.d.ts +0 -3
  55. package/dist/orm/decorators/transform.decorator.js +0 -24
  56. package/dist/orm/model/abstract-entityelement.d.ts +0 -8
  57. package/dist/orm/model/abstract-entityelement.js +0 -10
  58. package/dist/orm/model/association-node.d.ts +0 -9
  59. package/dist/orm/model/association-node.js +0 -25
  60. package/dist/orm/model/association.d.ts +0 -28
  61. package/dist/orm/model/association.js +0 -129
  62. package/dist/orm/model/entity-association-element.d.ts +0 -9
  63. package/dist/orm/model/entity-association-element.js +0 -13
  64. package/dist/orm/model/entity-column-element.d.ts +0 -68
  65. package/dist/orm/model/entity-column-element.js +0 -27
  66. package/dist/orm/model/entity-model.d.ts +0 -59
  67. package/dist/orm/model/entity-model.js +0 -295
  68. package/dist/orm/model/entity-object-element.d.ts +0 -12
  69. package/dist/orm/model/entity-object-element.js +0 -24
  70. package/dist/orm/model/index-meta.d.ts +0 -9
  71. package/dist/orm/model/index-meta.js +0 -16
  72. package/dist/orm/model/link-chain.d.ts +0 -15
  73. package/dist/orm/model/link-chain.js +0 -50
  74. package/dist/orm/orm.const.d.ts +0 -2
  75. package/dist/orm/orm.const.js +0 -5
  76. package/dist/orm/orm.type.d.ts +0 -112
  77. package/dist/orm/orm.type.js +0 -2
  78. package/dist/orm/repository.class.d.ts +0 -125
  79. package/dist/orm/repository.class.js +0 -217
  80. package/dist/orm/util/entity-mapping.d.ts +0 -12
  81. package/dist/orm/util/entity-mapping.js +0 -154
  82. package/dist/orm/util/extract-keyvalues.d.ts +0 -2
  83. package/dist/orm/util/extract-keyvalues.js +0 -60
  84. package/dist/orm/util/orm.helper.d.ts +0 -14
  85. package/dist/orm/util/orm.helper.js +0 -39
  86. package/dist/orm/util/serialize-element.d.ts +0 -2
  87. package/dist/orm/util/serialize-element.js +0 -43
  88. package/dist/types.d.ts +0 -2
  89. package/dist/types.js +0 -2
@@ -1,20 +0,0 @@
1
- import type { EntityModel } from '../model/entity-model';
2
- import { SqbConnection } from '../../client/SqbConnection';
3
- export declare type CreateCommandArgs = {
4
- entity: EntityModel;
5
- connection: SqbConnection;
6
- values: any;
7
- returning?: boolean;
8
- };
9
- declare type CreateCommandContext = {
10
- entity: EntityModel;
11
- queryParams: any;
12
- queryValues: any;
13
- colCount: number;
14
- };
15
- export declare class CreateCommand {
16
- protected constructor();
17
- static execute(args: CreateCommandArgs): Promise<any>;
18
- protected static _prepareParams(ctx: CreateCommandContext, entity: EntityModel, values: any, prefix?: string, suffix?: string): Promise<void>;
19
- }
20
- export {};
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateCommand = void 0;
4
- const builder_1 = require("@sqb/builder");
5
- const orm_helper_1 = require("../util/orm.helper");
6
- class CreateCommand {
7
- // istanbul ignore next
8
- constructor() {
9
- throw new Error('This class is abstract');
10
- }
11
- static async execute(args) {
12
- const { entity } = args;
13
- const tableName = entity.tableName;
14
- if (!tableName)
15
- throw new Error(`${entity.ctor.name} is not decorated with @Entity decorator`);
16
- // Create a context
17
- const ctx = {
18
- entity,
19
- queryParams: {},
20
- queryValues: {},
21
- colCount: 0
22
- };
23
- // Prepare
24
- await this._prepareParams(ctx, entity, args.values);
25
- if (!ctx.colCount)
26
- throw new Error('No element given to create new entity instance');
27
- const query = (0, builder_1.Insert)(tableName, ctx.queryValues);
28
- if (args.returning && entity.primaryIndex)
29
- query.returning(...entity.getPrimaryIndexColumns().map(col => col.fieldName));
30
- const qr = await args.connection.execute(query, {
31
- params: ctx.queryParams,
32
- objectRows: false,
33
- cursor: false
34
- });
35
- if (args.returning && qr.fields && qr.rows?.length) {
36
- const keyValues = {};
37
- for (const f of qr.fields.values()) {
38
- const el = entity.getColumnElementByFieldName(f.fieldName);
39
- if (el)
40
- keyValues[el.name] = qr.rows[0][f.index];
41
- }
42
- return keyValues;
43
- }
44
- }
45
- static async _prepareParams(ctx, entity, values, prefix, suffix) {
46
- let v;
47
- prefix = prefix || '';
48
- suffix = suffix || '';
49
- for (const col of entity.elements.values()) {
50
- v = values[col.name];
51
- if ((0, orm_helper_1.isColumnElement)(col)) {
52
- if (col.noInsert)
53
- continue;
54
- if (v == null && col.default !== undefined) {
55
- v = typeof col.default === 'function' ?
56
- col.default(values) : col.default;
57
- }
58
- if (typeof col.serialize === 'function')
59
- v = col.serialize(v, col.name);
60
- if (v == null) {
61
- if (col.notNull && !col.autoGenerated)
62
- throw new Error(`${entity.name}.${col.name} is required and can't be null`);
63
- continue;
64
- }
65
- col.checkEnumValue(v);
66
- const fieldName = prefix + col.fieldName + suffix;
67
- const k = '$input_' + fieldName;
68
- ctx.queryValues[fieldName] = (0, builder_1.Param)({
69
- name: k,
70
- dataType: col.dataType,
71
- isArray: col.isArray
72
- });
73
- ctx.queryParams[k] = v;
74
- ctx.colCount++;
75
- }
76
- else if (v != null && (0, orm_helper_1.isObjectElement)(col)) {
77
- const type = await col.resolveType();
78
- await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
79
- }
80
- }
81
- }
82
- }
83
- exports.CreateCommand = CreateCommand;
@@ -1,11 +0,0 @@
1
- import { EntityModel } from '../model/entity-model';
2
- import { Repository } from '../repository.class';
3
- import { SqbConnection } from '../../client/SqbConnection';
4
- export declare type DestroyCommandArgs = {
5
- entity: EntityModel;
6
- connection: SqbConnection;
7
- } & Repository.DestroyOptions;
8
- export declare class DestroyCommand {
9
- protected constructor();
10
- static execute(args: DestroyCommandArgs): Promise<number>;
11
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DestroyCommand = void 0;
4
- const builder_1 = require("@sqb/builder");
5
- const command_helper_1 = require("./command.helper");
6
- class DestroyCommand {
7
- // istanbul ignore next
8
- constructor() {
9
- throw new Error('This class is abstract');
10
- }
11
- static async execute(args) {
12
- const { connection, entity, filter, params } = args;
13
- let where;
14
- if (filter) {
15
- where = (0, builder_1.And)();
16
- await (0, command_helper_1.prepareFilter)(entity, filter, where);
17
- }
18
- const query = (0, builder_1.Delete)(entity.tableName + ' T');
19
- if (where)
20
- query.where(...where._items);
21
- // Execute query
22
- const resp = await connection.execute(query, {
23
- params,
24
- objectRows: false,
25
- cursor: false,
26
- });
27
- return (resp && resp.rowsAffected) || 0;
28
- }
29
- }
30
- exports.DestroyCommand = DestroyCommand;
@@ -1,44 +0,0 @@
1
- import type { Repository } from '../repository.class';
2
- import type { EntityModel } from '../model/entity-model';
3
- import { RowConverter } from './row-converter';
4
- import { AssociationNode } from '../model/association-node';
5
- import { SqbConnection } from '../../client/SqbConnection';
6
- export declare type FindCommandArgs = {
7
- entity: EntityModel;
8
- connection: SqbConnection;
9
- } & Repository.FindAllOptions;
10
- export declare class FindCommand {
11
- maxEagerFetch: number;
12
- maxSubQueries: number;
13
- readonly mainEntity: EntityModel;
14
- readonly resultEntity: EntityModel;
15
- readonly converter: RowConverter;
16
- readonly mainAlias: string;
17
- resultAlias: string;
18
- private _joins;
19
- private _selectColumns;
20
- private _filter;
21
- private _sort?;
22
- protected constructor(selectEntity: EntityModel, outputEntity: EntityModel);
23
- static create(source: EntityModel | AssociationNode, opts?: {
24
- maxSubQueries?: number;
25
- maxEagerFetch?: number;
26
- }): Promise<FindCommand>;
27
- static execute(args: FindCommandArgs): Promise<any[]>;
28
- addElements(opts?: {
29
- tableAlias?: string;
30
- converter?: RowConverter;
31
- entity?: EntityModel;
32
- elements?: string[];
33
- include?: string[];
34
- exclude?: string[];
35
- sort?: string[];
36
- prefix?: string;
37
- suffix?: string;
38
- }): Promise<void>;
39
- private _selectColumn;
40
- filter(filter: any): Promise<void>;
41
- sort(sortElements: string[]): Promise<void>;
42
- execute(args: Pick<FindCommandArgs, 'connection' | 'distinct' | 'offset' | 'limit' | 'params' | 'onTransformRow'>): Promise<any[]>;
43
- private _getEntityFromAlias;
44
- }
@@ -1,308 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FindCommand = void 0;
4
- const builder_1 = require("@sqb/builder");
5
- const row_converter_1 = require("./row-converter");
6
- const association_node_1 = require("../model/association-node");
7
- const orm_helper_1 = require("../util/orm.helper");
8
- const command_helper_1 = require("./command.helper");
9
- const base_entity_class_1 = require("../base-entity.class");
10
- const SORT_ORDER_PATTERN = /^([-+])?(.*)$/;
11
- class FindCommand {
12
- constructor(selectEntity, outputEntity) {
13
- this.maxEagerFetch = 100000;
14
- this.maxSubQueries = 5;
15
- this.mainAlias = 'T';
16
- this.resultAlias = 'T';
17
- this._joins = [];
18
- this._selectColumns = {};
19
- this._filter = (0, builder_1.And)();
20
- this.mainEntity = selectEntity;
21
- this.resultEntity = outputEntity;
22
- this.converter = new row_converter_1.RowConverter(outputEntity.ctor);
23
- }
24
- static async create(source, opts = {}) {
25
- let command;
26
- let listingEntity;
27
- if (source instanceof association_node_1.AssociationNode) {
28
- const node = source;
29
- listingEntity = await node.resolveTarget();
30
- const resultEntity = await node.getLast().resolveTarget();
31
- command = new FindCommand(listingEntity, resultEntity);
32
- if (node.conditions)
33
- await command.filter(node.conditions);
34
- if (node.next) {
35
- const join = await (0, command_helper_1.joinAssociationGetLast)(command._joins, node.next, command.mainAlias);
36
- command.resultAlias = join.joinAlias;
37
- }
38
- }
39
- else {
40
- listingEntity = source;
41
- command = new FindCommand(listingEntity, listingEntity);
42
- }
43
- if (!listingEntity.tableName)
44
- throw new Error(`${listingEntity.ctor.name} is not decorated with @Entity decorator`);
45
- if (typeof opts.maxSubQueries === 'number')
46
- command.maxSubQueries = opts.maxSubQueries;
47
- if (typeof opts.maxEagerFetch === 'number')
48
- command.maxEagerFetch = opts.maxEagerFetch;
49
- return command;
50
- }
51
- static async execute(args) {
52
- const command = await FindCommand.create(args.entity, {
53
- maxSubQueries: args.maxSubQueries,
54
- maxEagerFetch: args.maxEagerFetch,
55
- });
56
- await command.addElements({
57
- elements: args.elements,
58
- include: args.include,
59
- exclude: args.exclude,
60
- sort: args.sort
61
- });
62
- if (args.filter)
63
- await command.filter(args.filter);
64
- if (args.sort)
65
- await command.sort(args.sort);
66
- return await command.execute(args);
67
- }
68
- async addElements(opts = {}) {
69
- const tableAlias = opts.tableAlias || this.resultAlias;
70
- const entity = opts.entity || this._getEntityFromAlias(tableAlias);
71
- const converter = opts.converter || this.converter;
72
- const _elements = opts.elements ?
73
- opts.elements.map(x => x.toLowerCase()) : undefined;
74
- const _include = opts.include ?
75
- opts.include.map(x => x.toLowerCase()) : undefined;
76
- const _exclude = opts.exclude ?
77
- opts.exclude.map(x => x.toLowerCase()) : undefined;
78
- const requestElements = _elements ? [..._elements] :
79
- (0, base_entity_class_1.getNonAssociationElementNames)(entity.ctor)
80
- .map(x => x.toLowerCase());
81
- if (_include)
82
- requestElements.push(..._include);
83
- const sortElements = opts.sort && opts.sort.length ?
84
- opts.sort.map(x => x.toLowerCase()) : undefined;
85
- const prefix = opts.prefix || '';
86
- const suffix = opts.suffix || '';
87
- for (const key of entity.elementKeys) {
88
- const col = entity.getElement(key);
89
- if (!col)
90
- continue;
91
- const colNameLower = col.name.toLowerCase();
92
- // Ignore element if in excluded list
93
- if (_exclude && _exclude.includes(colNameLower))
94
- continue;
95
- // Check if element request list
96
- if (!requestElements.find((x) => x === colNameLower || x.startsWith(colNameLower + '.')))
97
- continue;
98
- // Add field to select list if element is a column
99
- if ((0, orm_helper_1.isColumnElement)(col)) {
100
- const fieldAlias = this._selectColumn(tableAlias, col, prefix, suffix);
101
- // Add column to converter
102
- if (!col.hidden)
103
- converter.addValueProperty({
104
- name: col.name,
105
- fieldAlias,
106
- dataType: col.dataType,
107
- parse: col.parse
108
- });
109
- continue;
110
- }
111
- if ((0, orm_helper_1.isObjectElement)(col)) {
112
- const typ = await col.resolveType();
113
- const subConverter = converter.addObjectProperty({
114
- name: col.name,
115
- type: typ.ctor
116
- }).converter;
117
- await this.addElements({
118
- tableAlias,
119
- converter: subConverter,
120
- entity: typ,
121
- prefix: col.fieldNamePrefix,
122
- suffix: col.fieldNameSuffix,
123
- elements: _elements?.includes(colNameLower) ? undefined :
124
- extractSubElements(colNameLower, _elements),
125
- include: extractSubElements(colNameLower, _include),
126
- exclude: extractSubElements(colNameLower, _exclude),
127
- sort: extractSubElements(colNameLower, sortElements),
128
- });
129
- continue;
130
- }
131
- if ((0, orm_helper_1.isAssociationElement)(col)) {
132
- // OtO relation
133
- if (!col.association.returnsMany()) {
134
- const joinInfo = await (0, command_helper_1.joinAssociationGetLast)(this._joins, col.association, tableAlias);
135
- const subConverter = converter.addObjectProperty({
136
- name: col.name,
137
- type: joinInfo.targetEntity.ctor
138
- }).converter;
139
- // Add join fields to select columns list
140
- await this.addElements({
141
- tableAlias: joinInfo.joinAlias,
142
- converter: subConverter,
143
- entity: joinInfo.targetEntity,
144
- elements: _elements?.includes(colNameLower) ? undefined :
145
- extractSubElements(colNameLower, _elements),
146
- include: extractSubElements(colNameLower, _include),
147
- exclude: extractSubElements(colNameLower, _exclude),
148
- sort: extractSubElements(colNameLower, sortElements),
149
- });
150
- continue;
151
- }
152
- // One-2-Many Eager relation
153
- if (this.maxSubQueries > 0) {
154
- const targetCol = await col.association.resolveTargetProperty();
155
- const sourceCol = await col.association.resolveSourceProperty();
156
- // We need to know key value to filter sub query.
157
- // So add key field into select columns
158
- const parentField = this._selectColumn(tableAlias, sourceCol);
159
- const findCommand = await FindCommand.create(col.association, {
160
- maxSubQueries: this.maxSubQueries - 1,
161
- maxEagerFetch: this.maxEagerFetch
162
- });
163
- await findCommand.filter((0, builder_1.In)(targetCol.name, (0, builder_1.Param)(parentField)));
164
- const sort = sortElements && extractSubElements(colNameLower, sortElements);
165
- await findCommand.addElements({
166
- elements: _elements?.includes(colNameLower) ? undefined :
167
- extractSubElements(colNameLower, _elements),
168
- include: extractSubElements(colNameLower, _include),
169
- exclude: extractSubElements(colNameLower, _exclude),
170
- sort,
171
- });
172
- if (sort)
173
- await findCommand.sort(sort);
174
- const keyField = findCommand._selectColumn(findCommand.mainAlias, targetCol);
175
- const resultType = await col.association.getLast().resolveTarget();
176
- converter.addNestedProperty({
177
- name: col.name,
178
- type: resultType.ctor,
179
- findCommand,
180
- parentField,
181
- keyField,
182
- sort: extractSubElements(colNameLower, sortElements)
183
- });
184
- }
185
- }
186
- }
187
- }
188
- _selectColumn(tableAlias, el, prefix, suffix) {
189
- const fieldName = (prefix || '').toLowerCase() +
190
- el.fieldName.toUpperCase() +
191
- (suffix || '').toLowerCase();
192
- const fieldAlias = tableAlias + '_' + fieldName;
193
- this._selectColumns[fieldAlias] = {
194
- element: el,
195
- statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias
196
- };
197
- return fieldAlias;
198
- }
199
- async filter(filter) {
200
- await (0, command_helper_1.prepareFilter)(this.mainEntity, filter, this._filter);
201
- }
202
- async sort(sortElements) {
203
- const orderColumns = [];
204
- for (const item of sortElements) {
205
- const m = item.match(SORT_ORDER_PATTERN);
206
- if (!m)
207
- throw new Error(`"${item}" is not a valid order expression`);
208
- let elName = m[2];
209
- let prefix = '';
210
- let suffix = '';
211
- let _entityDef = this.resultEntity;
212
- let tableAlias = this.resultAlias;
213
- if (elName.includes('.')) {
214
- const a = elName.split('.');
215
- while (a.length > 1) {
216
- const col = _entityDef.getElement(a.shift() || '');
217
- if ((0, orm_helper_1.isObjectElement)(col)) {
218
- _entityDef = await col.resolveType();
219
- if (col.fieldNamePrefix)
220
- prefix += col.fieldNamePrefix;
221
- if (col.fieldNameSuffix)
222
- suffix = col.fieldNameSuffix + suffix;
223
- }
224
- else if ((0, orm_helper_1.isAssociationElement)(col)) {
225
- if (col.association.returnsMany()) {
226
- elName = '';
227
- break;
228
- }
229
- const joinInfo = await (0, command_helper_1.joinAssociationGetLast)(this._joins, col.association, tableAlias);
230
- tableAlias = joinInfo.joinAlias;
231
- _entityDef = joinInfo.targetEntity;
232
- }
233
- else
234
- throw new Error(`Invalid column (${elName}) declared in sort property`);
235
- }
236
- if (!elName)
237
- continue;
238
- elName = a.shift() || '';
239
- }
240
- const col = _entityDef.getElement(elName);
241
- if (!col)
242
- throw new Error(`Unknown element (${elName}) declared in sort property`);
243
- if (!(0, orm_helper_1.isColumnElement)(col))
244
- throw new Error(`Can not sort by "${elName}", because it is not a data column`);
245
- const dir = m[1] || '+';
246
- orderColumns.push((dir || '') + tableAlias + '.' + prefix + col.fieldName + suffix);
247
- }
248
- this._sort = orderColumns;
249
- }
250
- async execute(args) {
251
- // Generate select query
252
- const columnSqls = Object.keys(this._selectColumns)
253
- .map(x => this._selectColumns[x].statement);
254
- if (!columnSqls.length)
255
- columnSqls.push('1');
256
- const query = (0, builder_1.Select)(...columnSqls)
257
- .from(this.mainEntity.tableName + ' as ' + this.mainAlias);
258
- if (args.distinct)
259
- query.distinct();
260
- query.where(...this._filter._items);
261
- if (this._sort) {
262
- query.orderBy(...this._sort);
263
- }
264
- if (args.offset)
265
- query.offset(args.offset);
266
- // joins must be added last
267
- if (this._joins)
268
- for (const j of this._joins) {
269
- query.join(j.join);
270
- }
271
- // Execute query
272
- const resp = await args.connection.execute(query, {
273
- params: args?.params,
274
- fetchRows: args?.limit,
275
- objectRows: false,
276
- cursor: false
277
- });
278
- // Create objects
279
- if (resp.rows && resp.fields) {
280
- return this.converter.transform(args.connection, resp.fields, resp.rows, args.onTransformRow);
281
- }
282
- return [];
283
- }
284
- _getEntityFromAlias(tableAlias) {
285
- if (tableAlias === this.mainAlias)
286
- return this.mainEntity;
287
- if (tableAlias === this.resultAlias)
288
- return this.resultEntity;
289
- if (this._joins) {
290
- const join = this._joins.find(j => j.joinAlias === tableAlias);
291
- if (join)
292
- return join.targetEntity;
293
- }
294
- throw new Error(`Unknown table alias "${tableAlias}"`);
295
- }
296
- }
297
- exports.FindCommand = FindCommand;
298
- function extractSubElements(colNameLower, elements) {
299
- if (!(elements && elements.length))
300
- return;
301
- if (elements) {
302
- return elements.reduce((trg, v) => {
303
- if (v.startsWith(colNameLower + '.'))
304
- trg.push(v.substring(colNameLower.length + 1).toLowerCase());
305
- return trg;
306
- }, []);
307
- }
308
- }
@@ -1,55 +0,0 @@
1
- import { Type } from 'ts-gems';
2
- import type { FieldInfoMap } from '../../client/FieldInfoMap';
3
- import type { FindCommand } from './find.command';
4
- import type { Repository } from '../repository.class';
5
- import { ColumnTransformFunction } from '../orm.type';
6
- import { SqbConnection } from '../../client/SqbConnection';
7
- import { DataType } from '@sqb/builder';
8
- export interface ValueProperty {
9
- fieldAlias: string;
10
- dataType?: DataType;
11
- parse?: ColumnTransformFunction;
12
- }
13
- export interface ObjectProperty {
14
- converter: RowConverter;
15
- type: Type;
16
- }
17
- export interface NestedProperty {
18
- converter: RowConverter;
19
- type: Type;
20
- parentField: string;
21
- keyField: string;
22
- findCommand: FindCommand;
23
- sort?: string[];
24
- paramValues: any[];
25
- }
26
- export declare class RowConverter {
27
- resultType: Type;
28
- parent?: RowConverter | undefined;
29
- private _properties;
30
- private _propertyKeys?;
31
- constructor(resultType: Type, parent?: RowConverter | undefined);
32
- addValueProperty(args: {
33
- name: string;
34
- fieldAlias: string;
35
- dataType?: DataType;
36
- parse?: ColumnTransformFunction;
37
- }): ValueProperty;
38
- addObjectProperty(args: {
39
- name: string;
40
- type: Type;
41
- }): ObjectProperty;
42
- addNestedProperty(args: {
43
- name: string;
44
- type: Type;
45
- findCommand: FindCommand;
46
- parentField: string;
47
- keyField: string;
48
- sort?: string[];
49
- }): NestedProperty;
50
- get keys(): string[];
51
- transform(connection: SqbConnection, fields: FieldInfoMap, rows: any, onTransform?: Repository.TransformRowFunction): Promise<any[]>;
52
- private _rowToObject;
53
- private _iterateForNested;
54
- private _checkCircularDep;
55
- }