pqb 0.41.2 → 0.41.4
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 +1 -1
- package/dist/index.js +149 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -146
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3404,20 +3404,18 @@ class Transaction {
|
|
|
3404
3404
|
sql.text = `BEGIN${options.level ? ` ISOLATION LEVEL ${options.level}` : ""}${options.readOnly !== void 0 ? ` READ ${options.readOnly ? "ONLY" : "WRITE"}` : ""}${options.deferrable !== void 0 ? ` ${options.deferrable ? "" : "NOT "}DEFERRABLE` : ""}`;
|
|
3405
3405
|
if (log)
|
|
3406
3406
|
logData = log.beforeQuery(sql);
|
|
3407
|
-
|
|
3408
|
-
const result = await this.q.adapter.transaction(sql, callback);
|
|
3409
|
-
if (log)
|
|
3410
|
-
log.afterQuery(commitSql$1, logData);
|
|
3411
|
-
await runAfterCommit(
|
|
3412
|
-
trx.afterCommit,
|
|
3413
|
-
result
|
|
3414
|
-
);
|
|
3415
|
-
return result;
|
|
3416
|
-
} catch (err) {
|
|
3407
|
+
const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
|
|
3417
3408
|
if (log)
|
|
3418
3409
|
log.afterQuery(rollbackSql$1, logData);
|
|
3419
3410
|
throw err;
|
|
3420
|
-
}
|
|
3411
|
+
});
|
|
3412
|
+
if (log)
|
|
3413
|
+
log.afterQuery(commitSql$1, logData);
|
|
3414
|
+
await runAfterCommit(
|
|
3415
|
+
trx.afterCommit,
|
|
3416
|
+
result
|
|
3417
|
+
);
|
|
3418
|
+
return result;
|
|
3421
3419
|
} else {
|
|
3422
3420
|
try {
|
|
3423
3421
|
sql.text = `SAVEPOINT "${transactionId}"`;
|
|
@@ -4316,172 +4314,175 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
|
|
|
4316
4314
|
);
|
|
4317
4315
|
}
|
|
4318
4316
|
};
|
|
4319
|
-
const addParserForSelectItem = (q, as, key, arg) => {
|
|
4320
|
-
var _a, _b, _c, _d;
|
|
4317
|
+
const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
|
|
4318
|
+
var _a, _b, _c, _d, _e;
|
|
4321
4319
|
if (typeof arg === "object" || typeof arg === "function") {
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
const
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
batches.push = Array.prototype.push;
|
|
4351
|
-
return batches.push(item);
|
|
4352
|
-
};
|
|
4353
|
-
}
|
|
4320
|
+
const { q: query } = arg;
|
|
4321
|
+
if (query.batchParsers) {
|
|
4322
|
+
const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
|
|
4323
|
+
for (const bp of query.batchParsers) {
|
|
4324
|
+
batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
if (query.hookSelect || query.parsers || query.transform) {
|
|
4328
|
+
const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
|
|
4329
|
+
batchParsers.push({
|
|
4330
|
+
path: [key],
|
|
4331
|
+
fn: (path, queryResult) => {
|
|
4332
|
+
var _a2, _b2, _c2;
|
|
4333
|
+
const { rows } = queryResult;
|
|
4334
|
+
const originalReturnType = query.returnType || "all";
|
|
4335
|
+
let returnType = originalReturnType;
|
|
4336
|
+
const { hookSelect } = query;
|
|
4337
|
+
const batches = [];
|
|
4338
|
+
const last = path.length;
|
|
4339
|
+
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4340
|
+
if (hookSelect) {
|
|
4341
|
+
batches.push = (item) => {
|
|
4342
|
+
if (!(key in item)) {
|
|
4343
|
+
returnType = returnType === "value" ? "one" : "oneOrThrow";
|
|
4344
|
+
}
|
|
4345
|
+
batches.push = Array.prototype.push;
|
|
4346
|
+
return batches.push(item);
|
|
4347
|
+
};
|
|
4354
4348
|
}
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4349
|
+
}
|
|
4350
|
+
collectNestedSelectBatches(batches, rows, path, last);
|
|
4351
|
+
switch (returnType) {
|
|
4352
|
+
case "all": {
|
|
4353
|
+
const { parsers } = query;
|
|
4354
|
+
if (parsers) {
|
|
4355
|
+
for (const { data } of batches) {
|
|
4356
|
+
for (const one of data) {
|
|
4357
|
+
parseRecord(parsers, one);
|
|
4364
4358
|
}
|
|
4365
4359
|
}
|
|
4366
|
-
break;
|
|
4367
4360
|
}
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
} else {
|
|
4378
|
-
for (const { data } of batches) {
|
|
4379
|
-
if (!data)
|
|
4380
|
-
throw new NotFoundError(arg);
|
|
4361
|
+
break;
|
|
4362
|
+
}
|
|
4363
|
+
case "one":
|
|
4364
|
+
case "oneOrThrow": {
|
|
4365
|
+
const { parsers } = query;
|
|
4366
|
+
if (parsers) {
|
|
4367
|
+
if (returnType === "one") {
|
|
4368
|
+
for (const { data } of batches) {
|
|
4369
|
+
if (data)
|
|
4381
4370
|
parseRecord(parsers, data);
|
|
4382
|
-
}
|
|
4383
4371
|
}
|
|
4384
|
-
} else
|
|
4372
|
+
} else {
|
|
4385
4373
|
for (const { data } of batches) {
|
|
4386
4374
|
if (!data)
|
|
4387
4375
|
throw new NotFoundError(arg);
|
|
4376
|
+
parseRecord(parsers, data);
|
|
4388
4377
|
}
|
|
4389
4378
|
}
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4379
|
+
} else if (returnType !== "one") {
|
|
4380
|
+
for (const { data } of batches) {
|
|
4381
|
+
if (!data)
|
|
4382
|
+
throw new NotFoundError(arg);
|
|
4394
4383
|
}
|
|
4395
|
-
break;
|
|
4396
4384
|
}
|
|
4397
|
-
|
|
4398
|
-
const
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4385
|
+
if (hookSelect) {
|
|
4386
|
+
for (const batch of batches) {
|
|
4387
|
+
batch.data = [batch.data];
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
break;
|
|
4391
|
+
}
|
|
4392
|
+
case "pluck": {
|
|
4393
|
+
const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
|
|
4394
|
+
if (parse) {
|
|
4395
|
+
for (const { data } of batches) {
|
|
4396
|
+
for (let i = 0; i < data.length; i++) {
|
|
4397
|
+
data[i] = parse(data[i]);
|
|
4404
4398
|
}
|
|
4405
4399
|
}
|
|
4406
|
-
break;
|
|
4407
4400
|
}
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
for (const item of batches) {
|
|
4418
|
-
if (item.data === void 0)
|
|
4419
|
-
throw new NotFoundError(arg);
|
|
4420
|
-
item.parent[item.key] = item.data = parse(item.data);
|
|
4421
|
-
}
|
|
4401
|
+
break;
|
|
4402
|
+
}
|
|
4403
|
+
case "value":
|
|
4404
|
+
case "valueOrThrow": {
|
|
4405
|
+
const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
|
|
4406
|
+
if (parse) {
|
|
4407
|
+
if (returnType === "value") {
|
|
4408
|
+
for (const item of batches) {
|
|
4409
|
+
item.parent[item.key] = item.data = item.data === void 0 ? query.notFoundDefault : parse(item.data);
|
|
4422
4410
|
}
|
|
4423
|
-
} else
|
|
4424
|
-
for (const
|
|
4425
|
-
if (data === void 0)
|
|
4411
|
+
} else {
|
|
4412
|
+
for (const item of batches) {
|
|
4413
|
+
if (item.data === void 0)
|
|
4426
4414
|
throw new NotFoundError(arg);
|
|
4415
|
+
item.parent[item.key] = item.data = parse(item.data);
|
|
4427
4416
|
}
|
|
4428
4417
|
}
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4418
|
+
} else if (returnType !== "value") {
|
|
4419
|
+
for (const { data } of batches) {
|
|
4420
|
+
if (data === void 0)
|
|
4421
|
+
throw new NotFoundError(arg);
|
|
4433
4422
|
}
|
|
4434
|
-
break;
|
|
4435
4423
|
}
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
for (const column of hookSelect.keys()) {
|
|
4441
|
-
const as2 = hookSelect.get(column).as;
|
|
4442
|
-
if (as2)
|
|
4443
|
-
(renames != null ? renames : renames = {})[column] = as2;
|
|
4444
|
-
(_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
|
|
4424
|
+
if (hookSelect) {
|
|
4425
|
+
for (const batch of batches) {
|
|
4426
|
+
batch.data = [batch.data];
|
|
4427
|
+
}
|
|
4445
4428
|
}
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4429
|
+
break;
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
if (hookSelect) {
|
|
4433
|
+
let tempColumns;
|
|
4434
|
+
let renames;
|
|
4435
|
+
for (const column of hookSelect.keys()) {
|
|
4436
|
+
const as2 = hookSelect.get(column).as;
|
|
4437
|
+
if (as2)
|
|
4438
|
+
(renames != null ? renames : renames = {})[column] = as2;
|
|
4439
|
+
(_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
|
|
4440
|
+
}
|
|
4441
|
+
if (renames) {
|
|
4442
|
+
for (const { data } of batches) {
|
|
4443
|
+
for (const record of data) {
|
|
4444
|
+
if (record) {
|
|
4445
|
+
for (const a in renames) {
|
|
4446
|
+
const value = record[renames[a]];
|
|
4447
|
+
record[renames[a]] = record[a];
|
|
4448
|
+
record[a] = value;
|
|
4455
4449
|
}
|
|
4456
4450
|
}
|
|
4457
4451
|
}
|
|
4458
4452
|
}
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
originalReturnType,
|
|
4464
|
-
returnType,
|
|
4465
|
-
tempColumns,
|
|
4466
|
-
renames,
|
|
4467
|
-
key
|
|
4468
|
-
);
|
|
4469
|
-
if (maybePromise)
|
|
4470
|
-
return maybePromise;
|
|
4471
|
-
}
|
|
4472
|
-
finalizeNestedHookSelect(
|
|
4453
|
+
}
|
|
4454
|
+
if (query.selectedComputeds) {
|
|
4455
|
+
const maybePromise = processComputedBatches(
|
|
4456
|
+
query,
|
|
4473
4457
|
batches,
|
|
4474
4458
|
originalReturnType,
|
|
4459
|
+
returnType,
|
|
4475
4460
|
tempColumns,
|
|
4476
4461
|
renames,
|
|
4477
4462
|
key
|
|
4478
4463
|
);
|
|
4464
|
+
if (maybePromise)
|
|
4465
|
+
return maybePromise;
|
|
4479
4466
|
}
|
|
4480
|
-
|
|
4481
|
-
|
|
4467
|
+
finalizeNestedHookSelect(
|
|
4468
|
+
batches,
|
|
4469
|
+
originalReturnType,
|
|
4470
|
+
tempColumns,
|
|
4471
|
+
renames,
|
|
4472
|
+
key
|
|
4473
|
+
);
|
|
4482
4474
|
}
|
|
4483
|
-
|
|
4484
|
-
|
|
4475
|
+
applyBatchTransforms(query, batches);
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4478
|
+
});
|
|
4479
|
+
}
|
|
4480
|
+
if (!joinQuery && ((_e = arg.q) == null ? void 0 : _e.subQuery) && arg.q.expr) {
|
|
4481
|
+
arg = arg.q.expr;
|
|
4482
|
+
}
|
|
4483
|
+
if (isExpression(arg)) {
|
|
4484
|
+
addParserForRawExpression(q, key, arg);
|
|
4485
|
+
return arg;
|
|
4485
4486
|
}
|
|
4486
4487
|
return arg;
|
|
4487
4488
|
}
|
|
@@ -4516,7 +4517,7 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
|
4516
4517
|
};
|
|
4517
4518
|
const emptyArrSQL = new RawSQL("'[]'");
|
|
4518
4519
|
const processSelectArg = (q, as, arg, columnAs) => {
|
|
4519
|
-
var _a
|
|
4520
|
+
var _a;
|
|
4520
4521
|
if (typeof arg === "string") {
|
|
4521
4522
|
return setParserForSelectedString(q, arg, as, columnAs);
|
|
4522
4523
|
}
|
|
@@ -4524,13 +4525,16 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4524
4525
|
let aliases;
|
|
4525
4526
|
for (const key in arg) {
|
|
4526
4527
|
let value = arg[key];
|
|
4528
|
+
let joinQuery;
|
|
4527
4529
|
if (typeof value === "function") {
|
|
4528
4530
|
value = resolveSubQueryCallback(q, value);
|
|
4529
4531
|
if (isQueryNone(value)) {
|
|
4530
4532
|
if (value.q.innerJoinLateral) {
|
|
4531
4533
|
return false;
|
|
4532
4534
|
}
|
|
4533
|
-
}
|
|
4535
|
+
}
|
|
4536
|
+
if (!isExpression(value) && value.joinQuery) {
|
|
4537
|
+
joinQuery = true;
|
|
4534
4538
|
value = value.joinQuery(value, q);
|
|
4535
4539
|
let query;
|
|
4536
4540
|
const returnType = value.q.returnType;
|
|
@@ -4568,8 +4572,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4568
4572
|
(q2) => q2,
|
|
4569
4573
|
key
|
|
4570
4574
|
);
|
|
4571
|
-
} else if (((_b = value.q) == null ? void 0 : _b.subQuery) && value.q.expr) {
|
|
4572
|
-
value = value.q.expr;
|
|
4573
4575
|
}
|
|
4574
4576
|
}
|
|
4575
4577
|
if (aliases)
|
|
@@ -4578,7 +4580,8 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4578
4580
|
q,
|
|
4579
4581
|
as,
|
|
4580
4582
|
key,
|
|
4581
|
-
value
|
|
4583
|
+
value,
|
|
4584
|
+
joinQuery
|
|
4582
4585
|
);
|
|
4583
4586
|
}
|
|
4584
4587
|
return { selectAs };
|