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