pqb 0.38.3 → 0.38.5
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.d.ts +6 -2
- package/dist/index.js +41 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3276,18 +3276,7 @@ class Transaction {
|
|
|
3276
3276
|
const result = await this.q.adapter.transaction(sql, callback);
|
|
3277
3277
|
if (log)
|
|
3278
3278
|
log.afterQuery(commitSql$1, logData);
|
|
3279
|
-
|
|
3280
|
-
if (afterCommit) {
|
|
3281
|
-
const promises = [];
|
|
3282
|
-
for (let i = 0, len = afterCommit.length; i < len; i += 2) {
|
|
3283
|
-
const q = afterCommit[i];
|
|
3284
|
-
const result2 = afterCommit[i + 1];
|
|
3285
|
-
for (const fn2 of afterCommit[i + 2]) {
|
|
3286
|
-
promises.push(fn2(result2, q));
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
await Promise.all(promises);
|
|
3290
|
-
}
|
|
3279
|
+
await runAfterCommit(trx.afterCommit);
|
|
3291
3280
|
return result;
|
|
3292
3281
|
} catch (err) {
|
|
3293
3282
|
if (log)
|
|
@@ -3319,6 +3308,11 @@ class Transaction {
|
|
|
3319
3308
|
await adapter.query(sql);
|
|
3320
3309
|
if (log)
|
|
3321
3310
|
log.afterQuery(sql, logData);
|
|
3311
|
+
if (transactionId === trx.testTransactionCount) {
|
|
3312
|
+
await runAfterCommit(
|
|
3313
|
+
trx.afterCommit
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
3322
3316
|
return result;
|
|
3323
3317
|
} finally {
|
|
3324
3318
|
trx.transactionId = transactionId - 1;
|
|
@@ -3326,6 +3320,19 @@ class Transaction {
|
|
|
3326
3320
|
}
|
|
3327
3321
|
}
|
|
3328
3322
|
}
|
|
3323
|
+
const runAfterCommit = async (afterCommit) => {
|
|
3324
|
+
if (afterCommit) {
|
|
3325
|
+
const promises = [];
|
|
3326
|
+
for (let i = 0, len = afterCommit.length; i < len; i += 3) {
|
|
3327
|
+
const result = afterCommit[i];
|
|
3328
|
+
const q = afterCommit[i + 1];
|
|
3329
|
+
for (const fn of afterCommit[i + 2]) {
|
|
3330
|
+
promises.push(fn(result, q));
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
await Promise.all(promises);
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3329
3336
|
|
|
3330
3337
|
const applyBatchTransforms = (query, batches) => {
|
|
3331
3338
|
if (query.transform) {
|
|
@@ -4000,19 +4007,19 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4000
4007
|
}
|
|
4001
4008
|
}
|
|
4002
4009
|
if (returnType === "value") {
|
|
4003
|
-
return (_a = result[0]) == null ? void 0 : _a[queryResult
|
|
4010
|
+
return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
|
|
4004
4011
|
}
|
|
4005
4012
|
if (returnType === "valueOrThrow") {
|
|
4006
4013
|
const row = result[0];
|
|
4007
4014
|
if (!row)
|
|
4008
4015
|
throw new NotFoundError(q);
|
|
4009
|
-
return row[queryResult
|
|
4016
|
+
return row[getFirstResultKey(q, queryResult)];
|
|
4010
4017
|
}
|
|
4011
4018
|
if (returnType === "rowCount") {
|
|
4012
4019
|
return queryResult.rowCount;
|
|
4013
4020
|
}
|
|
4014
4021
|
if (returnType === "pluck") {
|
|
4015
|
-
const key = queryResult
|
|
4022
|
+
const key = getFirstResultKey(q, queryResult);
|
|
4016
4023
|
return result.map((row) => row[key]);
|
|
4017
4024
|
}
|
|
4018
4025
|
if (returnType === "rows") {
|
|
@@ -4021,6 +4028,16 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4021
4028
|
}
|
|
4022
4029
|
return;
|
|
4023
4030
|
};
|
|
4031
|
+
const getFirstResultKey = (q, queryResult) => {
|
|
4032
|
+
if (q.q.select) {
|
|
4033
|
+
return queryResult.fields[0].name;
|
|
4034
|
+
} else {
|
|
4035
|
+
for (const key in q.q.selectedComputeds) {
|
|
4036
|
+
return key;
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
return;
|
|
4040
|
+
};
|
|
4024
4041
|
const filterAllResult = (result, tempColumns, hasAfterHook) => {
|
|
4025
4042
|
if (tempColumns == null ? void 0 : tempColumns.size) {
|
|
4026
4043
|
if (hasAfterHook) {
|
|
@@ -4455,7 +4472,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
4455
4472
|
} else if (it) {
|
|
4456
4473
|
const { returnType } = it.q;
|
|
4457
4474
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4458
|
-
const type = it.q
|
|
4475
|
+
const type = it.q.getColumn;
|
|
4459
4476
|
if (type)
|
|
4460
4477
|
result[key] = type;
|
|
4461
4478
|
} else {
|
|
@@ -4571,7 +4588,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4571
4588
|
}
|
|
4572
4589
|
}
|
|
4573
4590
|
}
|
|
4574
|
-
q
|
|
4591
|
+
q.getColumn = type;
|
|
4575
4592
|
const selected = setParserForSelectedString(
|
|
4576
4593
|
query,
|
|
4577
4594
|
arg,
|
|
@@ -4587,7 +4604,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4587
4604
|
] : void 0;
|
|
4588
4605
|
} else {
|
|
4589
4606
|
type = arg.result.value;
|
|
4590
|
-
q
|
|
4607
|
+
q.getColumn = type;
|
|
4591
4608
|
addParserForRawExpression(query, getValueKey, arg);
|
|
4592
4609
|
q.select = [q.expr = arg];
|
|
4593
4610
|
}
|
|
@@ -6432,7 +6449,7 @@ class FnExpression extends Expression {
|
|
|
6432
6449
|
Object.assign(query, value.operators);
|
|
6433
6450
|
query.q.returnType = "valueOrThrow";
|
|
6434
6451
|
query.q.returnsOne = true;
|
|
6435
|
-
query.q
|
|
6452
|
+
query.q.getColumn = value;
|
|
6436
6453
|
query.q.select = [this];
|
|
6437
6454
|
const { parseFn } = value;
|
|
6438
6455
|
if (parseFn) {
|
|
@@ -9151,7 +9168,6 @@ class MergeQueryMethods {
|
|
|
9151
9168
|
break;
|
|
9152
9169
|
}
|
|
9153
9170
|
}
|
|
9154
|
-
a[getValueKey] = b[getValueKey];
|
|
9155
9171
|
if (b.returnType)
|
|
9156
9172
|
a.returnType = b.returnType;
|
|
9157
9173
|
return query;
|
|
@@ -12693,6 +12709,7 @@ const testTransaction = {
|
|
|
12693
12709
|
adapter.query = t.query.bind(t);
|
|
12694
12710
|
adapter.arrays = t.arrays.bind(t);
|
|
12695
12711
|
adapter.transaction = t.transaction.bind(t);
|
|
12712
|
+
trx.testTransactionCount = trx.testTransactionCount ? trx.testTransactionCount + 1 : 1;
|
|
12696
12713
|
}
|
|
12697
12714
|
data.reject = rej;
|
|
12698
12715
|
});
|
|
@@ -12701,6 +12718,10 @@ const testTransaction = {
|
|
|
12701
12718
|
throw err;
|
|
12702
12719
|
}
|
|
12703
12720
|
}).finally(() => {
|
|
12721
|
+
const trx = db.internal.transactionStorage.getStore();
|
|
12722
|
+
if (trx == null ? void 0 : trx.testTransactionCount) {
|
|
12723
|
+
trx.testTransactionCount--;
|
|
12724
|
+
}
|
|
12704
12725
|
db.internal.transactionStorage.getStore = getStore;
|
|
12705
12726
|
});
|
|
12706
12727
|
});
|