orange-orm 5.0.0-beta.7 → 5.0.0-beta.9
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/dist/index.browser.mjs +18 -4
- package/dist/index.mjs +87 -27
- package/package.json +1 -1
- package/src/getManyDto.js +18 -4
- package/src/tedious/wrapCommand.js +34 -11
- package/src/tedious/wrapQuery.js +36 -13
package/dist/index.browser.mjs
CHANGED
|
@@ -10994,6 +10994,8 @@ function requireGetManyDto$1 () {
|
|
|
10994
10994
|
}
|
|
10995
10995
|
|
|
10996
10996
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
10997
|
+
if (!spanFromParent)
|
|
10998
|
+
assignAliases(span, table._dbName);
|
|
10997
10999
|
let alias = table._dbName;
|
|
10998
11000
|
|
|
10999
11001
|
const query = newQuery(context, table, filter, span, alias);
|
|
@@ -11001,6 +11003,13 @@ function requireGetManyDto$1 () {
|
|
|
11001
11003
|
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
11002
11004
|
}
|
|
11003
11005
|
|
|
11006
|
+
function assignAliases(span, alias) {
|
|
11007
|
+
span._alias = alias;
|
|
11008
|
+
span.legs.forEach((leg) => {
|
|
11009
|
+
assignAliases(leg.span, alias + leg.name);
|
|
11010
|
+
});
|
|
11011
|
+
}
|
|
11012
|
+
|
|
11004
11013
|
function newCreateRow(span) {
|
|
11005
11014
|
let columnsMap = span.columns;
|
|
11006
11015
|
const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -11086,6 +11095,8 @@ function requireGetManyDto$1 () {
|
|
|
11086
11095
|
const fkIds = new Array(rows.length);
|
|
11087
11096
|
const getIds = createGetIds();
|
|
11088
11097
|
const aggregateKeys = Object.keys(span.aggregates);
|
|
11098
|
+
const aliasPrefix = span._alias ? 's' + span._alias : null;
|
|
11099
|
+
const useAlias = aliasPrefix && rowsLength > 0 && Object.prototype.hasOwnProperty.call(rows[0], aliasPrefix + '0');
|
|
11089
11100
|
|
|
11090
11101
|
const outRows = new Array(rowsLength);
|
|
11091
11102
|
const createRow = newCreateRow(span);
|
|
@@ -11095,8 +11106,9 @@ function requireGetManyDto$1 () {
|
|
|
11095
11106
|
let outRow = createRow();
|
|
11096
11107
|
let pkWithNullCount = 0;
|
|
11097
11108
|
for (let j = 0; j < columnsLength; j++) {
|
|
11109
|
+
const key = useAlias ? (aliasPrefix + j) : keys[j];
|
|
11098
11110
|
if (j < primaryColumnsLength) {
|
|
11099
|
-
if (row[
|
|
11111
|
+
if (row[key] === null)
|
|
11100
11112
|
pkWithNullCount++;
|
|
11101
11113
|
if (pkWithNullCount === primaryColumnsLength) {
|
|
11102
11114
|
outRow = null;
|
|
@@ -11104,13 +11116,14 @@ function requireGetManyDto$1 () {
|
|
|
11104
11116
|
}
|
|
11105
11117
|
}
|
|
11106
11118
|
const column = columns[j];
|
|
11107
|
-
outRow[column.alias] = column.decode(context, row[
|
|
11119
|
+
outRow[column.alias] = column.decode(context, row[key]);
|
|
11108
11120
|
}
|
|
11109
11121
|
|
|
11110
11122
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
11111
11123
|
const key = aggregateKeys[j];
|
|
11112
11124
|
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
11113
|
-
|
|
11125
|
+
const value = useAlias ? row[key] : row[keys[j + columnsLength]];
|
|
11126
|
+
outRow[key] = parse(context, value);
|
|
11114
11127
|
}
|
|
11115
11128
|
|
|
11116
11129
|
outRows[i] = outRow;
|
|
@@ -11124,7 +11137,8 @@ function requireGetManyDto$1 () {
|
|
|
11124
11137
|
span._rowsMap = rowsMap;
|
|
11125
11138
|
span._ids = fkIds;
|
|
11126
11139
|
|
|
11127
|
-
|
|
11140
|
+
if (!useAlias)
|
|
11141
|
+
keys.splice(0, columnsLength + aggregateKeys.length);
|
|
11128
11142
|
if (span.legs.toArray().length === 0)
|
|
11129
11143
|
return outRows;
|
|
11130
11144
|
|
package/dist/index.mjs
CHANGED
|
@@ -10995,6 +10995,8 @@ function requireGetManyDto$1 () {
|
|
|
10995
10995
|
}
|
|
10996
10996
|
|
|
10997
10997
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
10998
|
+
if (!spanFromParent)
|
|
10999
|
+
assignAliases(span, table._dbName);
|
|
10998
11000
|
let alias = table._dbName;
|
|
10999
11001
|
|
|
11000
11002
|
const query = newQuery(context, table, filter, span, alias);
|
|
@@ -11002,6 +11004,13 @@ function requireGetManyDto$1 () {
|
|
|
11002
11004
|
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
11003
11005
|
}
|
|
11004
11006
|
|
|
11007
|
+
function assignAliases(span, alias) {
|
|
11008
|
+
span._alias = alias;
|
|
11009
|
+
span.legs.forEach((leg) => {
|
|
11010
|
+
assignAliases(leg.span, alias + leg.name);
|
|
11011
|
+
});
|
|
11012
|
+
}
|
|
11013
|
+
|
|
11005
11014
|
function newCreateRow(span) {
|
|
11006
11015
|
let columnsMap = span.columns;
|
|
11007
11016
|
const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -11087,6 +11096,8 @@ function requireGetManyDto$1 () {
|
|
|
11087
11096
|
const fkIds = new Array(rows.length);
|
|
11088
11097
|
const getIds = createGetIds();
|
|
11089
11098
|
const aggregateKeys = Object.keys(span.aggregates);
|
|
11099
|
+
const aliasPrefix = span._alias ? 's' + span._alias : null;
|
|
11100
|
+
const useAlias = aliasPrefix && rowsLength > 0 && Object.prototype.hasOwnProperty.call(rows[0], aliasPrefix + '0');
|
|
11090
11101
|
|
|
11091
11102
|
const outRows = new Array(rowsLength);
|
|
11092
11103
|
const createRow = newCreateRow(span);
|
|
@@ -11096,8 +11107,9 @@ function requireGetManyDto$1 () {
|
|
|
11096
11107
|
let outRow = createRow();
|
|
11097
11108
|
let pkWithNullCount = 0;
|
|
11098
11109
|
for (let j = 0; j < columnsLength; j++) {
|
|
11110
|
+
const key = useAlias ? (aliasPrefix + j) : keys[j];
|
|
11099
11111
|
if (j < primaryColumnsLength) {
|
|
11100
|
-
if (row[
|
|
11112
|
+
if (row[key] === null)
|
|
11101
11113
|
pkWithNullCount++;
|
|
11102
11114
|
if (pkWithNullCount === primaryColumnsLength) {
|
|
11103
11115
|
outRow = null;
|
|
@@ -11105,13 +11117,14 @@ function requireGetManyDto$1 () {
|
|
|
11105
11117
|
}
|
|
11106
11118
|
}
|
|
11107
11119
|
const column = columns[j];
|
|
11108
|
-
outRow[column.alias] = column.decode(context, row[
|
|
11120
|
+
outRow[column.alias] = column.decode(context, row[key]);
|
|
11109
11121
|
}
|
|
11110
11122
|
|
|
11111
11123
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
11112
11124
|
const key = aggregateKeys[j];
|
|
11113
11125
|
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
11114
|
-
|
|
11126
|
+
const value = useAlias ? row[key] : row[keys[j + columnsLength]];
|
|
11127
|
+
outRow[key] = parse(context, value);
|
|
11115
11128
|
}
|
|
11116
11129
|
|
|
11117
11130
|
outRows[i] = outRow;
|
|
@@ -11125,7 +11138,8 @@ function requireGetManyDto$1 () {
|
|
|
11125
11138
|
span._rowsMap = rowsMap;
|
|
11126
11139
|
span._ids = fkIds;
|
|
11127
11140
|
|
|
11128
|
-
|
|
11141
|
+
if (!useAlias)
|
|
11142
|
+
keys.splice(0, columnsLength + aggregateKeys.length);
|
|
11129
11143
|
if (span.legs.toArray().length === 0)
|
|
11130
11144
|
return outRows;
|
|
11131
11145
|
|
|
@@ -20267,18 +20281,28 @@ function requireWrapQuery$1 () {
|
|
|
20267
20281
|
return runQuery;
|
|
20268
20282
|
|
|
20269
20283
|
function runQuery(query, onCompleted) {
|
|
20270
|
-
|
|
20271
|
-
|
|
20272
|
-
|
|
20273
|
-
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
}
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20284
|
+
enqueue(function(done) {
|
|
20285
|
+
function safeCompleted(err, rows) {
|
|
20286
|
+
try {
|
|
20287
|
+
onCompleted(err, rows);
|
|
20288
|
+
} finally {
|
|
20289
|
+
done();
|
|
20290
|
+
}
|
|
20291
|
+
}
|
|
20292
|
+
|
|
20293
|
+
if (!CachedRequest || !CachedTypes) {
|
|
20294
|
+
import('tedious')
|
|
20295
|
+
.then(({ Request, TYPES }) => {
|
|
20296
|
+
CachedRequest = Request;
|
|
20297
|
+
CachedTypes = TYPES;
|
|
20298
|
+
doQuery(query, safeCompleted);
|
|
20299
|
+
})
|
|
20300
|
+
.catch(err => safeCompleted(extractError(err), []));
|
|
20301
|
+
}
|
|
20302
|
+
else {
|
|
20303
|
+
doQuery(query, safeCompleted);
|
|
20304
|
+
}
|
|
20305
|
+
});
|
|
20282
20306
|
}
|
|
20283
20307
|
|
|
20284
20308
|
function doQuery(query, onCompleted) {
|
|
@@ -20379,6 +20403,19 @@ function requireWrapQuery$1 () {
|
|
|
20379
20403
|
}
|
|
20380
20404
|
}
|
|
20381
20405
|
}
|
|
20406
|
+
|
|
20407
|
+
function enqueue(task) {
|
|
20408
|
+
if (!connection.__orangeOrmQueue)
|
|
20409
|
+
connection.__orangeOrmQueue = Promise.resolve();
|
|
20410
|
+
connection.__orangeOrmQueue = connection.__orangeOrmQueue.then(() => new Promise((resolve) => {
|
|
20411
|
+
try {
|
|
20412
|
+
task(resolve);
|
|
20413
|
+
}
|
|
20414
|
+
catch (_e) {
|
|
20415
|
+
resolve();
|
|
20416
|
+
}
|
|
20417
|
+
})).catch(() => {});
|
|
20418
|
+
}
|
|
20382
20419
|
}
|
|
20383
20420
|
|
|
20384
20421
|
// Helper functions remain the same
|
|
@@ -20458,17 +20495,27 @@ function requireWrapCommand$1 () {
|
|
|
20458
20495
|
return runQuery;
|
|
20459
20496
|
|
|
20460
20497
|
function runQuery(query, onCompleted) {
|
|
20461
|
-
|
|
20462
|
-
|
|
20463
|
-
|
|
20464
|
-
|
|
20465
|
-
|
|
20466
|
-
|
|
20467
|
-
}
|
|
20468
|
-
|
|
20469
|
-
|
|
20470
|
-
|
|
20471
|
-
|
|
20498
|
+
enqueue(function(done) {
|
|
20499
|
+
function safeCompleted(err, result) {
|
|
20500
|
+
try {
|
|
20501
|
+
onCompleted(err, result);
|
|
20502
|
+
} finally {
|
|
20503
|
+
done();
|
|
20504
|
+
}
|
|
20505
|
+
}
|
|
20506
|
+
|
|
20507
|
+
if (!CachedRequest || !CachedTypes) {
|
|
20508
|
+
import('tedious')
|
|
20509
|
+
.then(({ Request, TYPES }) => {
|
|
20510
|
+
CachedRequest = Request;
|
|
20511
|
+
CachedTypes = TYPES;
|
|
20512
|
+
doQuery(query, safeCompleted);
|
|
20513
|
+
})
|
|
20514
|
+
.catch((err) => safeCompleted(extractError(err), { rowsAffected: 0 }));
|
|
20515
|
+
} else {
|
|
20516
|
+
doQuery(query, safeCompleted);
|
|
20517
|
+
}
|
|
20518
|
+
});
|
|
20472
20519
|
}
|
|
20473
20520
|
|
|
20474
20521
|
function doQuery(query, onCompleted) {
|
|
@@ -20521,6 +20568,19 @@ function requireWrapCommand$1 () {
|
|
|
20521
20568
|
return onCompleted(null, { rowsAffected: affectedRows });
|
|
20522
20569
|
}
|
|
20523
20570
|
}
|
|
20571
|
+
|
|
20572
|
+
function enqueue(task) {
|
|
20573
|
+
if (!connection.__orangeOrmQueue)
|
|
20574
|
+
connection.__orangeOrmQueue = Promise.resolve();
|
|
20575
|
+
connection.__orangeOrmQueue = connection.__orangeOrmQueue.then(() => new Promise((resolve) => {
|
|
20576
|
+
try {
|
|
20577
|
+
task(resolve);
|
|
20578
|
+
}
|
|
20579
|
+
catch (_e) {
|
|
20580
|
+
resolve();
|
|
20581
|
+
}
|
|
20582
|
+
})).catch(() => {});
|
|
20583
|
+
}
|
|
20524
20584
|
}
|
|
20525
20585
|
|
|
20526
20586
|
function extractError(e) {
|
package/package.json
CHANGED
package/src/getManyDto.js
CHANGED
|
@@ -13,6 +13,8 @@ async function getManyDto(context, table, filter, strategy, spanFromParent, upda
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
16
|
+
if (!spanFromParent)
|
|
17
|
+
assignAliases(span, table._dbName);
|
|
16
18
|
let alias = table._dbName;
|
|
17
19
|
|
|
18
20
|
const query = newQuery(context, table, filter, span, alias);
|
|
@@ -20,6 +22,13 @@ async function getManyDto(context, table, filter, strategy, spanFromParent, upda
|
|
|
20
22
|
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
function assignAliases(span, alias) {
|
|
26
|
+
span._alias = alias;
|
|
27
|
+
span.legs.forEach((leg) => {
|
|
28
|
+
assignAliases(leg.span, alias + leg.name);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
function newCreateRow(span) {
|
|
24
33
|
let columnsMap = span.columns;
|
|
25
34
|
const columns = span.table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -105,6 +114,8 @@ async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Ob
|
|
|
105
114
|
const fkIds = new Array(rows.length);
|
|
106
115
|
const getIds = createGetIds();
|
|
107
116
|
const aggregateKeys = Object.keys(span.aggregates);
|
|
117
|
+
const aliasPrefix = span._alias ? 's' + span._alias : null;
|
|
118
|
+
const useAlias = aliasPrefix && rowsLength > 0 && Object.prototype.hasOwnProperty.call(rows[0], aliasPrefix + '0');
|
|
108
119
|
|
|
109
120
|
const outRows = new Array(rowsLength);
|
|
110
121
|
const createRow = newCreateRow(span);
|
|
@@ -114,8 +125,9 @@ async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Ob
|
|
|
114
125
|
let outRow = createRow();
|
|
115
126
|
let pkWithNullCount = 0;
|
|
116
127
|
for (let j = 0; j < columnsLength; j++) {
|
|
128
|
+
const key = useAlias ? (aliasPrefix + j) : keys[j];
|
|
117
129
|
if (j < primaryColumnsLength) {
|
|
118
|
-
if (row[
|
|
130
|
+
if (row[key] === null)
|
|
119
131
|
pkWithNullCount++;
|
|
120
132
|
if (pkWithNullCount === primaryColumnsLength) {
|
|
121
133
|
outRow = null;
|
|
@@ -123,13 +135,14 @@ async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Ob
|
|
|
123
135
|
}
|
|
124
136
|
}
|
|
125
137
|
const column = columns[j];
|
|
126
|
-
outRow[column.alias] = column.decode(context, row[
|
|
138
|
+
outRow[column.alias] = column.decode(context, row[key]);
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
130
142
|
const key = aggregateKeys[j];
|
|
131
143
|
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
132
|
-
|
|
144
|
+
const value = useAlias ? row[key] : row[keys[j + columnsLength]];
|
|
145
|
+
outRow[key] = parse(context, value);
|
|
133
146
|
}
|
|
134
147
|
|
|
135
148
|
outRows[i] = outRow;
|
|
@@ -143,7 +156,8 @@ async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Ob
|
|
|
143
156
|
span._rowsMap = rowsMap;
|
|
144
157
|
span._ids = fkIds;
|
|
145
158
|
|
|
146
|
-
|
|
159
|
+
if (!useAlias)
|
|
160
|
+
keys.splice(0, columnsLength + aggregateKeys.length);
|
|
147
161
|
if (span.legs.toArray().length === 0)
|
|
148
162
|
return outRows;
|
|
149
163
|
|
|
@@ -7,17 +7,27 @@ function wrapCommand(_context, connection) {
|
|
|
7
7
|
return runQuery;
|
|
8
8
|
|
|
9
9
|
function runQuery(query, onCompleted) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
enqueue(function(done) {
|
|
11
|
+
function safeCompleted(err, result) {
|
|
12
|
+
try {
|
|
13
|
+
onCompleted(err, result);
|
|
14
|
+
} finally {
|
|
15
|
+
done();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!CachedRequest || !CachedTypes) {
|
|
20
|
+
import('tedious')
|
|
21
|
+
.then(({ Request, TYPES }) => {
|
|
22
|
+
CachedRequest = Request;
|
|
23
|
+
CachedTypes = TYPES;
|
|
24
|
+
doQuery(query, safeCompleted);
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => safeCompleted(extractError(err), { rowsAffected: 0 }));
|
|
27
|
+
} else {
|
|
28
|
+
doQuery(query, safeCompleted);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
function doQuery(query, onCompleted) {
|
|
@@ -70,6 +80,19 @@ function wrapCommand(_context, connection) {
|
|
|
70
80
|
return onCompleted(null, { rowsAffected: affectedRows });
|
|
71
81
|
}
|
|
72
82
|
}
|
|
83
|
+
|
|
84
|
+
function enqueue(task) {
|
|
85
|
+
if (!connection.__orangeOrmQueue)
|
|
86
|
+
connection.__orangeOrmQueue = Promise.resolve();
|
|
87
|
+
connection.__orangeOrmQueue = connection.__orangeOrmQueue.then(() => new Promise((resolve) => {
|
|
88
|
+
try {
|
|
89
|
+
task(resolve);
|
|
90
|
+
}
|
|
91
|
+
catch (_e) {
|
|
92
|
+
resolve();
|
|
93
|
+
}
|
|
94
|
+
})).catch(() => {});
|
|
95
|
+
}
|
|
73
96
|
}
|
|
74
97
|
|
|
75
98
|
function extractError(e) {
|
package/src/tedious/wrapQuery.js
CHANGED
|
@@ -7,18 +7,28 @@ function wrapQuery(_context, connection) {
|
|
|
7
7
|
return runQuery;
|
|
8
8
|
|
|
9
9
|
function runQuery(query, onCompleted) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
enqueue(function(done) {
|
|
11
|
+
function safeCompleted(err, rows) {
|
|
12
|
+
try {
|
|
13
|
+
onCompleted(err, rows);
|
|
14
|
+
} finally {
|
|
15
|
+
done();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!CachedRequest || !CachedTypes) {
|
|
20
|
+
import('tedious')
|
|
21
|
+
.then(({ Request, TYPES }) => {
|
|
22
|
+
CachedRequest = Request;
|
|
23
|
+
CachedTypes = TYPES;
|
|
24
|
+
doQuery(query, safeCompleted);
|
|
25
|
+
})
|
|
26
|
+
.catch(err => safeCompleted(extractError(err), []));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
doQuery(query, safeCompleted);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
function doQuery(query, onCompleted) {
|
|
@@ -119,6 +129,19 @@ function wrapQuery(_context, connection) {
|
|
|
119
129
|
}
|
|
120
130
|
}
|
|
121
131
|
}
|
|
132
|
+
|
|
133
|
+
function enqueue(task) {
|
|
134
|
+
if (!connection.__orangeOrmQueue)
|
|
135
|
+
connection.__orangeOrmQueue = Promise.resolve();
|
|
136
|
+
connection.__orangeOrmQueue = connection.__orangeOrmQueue.then(() => new Promise((resolve) => {
|
|
137
|
+
try {
|
|
138
|
+
task(resolve);
|
|
139
|
+
}
|
|
140
|
+
catch (_e) {
|
|
141
|
+
resolve();
|
|
142
|
+
}
|
|
143
|
+
})).catch(() => {});
|
|
144
|
+
}
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
// Helper functions remain the same
|
|
@@ -179,4 +202,4 @@ function addParameters(request, params, TYPES) {
|
|
|
179
202
|
}
|
|
180
203
|
}
|
|
181
204
|
|
|
182
|
-
module.exports = wrapQuery;
|
|
205
|
+
module.exports = wrapQuery;
|