orange-orm 4.3.0-beta.1 → 4.3.0-beta.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/getManyDto.js +83 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.3.0-beta.1",
3
+ "version": "4.3.0-beta.2",
4
4
  "main": "./src/index.js",
5
5
  "browser": "./src/client/index.mjs",
6
6
  "bin": {
package/src/getManyDto.js CHANGED
@@ -128,7 +128,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
128
128
  for (let j = 0; j < aggregateKeys.length; j++) {
129
129
  const key = aggregateKeys[j];
130
130
  const parse = span.aggregates[key].column?.decode || Number.parseFloat;
131
- outRow[key] = parse(row[keys[j+columnsLength]]);
131
+ outRow[key] = parse(row[keys[j + columnsLength]]);
132
132
  }
133
133
 
134
134
  outRows[i] = outRow;
@@ -141,8 +141,18 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
141
141
  span._ids = fkIds;
142
142
 
143
143
  keys.splice(0, columnsLength + aggregateKeys.length);
144
+ if (span.legs.toArray().length === 0)
145
+ return outRows;
146
+
147
+ const all = [];
148
+
149
+ if (shouldCreateMap)
150
+ all.push(decodeManyRelations(strategy, span).then(() => decodeRelations2(strategy, span, rows, outRows, keys)));
151
+ else
152
+ all.push(decodeRelations2(strategy, span, rows, outRows, keys));
153
+
154
+ await Promise.all(all);
144
155
 
145
- await decodeRelations(strategy, span, rows, outRows, keys);
146
156
  return outRows;
147
157
 
148
158
 
@@ -165,19 +175,10 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
165
175
 
166
176
  }
167
177
 
168
- async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
178
+ async function decodeManyRelations(strategy, span) {
169
179
  const promises = [];
170
180
  const c = {};
171
- c.visitJoin = function(leg) {
172
- const name = leg.name;
173
- const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
174
- for (let i = 0; i < rows.length; i++) {
175
- resultRows[i][name] = rows[i];
176
- }
177
- });
178
- promises.push(p);
179
- };
180
-
181
+ c.visitJoin = () => { };
181
182
  c.visitOne = c.visitJoin;
182
183
 
183
184
  c.visitMany = function(leg) {
@@ -205,6 +206,74 @@ async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
205
206
  await Promise.all(promises);
206
207
  }
207
208
 
209
+ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
210
+ const promises = [];
211
+ const c = {};
212
+ c.visitJoin = function (leg) {
213
+ const name = leg.name;
214
+ const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
215
+ for (let i = 0; i < rows.length; i++) {
216
+ resultRows[i][name] = rows[i];
217
+ }
218
+ });
219
+ promises.push(p);
220
+ };
221
+
222
+ c.visitOne = c.visitJoin;
223
+
224
+ c.visitMany = () => { };
225
+
226
+
227
+ span.legs.forEach(onEachLeg);
228
+
229
+ function onEachLeg(leg) {
230
+ leg.accept(c);
231
+ }
232
+
233
+ await Promise.all(promises);
234
+ }
235
+
236
+
237
+ // async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
238
+ // const promises = [];
239
+ // const c = {};
240
+ // c.visitJoin = function (leg) {
241
+ // const name = leg.name;
242
+ // const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
243
+ // for (let i = 0; i < rows.length; i++) {
244
+ // resultRows[i][name] = rows[i];
245
+ // }
246
+ // });
247
+ // promises.push(p);
248
+ // };
249
+
250
+ // c.visitOne = c.visitJoin;
251
+
252
+ // c.visitMany = function (leg) {
253
+ // const name = leg.name;
254
+ // const table = span.table;
255
+ // const relation = table._relations[name];
256
+ // const filter = createOneFilter(relation, span._ids);
257
+ // const rowsMap = span._rowsMap;
258
+ // const p = getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => {
259
+ // for (let i = 0; i < subRows.length; i++) {
260
+ // const key = leg.columns.map(column => subRows[i][column.alias]);
261
+ // const parentRow = getFromMap(rowsMap, table._primaryColumns, key);
262
+ // parentRow[name].push(subRows[i]);
263
+ // }
264
+ // });
265
+ // promises.push(p);
266
+ // };
267
+
268
+ // span.legs.forEach(onEachLeg);
269
+
270
+ // function onEachLeg(leg) {
271
+ // leg.accept(c);
272
+ // }
273
+
274
+ // await Promise.all(promises);
275
+ // }
276
+
208
277
  function createOneFilter(relation, ids) {
209
278
  const columns = relation.joinRelation.columns;
210
279
 
@@ -216,7 +285,7 @@ function createOneFilter(relation, ids) {
216
285
 
217
286
  function createCompositeFilter() {
218
287
  let filter = emptyFilter;
219
- for(let id of ids) {
288
+ for (let id of ids) {
220
289
  let nextFilter;
221
290
  for (let i = 0; i < columns.length; i++) {
222
291
  if (nextFilter)