orange-orm 4.4.0-beta.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/changelog.md +4 -0
- package/package.json +1 -1
- package/src/client/index.mjs +784 -373
- package/src/getManyDto.js +131 -89
- package/src/table/column/binary/newEncode.js +0 -3
- package/src/table/column/boolean/newEncode.js +0 -6
- package/src/table/column/date/newEncode.js +0 -6
- package/src/table/column/dateWithTimeZone/newEncode.js +0 -6
- package/src/table/column/guid/newEncode.js +1 -7
- package/src/table/column/json/newEncode.js +1 -7
- package/src/table/column/numeric/newEncode.js +0 -6
- package/src/table/column/string/newEncode.js +0 -6
- package/getManyDto4.js +0 -313
- package/getManyDtoFast.js +0 -530
- package/src/getManyDtoFast2.js +0 -293
- package/src/getManyDtoFastes.js +0 -588
- package/src/table/getManyDtoFast3.js +0 -313
package/src/getManyDto.js
CHANGED
|
@@ -4,7 +4,7 @@ const negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
|
|
|
4
4
|
const strategyToSpan = require('./table/strategyToSpan');
|
|
5
5
|
const executeQueries = require('./table/executeQueries');
|
|
6
6
|
|
|
7
|
-
async function getManyDto(table, filter, strategy, spanFromParent) {
|
|
7
|
+
async function getManyDto(table, filter, strategy, spanFromParent, updateParent) {
|
|
8
8
|
filter = negotiateRawSqlFilter(filter, table);
|
|
9
9
|
if (strategy && strategy.where) {
|
|
10
10
|
let arg = typeof strategy.where === 'function' ? strategy.where(table) : strategy.where;
|
|
@@ -16,95 +16,122 @@ async function getManyDto(table, filter, strategy, spanFromParent) {
|
|
|
16
16
|
|
|
17
17
|
const query = newQuery(table, filter, span, alias);
|
|
18
18
|
const res = await executeQueries([query]);
|
|
19
|
-
return decode(strategy, span, await res[0]);
|
|
19
|
+
return decode(strategy, span, await res[0], undefined, updateParent);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// function newCreateRow(span) {
|
|
23
|
-
// let columnsMap = span.columns;
|
|
24
|
-
// const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
25
|
-
// const protoRow = createProto(columns, span);
|
|
26
|
-
// const manyNames = [];
|
|
27
|
-
|
|
28
|
-
// const c = {};
|
|
29
|
-
// c.visitJoin = () => { };
|
|
30
|
-
// c.visitOne = () => { };
|
|
31
|
-
// c.visitMany = function(leg) {
|
|
32
|
-
// manyNames.push(leg.name);
|
|
33
|
-
// };
|
|
34
|
-
|
|
35
|
-
// span.legs.forEach(onEachLeg);
|
|
36
|
-
// return createRow;
|
|
37
|
-
|
|
38
|
-
// function onEachLeg(leg) {
|
|
39
|
-
// leg.accept(c);
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// function createRow() {
|
|
43
|
-
// const obj = Object.create(protoRow);
|
|
44
|
-
// for (let i = 0; i < manyNames.length; i++) {
|
|
45
|
-
// obj[manyNames[i]] = [];
|
|
46
|
-
// }
|
|
47
|
-
// return obj;
|
|
48
|
-
// }
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
|
|
52
22
|
function newCreateRow(span) {
|
|
53
|
-
|
|
23
|
+
let columnsMap = span.columns;
|
|
54
24
|
const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
55
|
-
const
|
|
25
|
+
const protoRow = createProto(columns, span);
|
|
56
26
|
const manyNames = [];
|
|
57
27
|
|
|
58
|
-
const c = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
28
|
+
const c = {};
|
|
29
|
+
c.visitJoin = () => { };
|
|
30
|
+
c.visitOne = () => { };
|
|
31
|
+
c.visitMany = function(leg) {
|
|
32
|
+
manyNames.push(leg.name);
|
|
64
33
|
};
|
|
65
34
|
|
|
66
|
-
span.legs.forEach(
|
|
67
|
-
|
|
35
|
+
span.legs.forEach(onEachLeg);
|
|
68
36
|
return createRow;
|
|
69
37
|
|
|
38
|
+
function onEachLeg(leg) {
|
|
39
|
+
leg.accept(c);
|
|
40
|
+
}
|
|
41
|
+
|
|
70
42
|
function createRow() {
|
|
71
|
-
const obj =
|
|
72
|
-
manyNames.
|
|
73
|
-
obj[
|
|
74
|
-
}
|
|
43
|
+
const obj = Object.create(protoRow);
|
|
44
|
+
for (let i = 0; i < manyNames.length; i++) {
|
|
45
|
+
obj[manyNames[i]] = [];
|
|
46
|
+
}
|
|
75
47
|
return obj;
|
|
76
48
|
}
|
|
77
49
|
}
|
|
78
50
|
|
|
79
51
|
function createProto(columns, span) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
52
|
+
let obj = {};
|
|
53
|
+
for (let i = 0; i < columns.length; i++) {
|
|
54
|
+
obj[columns[i].alias] = null;
|
|
55
|
+
}
|
|
56
|
+
for (let key in span.aggregates) {
|
|
57
|
+
obj[key] = null;
|
|
58
|
+
}
|
|
59
|
+
const c = {};
|
|
84
60
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
c.visitJoin = function(leg) {
|
|
62
|
+
obj[leg.name] = null;
|
|
63
|
+
};
|
|
64
|
+
c.visitOne = c.visitJoin;
|
|
65
|
+
c.visitMany = function(leg) {
|
|
66
|
+
obj[leg.name] = null;
|
|
67
|
+
};
|
|
88
68
|
|
|
89
|
-
|
|
90
|
-
visitJoin: (leg) => {
|
|
91
|
-
this[leg.name] = null;
|
|
92
|
-
},
|
|
93
|
-
visitOne: (leg) => {
|
|
94
|
-
this[leg.name] = null;
|
|
95
|
-
},
|
|
96
|
-
visitMany: (leg) => {
|
|
97
|
-
this[leg.name] = null;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
69
|
+
span.legs.forEach(onEachLeg);
|
|
100
70
|
|
|
101
|
-
|
|
71
|
+
function onEachLeg(leg) {
|
|
72
|
+
leg.accept(c);
|
|
102
73
|
}
|
|
103
74
|
|
|
104
|
-
return
|
|
75
|
+
return obj;
|
|
105
76
|
}
|
|
106
77
|
|
|
107
78
|
|
|
79
|
+
// function newCreateRow(span) {
|
|
80
|
+
// const columnsMap = span.columns;
|
|
81
|
+
// const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
82
|
+
// const ProtoRow = createProto(columns, span);
|
|
83
|
+
// const manyNames = [];
|
|
84
|
+
|
|
85
|
+
// const c = {
|
|
86
|
+
// visitJoin: () => { },
|
|
87
|
+
// visitOne: () => { },
|
|
88
|
+
// visitMany: function(leg) {
|
|
89
|
+
// manyNames.push(leg.name);
|
|
90
|
+
// }
|
|
91
|
+
// };
|
|
92
|
+
|
|
93
|
+
// span.legs.forEach(leg => leg.accept(c));
|
|
94
|
+
|
|
95
|
+
// return createRow;
|
|
96
|
+
|
|
97
|
+
// function createRow() {
|
|
98
|
+
// const obj = new ProtoRow();
|
|
99
|
+
// manyNames.forEach(name => {
|
|
100
|
+
// obj[name] = [];
|
|
101
|
+
// });
|
|
102
|
+
// return obj;
|
|
103
|
+
// }
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
// function createProto(columns, span) {
|
|
107
|
+
// function ProtoRow() {
|
|
108
|
+
// columns.forEach(column => {
|
|
109
|
+
// this[column.alias] = null;
|
|
110
|
+
// });
|
|
111
|
+
|
|
112
|
+
// for (const key in span.aggregates) {
|
|
113
|
+
// this[key] = null;
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// const c = {
|
|
117
|
+
// visitJoin: (leg) => {
|
|
118
|
+
// this[leg.name] = null;
|
|
119
|
+
// },
|
|
120
|
+
// visitOne: (leg) => {
|
|
121
|
+
// this[leg.name] = null;
|
|
122
|
+
// },
|
|
123
|
+
// visitMany: (leg) => {
|
|
124
|
+
// this[leg.name] = null;
|
|
125
|
+
// }
|
|
126
|
+
// };
|
|
127
|
+
|
|
128
|
+
// span.legs.forEach(leg => leg.accept(c));
|
|
129
|
+
// }
|
|
130
|
+
|
|
131
|
+
// return ProtoRow;
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
|
|
108
135
|
function hasManyRelations(span) {
|
|
109
136
|
let result;
|
|
110
137
|
const c = {};
|
|
@@ -122,7 +149,7 @@ function hasManyRelations(span) {
|
|
|
122
149
|
}
|
|
123
150
|
}
|
|
124
151
|
|
|
125
|
-
async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [],
|
|
152
|
+
async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
126
153
|
const table = span.table;
|
|
127
154
|
let columnsMap = span.columns;
|
|
128
155
|
const columns = table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -162,8 +189,10 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
162
189
|
}
|
|
163
190
|
|
|
164
191
|
outRows[i] = outRow;
|
|
165
|
-
if (parentRows)
|
|
166
|
-
|
|
192
|
+
// if (parentRows)
|
|
193
|
+
// parentRows[i][parentProp] = outRow;
|
|
194
|
+
if (updateParent)
|
|
195
|
+
updateParent(outRow, i);
|
|
167
196
|
if (shouldCreateMap) {
|
|
168
197
|
fkIds[i] = getIds(outRow);
|
|
169
198
|
addToMap(rowsMap, fkIds[i], outRow);
|
|
@@ -178,8 +207,12 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
178
207
|
|
|
179
208
|
const all = [];
|
|
180
209
|
|
|
181
|
-
if (shouldCreateMap)
|
|
182
|
-
all.push(decodeManyRelations(strategy, span)
|
|
210
|
+
if (shouldCreateMap) {
|
|
211
|
+
all.push(decodeManyRelations(strategy, span));
|
|
212
|
+
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
213
|
+
}
|
|
214
|
+
// decodeRelations2(strategy, span, rows, outRows, keys);
|
|
215
|
+
// }
|
|
183
216
|
else
|
|
184
217
|
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
185
218
|
|
|
@@ -222,13 +255,22 @@ async function decodeManyRelations(strategy, span) {
|
|
|
222
255
|
const filter = createOneFilter(relation, span._ids);
|
|
223
256
|
const extractKey = createExtractKey(leg);
|
|
224
257
|
const extractFromMap = createExtractFromMap(rowsMap, table._primaryColumns);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
258
|
+
|
|
259
|
+
const p = getManyDto(relation.childTable, filter, strategy[name], leg.span, updateParent);
|
|
260
|
+
// .then(subRows => {
|
|
261
|
+
// for (let i = 0; i < subRows.length; i++) {
|
|
262
|
+
// const key = extractKey(subRows[i]);
|
|
263
|
+
// const parentRow = extractFromMap(key);
|
|
264
|
+
// parentRow[name].push(subRows[i]);
|
|
265
|
+
// }
|
|
266
|
+
// });
|
|
267
|
+
|
|
268
|
+
function updateParent(subRow) {
|
|
269
|
+
const key = extractKey(subRow);
|
|
270
|
+
const parentRow = extractFromMap(key);
|
|
271
|
+
parentRow[name].push(subRow);
|
|
272
|
+
}
|
|
273
|
+
|
|
232
274
|
promises.push(p);
|
|
233
275
|
};
|
|
234
276
|
|
|
@@ -257,28 +299,28 @@ async function decodeManyRelations(strategy, span) {
|
|
|
257
299
|
|
|
258
300
|
await Promise.all(promises);
|
|
259
301
|
}
|
|
260
|
-
|
|
261
302
|
async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
262
|
-
const promises = [];
|
|
263
303
|
const c = {};
|
|
264
304
|
c.visitJoin = function(leg) {
|
|
265
305
|
const name = leg.name;
|
|
266
|
-
|
|
267
|
-
|
|
306
|
+
return decode(strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
|
+
|
|
308
|
+
function updateParent(subRow, i) {
|
|
309
|
+
resultRows[i][name] = subRow;
|
|
310
|
+
|
|
311
|
+
}
|
|
268
312
|
};
|
|
269
313
|
|
|
270
314
|
c.visitOne = c.visitJoin;
|
|
271
|
-
|
|
272
315
|
c.visitMany = () => { };
|
|
273
316
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
leg.accept(c);
|
|
317
|
+
async function processLegsSequentially(legs) {
|
|
318
|
+
for (const leg of legs.toArray()) {
|
|
319
|
+
await leg.accept(c);
|
|
320
|
+
}
|
|
279
321
|
}
|
|
280
322
|
|
|
281
|
-
await
|
|
323
|
+
await processLegsSequentially(span.legs);
|
|
282
324
|
}
|
|
283
325
|
|
|
284
326
|
function createOneFilter(relation, ids) {
|
|
@@ -31,12 +31,6 @@ function _new(column) {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
encode.direct = function(value) {
|
|
34
|
-
value = purify(value);
|
|
35
|
-
if (value === null) {
|
|
36
|
-
if (column.dbNull === null)
|
|
37
|
-
return null;
|
|
38
|
-
return column.dbNull ;
|
|
39
|
-
}
|
|
40
34
|
var encodeCore = getSessionSingleton('encodeBoolean');
|
|
41
35
|
|
|
42
36
|
return encodeCore(value);
|
|
@@ -29,12 +29,6 @@ function _new(column) {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
encode.direct = function(value) {
|
|
32
|
-
value = purify(value);
|
|
33
|
-
if (value == null) {
|
|
34
|
-
if (column.dbNull === null)
|
|
35
|
-
null;
|
|
36
|
-
return column.dbNull;
|
|
37
|
-
}
|
|
38
32
|
var encodeCore = getSessionSingleton('encodeDate') || encodeDate;
|
|
39
33
|
return encodeCore(value);
|
|
40
34
|
};
|
|
@@ -23,13 +23,7 @@ function _new(column) {
|
|
|
23
23
|
return '\'' + value + '\'';
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
encode.direct = function(
|
|
27
|
-
var value = purify(candidate);
|
|
28
|
-
if (value == null) {
|
|
29
|
-
if (column.dbNull === null)
|
|
30
|
-
return null;
|
|
31
|
-
return column.dbNull;
|
|
32
|
-
}
|
|
26
|
+
encode.direct = function(value) {
|
|
33
27
|
return value ;
|
|
34
28
|
};
|
|
35
29
|
|
|
@@ -35,13 +35,7 @@ function _new(column) {
|
|
|
35
35
|
return value;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
encode.direct = function(
|
|
39
|
-
var value = purify(candidate);
|
|
40
|
-
if (value == null) {
|
|
41
|
-
if(column.dbNull === null)
|
|
42
|
-
return null;
|
|
43
|
-
return column.dbNull;
|
|
44
|
-
}
|
|
38
|
+
encode.direct = function(value) {
|
|
45
39
|
var encodeCore = getSessionSingleton('encodeJSON');
|
|
46
40
|
|
|
47
41
|
if (encodeCore) {
|