pqb 0.54.0 → 0.54.1
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 +26 -17
- package/dist/index.js +236 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -66
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6238,6 +6238,8 @@ function _querySelect(q, args) {
|
|
|
6238
6238
|
q.q.returnType = q.q.returningMany ? "all" : "oneOrThrow";
|
|
6239
6239
|
} else if (returnType === "value") {
|
|
6240
6240
|
q.q.returnType = q.q.returningMany ? "all" : "one";
|
|
6241
|
+
} else if (returnType === "void") {
|
|
6242
|
+
q.q.returnType = q.q.returningMany ? "all" : "oneOrThrow";
|
|
6241
6243
|
}
|
|
6242
6244
|
const len = args.length;
|
|
6243
6245
|
if (!len) {
|
|
@@ -6427,7 +6429,22 @@ const pushWithSql = (ctx, items) => {
|
|
|
6427
6429
|
};
|
|
6428
6430
|
|
|
6429
6431
|
const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
6430
|
-
|
|
6432
|
+
let { columns } = query;
|
|
6433
|
+
const { shape, inCTE, hookCreateSet } = query;
|
|
6434
|
+
const QueryClass = ctx.qb.constructor;
|
|
6435
|
+
let values = query.values;
|
|
6436
|
+
let hookSetSql;
|
|
6437
|
+
if (hookCreateSet) {
|
|
6438
|
+
({ hookSetSql, columns, values } = processHookSet(
|
|
6439
|
+
ctx,
|
|
6440
|
+
q,
|
|
6441
|
+
values,
|
|
6442
|
+
hookCreateSet,
|
|
6443
|
+
columns,
|
|
6444
|
+
QueryClass,
|
|
6445
|
+
quotedAs
|
|
6446
|
+
));
|
|
6447
|
+
}
|
|
6431
6448
|
const quotedColumns = columns.map(
|
|
6432
6449
|
(column) => `"${shape[column]?.data.name || column}"`
|
|
6433
6450
|
);
|
|
@@ -6442,7 +6459,6 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6442
6459
|
}
|
|
6443
6460
|
}
|
|
6444
6461
|
}
|
|
6445
|
-
let values = query.values;
|
|
6446
6462
|
if (quotedColumns.length === 0) {
|
|
6447
6463
|
const key = Object.keys(q.shape)[0];
|
|
6448
6464
|
if (key) {
|
|
@@ -6454,12 +6470,11 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6454
6470
|
}
|
|
6455
6471
|
}
|
|
6456
6472
|
const insertSql = `INSERT INTO ${quotedAs}${quotedColumns.length ? "(" + quotedColumns.join(", ") + ")" : ""}`;
|
|
6457
|
-
if (
|
|
6473
|
+
if ("from" in values && query.insertWith) {
|
|
6458
6474
|
pushWithSql(ctx, Object.values(query.insertWith).flat());
|
|
6459
6475
|
}
|
|
6460
6476
|
const valuesPos = ctx.sql.length + 1;
|
|
6461
6477
|
ctx.sql.push(insertSql, null);
|
|
6462
|
-
const QueryClass = ctx.qb.constructor;
|
|
6463
6478
|
if (query.onConflict) {
|
|
6464
6479
|
ctx.sql.push("ON CONFLICT");
|
|
6465
6480
|
const { target } = query.onConflict;
|
|
@@ -6523,7 +6538,28 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6523
6538
|
returning = makeReturningSql(ctx, q, query, quotedAs, 2);
|
|
6524
6539
|
}
|
|
6525
6540
|
if (returning.select) ctx.sql.push("RETURNING", returning.select);
|
|
6526
|
-
if (
|
|
6541
|
+
if ("from" in values) {
|
|
6542
|
+
const { from, values: v } = values;
|
|
6543
|
+
const q2 = from.clone();
|
|
6544
|
+
if (v) {
|
|
6545
|
+
pushQueryValueImmutable(
|
|
6546
|
+
q2,
|
|
6547
|
+
"select",
|
|
6548
|
+
new RawSQL(
|
|
6549
|
+
encodeRow(
|
|
6550
|
+
ctx,
|
|
6551
|
+
ctx.values,
|
|
6552
|
+
q2,
|
|
6553
|
+
QueryClass,
|
|
6554
|
+
v,
|
|
6555
|
+
runtimeDefaults,
|
|
6556
|
+
quotedAs
|
|
6557
|
+
)
|
|
6558
|
+
)
|
|
6559
|
+
);
|
|
6560
|
+
}
|
|
6561
|
+
ctx.sql[valuesPos] = getSqlText(toSQL(q2, { values: ctx.values }));
|
|
6562
|
+
} else {
|
|
6527
6563
|
const valuesSql = [];
|
|
6528
6564
|
let ctxValues = ctx.values;
|
|
6529
6565
|
const restValuesLen = ctxValues.length;
|
|
@@ -6544,7 +6580,8 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6544
6580
|
QueryClass,
|
|
6545
6581
|
values[i],
|
|
6546
6582
|
runtimeDefaults,
|
|
6547
|
-
quotedAs
|
|
6583
|
+
quotedAs,
|
|
6584
|
+
hookSetSql
|
|
6548
6585
|
);
|
|
6549
6586
|
if (!inCTE) encodedRow = "(" + encodedRow + ")";
|
|
6550
6587
|
if (ctxValues.length > MAX_BINDING_PARAMS) {
|
|
@@ -6593,32 +6630,127 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6593
6630
|
if (inCTE) {
|
|
6594
6631
|
ctx.sql[valuesPos] += ' WHERE NOT EXISTS (SELECT 1 FROM "f")';
|
|
6595
6632
|
}
|
|
6596
|
-
}
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6633
|
+
}
|
|
6634
|
+
return {
|
|
6635
|
+
hookSelect: returning.hookSelect,
|
|
6636
|
+
text: ctx.sql.join(" "),
|
|
6637
|
+
values: ctx.values
|
|
6638
|
+
};
|
|
6639
|
+
};
|
|
6640
|
+
const processHookSet = (ctx, q, values, hookCreateSet, columns, QueryClass, quotedAs) => {
|
|
6641
|
+
const hookSet = {};
|
|
6642
|
+
for (const item of hookCreateSet) {
|
|
6643
|
+
Object.assign(hookSet, item);
|
|
6644
|
+
}
|
|
6645
|
+
const addHookSetColumns = Object.keys(hookSet).filter(
|
|
6646
|
+
(key) => !columns.includes(key)
|
|
6647
|
+
);
|
|
6648
|
+
if ("from" in values) {
|
|
6649
|
+
const v = { ...values };
|
|
6650
|
+
const newColumns = [];
|
|
6651
|
+
const originalSelect = v.from.q.select;
|
|
6652
|
+
if (originalSelect) {
|
|
6653
|
+
v.from = _clone(v.from);
|
|
6654
|
+
const select = [];
|
|
6655
|
+
for (const s of originalSelect) {
|
|
6656
|
+
if (typeof s === "string" && !hookSet[s]) {
|
|
6657
|
+
select.push(s);
|
|
6658
|
+
newColumns.push(s);
|
|
6659
|
+
} else if (typeof s === "object" && "selectAs" in s) {
|
|
6660
|
+
const filtered = {};
|
|
6661
|
+
for (const key in s.selectAs) {
|
|
6662
|
+
if (!hookSet[key]) {
|
|
6663
|
+
filtered[key] = s.selectAs[key];
|
|
6664
|
+
newColumns.push(key);
|
|
6665
|
+
}
|
|
6666
|
+
}
|
|
6667
|
+
select.push({ selectAs: filtered });
|
|
6668
|
+
}
|
|
6669
|
+
}
|
|
6670
|
+
v.from.q.select = select;
|
|
6671
|
+
}
|
|
6672
|
+
let row;
|
|
6673
|
+
if (v.values) {
|
|
6674
|
+
const originalRow = v.values;
|
|
6675
|
+
const valuesColumns = columns.slice(-originalRow.length);
|
|
6676
|
+
row = [];
|
|
6677
|
+
valuesColumns.forEach((c, i) => {
|
|
6678
|
+
if (!hookSet[c]) {
|
|
6679
|
+
newColumns.push(c);
|
|
6680
|
+
row.push(originalRow[i]);
|
|
6681
|
+
}
|
|
6682
|
+
});
|
|
6683
|
+
} else {
|
|
6684
|
+
row = [];
|
|
6685
|
+
}
|
|
6686
|
+
v.values = row;
|
|
6687
|
+
columns.forEach((column) => {
|
|
6688
|
+
if (column in hookSet) {
|
|
6689
|
+
newColumns.push(column);
|
|
6690
|
+
const fromHook = {
|
|
6691
|
+
fromHook: encodeValue(
|
|
6605
6692
|
ctx,
|
|
6606
6693
|
ctx.values,
|
|
6607
|
-
|
|
6694
|
+
q,
|
|
6608
6695
|
QueryClass,
|
|
6609
|
-
|
|
6610
|
-
runtimeDefaults,
|
|
6696
|
+
hookSet[column],
|
|
6611
6697
|
quotedAs
|
|
6612
6698
|
)
|
|
6613
|
-
|
|
6614
|
-
|
|
6699
|
+
};
|
|
6700
|
+
row.push(fromHook);
|
|
6701
|
+
}
|
|
6702
|
+
});
|
|
6703
|
+
if (addHookSetColumns) {
|
|
6704
|
+
for (const key of addHookSetColumns) {
|
|
6705
|
+
row.push({
|
|
6706
|
+
fromHook: encodeValue(
|
|
6707
|
+
ctx,
|
|
6708
|
+
ctx.values,
|
|
6709
|
+
q,
|
|
6710
|
+
QueryClass,
|
|
6711
|
+
hookSet[key],
|
|
6712
|
+
quotedAs
|
|
6713
|
+
)
|
|
6714
|
+
});
|
|
6715
|
+
}
|
|
6716
|
+
return {
|
|
6717
|
+
columns: [...newColumns, ...addHookSetColumns],
|
|
6718
|
+
values: v
|
|
6719
|
+
};
|
|
6615
6720
|
}
|
|
6616
|
-
|
|
6721
|
+
return { columns: newColumns, values: v };
|
|
6617
6722
|
}
|
|
6723
|
+
columns.forEach((column, i) => {
|
|
6724
|
+
if (column in hookSet) {
|
|
6725
|
+
const fromHook = {
|
|
6726
|
+
fromHook: encodeValue(
|
|
6727
|
+
ctx,
|
|
6728
|
+
ctx.values,
|
|
6729
|
+
q,
|
|
6730
|
+
QueryClass,
|
|
6731
|
+
hookSet[column],
|
|
6732
|
+
quotedAs
|
|
6733
|
+
)
|
|
6734
|
+
};
|
|
6735
|
+
for (const row of values) {
|
|
6736
|
+
row[i] = fromHook;
|
|
6737
|
+
}
|
|
6738
|
+
}
|
|
6739
|
+
});
|
|
6740
|
+
const hookSetSql = addHookSetColumns.map(
|
|
6741
|
+
(key) => encodeValue(
|
|
6742
|
+
ctx,
|
|
6743
|
+
ctx.values,
|
|
6744
|
+
q,
|
|
6745
|
+
QueryClass,
|
|
6746
|
+
hookSet[key],
|
|
6747
|
+
quotedAs
|
|
6748
|
+
)
|
|
6749
|
+
).join(", ");
|
|
6618
6750
|
return {
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
values
|
|
6751
|
+
hookSetSql,
|
|
6752
|
+
columns: addHookSetColumns ? [...columns, ...addHookSetColumns] : columns,
|
|
6753
|
+
values
|
|
6622
6754
|
};
|
|
6623
6755
|
};
|
|
6624
6756
|
const mergeColumnsSql = (columns, quotedColumns, target, except) => {
|
|
@@ -6642,24 +6774,30 @@ const mergeColumnsSql = (columns, quotedColumns, target, except) => {
|
|
|
6642
6774
|
`DO UPDATE SET ${quotedColumns[0]} = excluded.${quotedColumns[0]}`
|
|
6643
6775
|
);
|
|
6644
6776
|
};
|
|
6645
|
-
const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) => {
|
|
6646
|
-
const arr = row.map(
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
return value.toSQL(ctx, quotedAs);
|
|
6650
|
-
} else if (value instanceof QueryClass) {
|
|
6651
|
-
return `(${getSqlText(joinSubQuery(q, value).toSQL(ctx))})`;
|
|
6652
|
-
}
|
|
6653
|
-
}
|
|
6654
|
-
return value === void 0 ? "DEFAULT" : addValue(values, value);
|
|
6655
|
-
});
|
|
6777
|
+
const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs, hookSetSql) => {
|
|
6778
|
+
const arr = row.map(
|
|
6779
|
+
(value) => encodeValue(ctx, values, q, QueryClass, value, quotedAs)
|
|
6780
|
+
);
|
|
6656
6781
|
if (runtimeDefaults) {
|
|
6657
6782
|
for (const fn of runtimeDefaults) {
|
|
6658
6783
|
arr.push(addValue(values, fn()));
|
|
6659
6784
|
}
|
|
6660
6785
|
}
|
|
6786
|
+
if (hookSetSql) arr.push(hookSetSql);
|
|
6661
6787
|
return arr.join(", ");
|
|
6662
6788
|
};
|
|
6789
|
+
const encodeValue = (ctx, values, q, QueryClass, value, quotedAs) => {
|
|
6790
|
+
if (value && typeof value === "object") {
|
|
6791
|
+
if (value instanceof Expression) {
|
|
6792
|
+
return value.toSQL(ctx, quotedAs);
|
|
6793
|
+
} else if (value instanceof QueryClass) {
|
|
6794
|
+
return `(${getSqlText(joinSubQuery(q, value).toSQL(ctx))})`;
|
|
6795
|
+
} else if ("fromHook" in value) {
|
|
6796
|
+
return value.fromHook;
|
|
6797
|
+
}
|
|
6798
|
+
}
|
|
6799
|
+
return value === void 0 ? "DEFAULT" : addValue(values, value);
|
|
6800
|
+
};
|
|
6663
6801
|
const hookSelectKeys = [
|
|
6664
6802
|
null,
|
|
6665
6803
|
"afterUpdateSelect",
|
|
@@ -7238,8 +7376,20 @@ const pushUpdateSql = (ctx, table, query, quotedAs) => {
|
|
|
7238
7376
|
query.schema,
|
|
7239
7377
|
table.table || query.from
|
|
7240
7378
|
);
|
|
7379
|
+
let hookSet;
|
|
7380
|
+
if (query.hookUpdateSet) {
|
|
7381
|
+
hookSet = {};
|
|
7382
|
+
for (const item of query.hookUpdateSet) {
|
|
7383
|
+
Object.assign(hookSet, item);
|
|
7384
|
+
}
|
|
7385
|
+
} else {
|
|
7386
|
+
hookSet = emptyObject;
|
|
7387
|
+
}
|
|
7241
7388
|
const set = [];
|
|
7242
|
-
processData(ctx, table, set, query.updateData, quotedAs);
|
|
7389
|
+
processData(ctx, table, set, query.updateData, hookSet, quotedAs);
|
|
7390
|
+
if (query.hookUpdateSet) {
|
|
7391
|
+
applySet(ctx, table, set, hookSet, emptyObject, quotedAs);
|
|
7392
|
+
}
|
|
7243
7393
|
if (!set.length) {
|
|
7244
7394
|
if (!query.select) {
|
|
7245
7395
|
query.select = countSelect;
|
|
@@ -7279,32 +7429,35 @@ const pushUpdateReturning = (ctx, table, query, quotedAs, keyword) => {
|
|
|
7279
7429
|
if (s) ctx.sql.push(keyword, s);
|
|
7280
7430
|
return hookSelect;
|
|
7281
7431
|
};
|
|
7282
|
-
const processData = (ctx, table, set, data, quotedAs) => {
|
|
7432
|
+
const processData = (ctx, table, set, data, hookSet, quotedAs) => {
|
|
7283
7433
|
let append;
|
|
7284
|
-
const QueryClass = ctx.qb.constructor;
|
|
7285
7434
|
for (const item of data) {
|
|
7286
7435
|
if (typeof item === "function") {
|
|
7287
7436
|
const result = item(data);
|
|
7288
7437
|
if (result) append = pushOrNewArray(append, result);
|
|
7289
7438
|
} else {
|
|
7290
|
-
|
|
7291
|
-
for (const key in item) {
|
|
7292
|
-
const value = item[key];
|
|
7293
|
-
if (value === void 0) continue;
|
|
7294
|
-
set.push(
|
|
7295
|
-
`"${shape[key].data.name || key}" = ${processValue(
|
|
7296
|
-
ctx,
|
|
7297
|
-
table,
|
|
7298
|
-
QueryClass,
|
|
7299
|
-
key,
|
|
7300
|
-
value,
|
|
7301
|
-
quotedAs
|
|
7302
|
-
)}`
|
|
7303
|
-
);
|
|
7304
|
-
}
|
|
7439
|
+
applySet(ctx, table, set, item, hookSet, quotedAs);
|
|
7305
7440
|
}
|
|
7306
7441
|
}
|
|
7307
|
-
if (append) processData(ctx, table, set, append, quotedAs);
|
|
7442
|
+
if (append) processData(ctx, table, set, append, hookSet, quotedAs);
|
|
7443
|
+
};
|
|
7444
|
+
const applySet = (ctx, table, set, item, hookSet, quotedAs) => {
|
|
7445
|
+
const QueryClass = ctx.qb.constructor;
|
|
7446
|
+
const shape = table.q.shape;
|
|
7447
|
+
for (const key in item) {
|
|
7448
|
+
const value = item[key];
|
|
7449
|
+
if (value === void 0 || key in hookSet) continue;
|
|
7450
|
+
set.push(
|
|
7451
|
+
`"${shape[key].data.name || key}" = ${processValue(
|
|
7452
|
+
ctx,
|
|
7453
|
+
table,
|
|
7454
|
+
QueryClass,
|
|
7455
|
+
key,
|
|
7456
|
+
value,
|
|
7457
|
+
quotedAs
|
|
7458
|
+
)}`
|
|
7459
|
+
);
|
|
7460
|
+
}
|
|
7308
7461
|
};
|
|
7309
7462
|
const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
|
|
7310
7463
|
if (value && typeof value === "object") {
|
|
@@ -8745,7 +8898,7 @@ const handleManyData = (q, data, ctx) => {
|
|
|
8745
8898
|
const insert = (self, {
|
|
8746
8899
|
columns,
|
|
8747
8900
|
values
|
|
8748
|
-
},
|
|
8901
|
+
}, many) => {
|
|
8749
8902
|
const { q } = self;
|
|
8750
8903
|
if (!q.select?.length) {
|
|
8751
8904
|
q.returning = true;
|
|
@@ -8756,7 +8909,6 @@ const insert = (self, {
|
|
|
8756
8909
|
q.type = "insert";
|
|
8757
8910
|
q.columns = columns;
|
|
8758
8911
|
q.values = values;
|
|
8759
|
-
if (!q.kind) q.kind = kind;
|
|
8760
8912
|
const { select, returnType } = q;
|
|
8761
8913
|
if (!select) {
|
|
8762
8914
|
if (returnType !== "void") {
|
|
@@ -8804,9 +8956,8 @@ const insertFromQuery = (q, from, many, data) => {
|
|
|
8804
8956
|
q,
|
|
8805
8957
|
{
|
|
8806
8958
|
columns,
|
|
8807
|
-
values: { from, values: obj?.values }
|
|
8959
|
+
values: { from, values: obj?.values[0] }
|
|
8808
8960
|
},
|
|
8809
|
-
"from",
|
|
8810
8961
|
many
|
|
8811
8962
|
);
|
|
8812
8963
|
};
|
|
@@ -8820,10 +8971,10 @@ const _queryInsert = (q, data) => {
|
|
|
8820
8971
|
const values = q.q.values;
|
|
8821
8972
|
if (values && "from" in values) {
|
|
8822
8973
|
obj.columns = getFromSelectColumns(values.from, obj);
|
|
8823
|
-
values.values = obj.values;
|
|
8974
|
+
values.values = obj.values[0];
|
|
8824
8975
|
obj.values = values;
|
|
8825
8976
|
}
|
|
8826
|
-
return insert(q, obj
|
|
8977
|
+
return insert(q, obj);
|
|
8827
8978
|
};
|
|
8828
8979
|
const _queryCreateMany = (q, data) => {
|
|
8829
8980
|
createSelect(q);
|
|
@@ -8831,7 +8982,7 @@ const _queryCreateMany = (q, data) => {
|
|
|
8831
8982
|
};
|
|
8832
8983
|
const _queryInsertMany = (q, data) => {
|
|
8833
8984
|
const ctx = createCtx();
|
|
8834
|
-
let result = insert(q, handleManyData(q, data, ctx),
|
|
8985
|
+
let result = insert(q, handleManyData(q, data, ctx), true);
|
|
8835
8986
|
if (!data.length) result = result.none();
|
|
8836
8987
|
return result;
|
|
8837
8988
|
};
|
|
@@ -9564,7 +9715,7 @@ const _queryHookAfterQuery = (q, cb) => {
|
|
|
9564
9715
|
return pushQueryValueImmutable(q, "after", cb);
|
|
9565
9716
|
};
|
|
9566
9717
|
const _queryHookBeforeCreate = (q, cb) => {
|
|
9567
|
-
return before(q, "Create", cb);
|
|
9718
|
+
return before(q, "Create", (q2) => cb(new QueryHookUtils(q2, "hookCreateSet")));
|
|
9568
9719
|
};
|
|
9569
9720
|
const _queryHookAfterCreate = (q, select, cb) => {
|
|
9570
9721
|
return after(q, "Create", select, cb);
|
|
@@ -9573,7 +9724,7 @@ const _queryHookAfterCreateCommit = (q, select, cb) => {
|
|
|
9573
9724
|
return after(q, "Create", select, cb, true);
|
|
9574
9725
|
};
|
|
9575
9726
|
const _queryHookBeforeUpdate = (q, cb) => {
|
|
9576
|
-
return before(q, "Update", cb);
|
|
9727
|
+
return before(q, "Update", (q2) => cb(new QueryHookUtils(q2, "hookUpdateSet")));
|
|
9577
9728
|
};
|
|
9578
9729
|
const _queryHookAfterUpdate = (q, select, cb) => {
|
|
9579
9730
|
return after(q, "Update", select, cb);
|
|
@@ -9582,7 +9733,11 @@ const _queryHookAfterUpdateCommit = (q, select, cb) => {
|
|
|
9582
9733
|
return after(q, "Update", select, cb, true);
|
|
9583
9734
|
};
|
|
9584
9735
|
const _queryHookBeforeSave = (q, cb) => {
|
|
9585
|
-
return before(
|
|
9736
|
+
return before(
|
|
9737
|
+
before(q, "Create", (q2) => cb(new QueryHookUtils(q2, "hookCreateSet"))),
|
|
9738
|
+
"Update",
|
|
9739
|
+
(q2) => cb(new QueryHookUtils(q2, "hookUpdateSet"))
|
|
9740
|
+
);
|
|
9586
9741
|
};
|
|
9587
9742
|
const _queryHookAfterSave = (q, select, cb) => {
|
|
9588
9743
|
return after(after(q, "Create", select, cb), "Update", select, cb);
|
|
@@ -9605,6 +9760,21 @@ const _queryHookAfterDelete = (q, select, cb) => {
|
|
|
9605
9760
|
const _queryHookAfterDeleteCommit = (q, select, cb) => {
|
|
9606
9761
|
return after(q, "Delete", select, cb, true);
|
|
9607
9762
|
};
|
|
9763
|
+
class QueryHookUtils {
|
|
9764
|
+
constructor(query, key) {
|
|
9765
|
+
this.query = query;
|
|
9766
|
+
this.key = key;
|
|
9767
|
+
this.set = (data) => {
|
|
9768
|
+
const set = {};
|
|
9769
|
+
for (const key in data) {
|
|
9770
|
+
if (data[key] !== void 0) {
|
|
9771
|
+
set[key] = data[key];
|
|
9772
|
+
}
|
|
9773
|
+
}
|
|
9774
|
+
pushQueryValueImmutable(this.query, this.key, set);
|
|
9775
|
+
};
|
|
9776
|
+
}
|
|
9777
|
+
}
|
|
9608
9778
|
class QueryHooks {
|
|
9609
9779
|
/**
|
|
9610
9780
|
* Run the function before any kind of query.
|
|
@@ -11356,7 +11526,7 @@ function orCreate(query, data, updateData, mergeData) {
|
|
|
11356
11526
|
q22.q.log = q2.q.log;
|
|
11357
11527
|
q22.q.logger = q2.q.logger;
|
|
11358
11528
|
q22.q.type = "upsert";
|
|
11359
|
-
q22.q.beforeCreate = q2.q.beforeCreate;
|
|
11529
|
+
q22.q.beforeCreate = q2.q.beforeCreate?.map((cb) => () => cb(c));
|
|
11360
11530
|
if (hasAfterCallback) {
|
|
11361
11531
|
((_a = q22.q).afterCreate ?? (_a.afterCreate = [])).push(
|
|
11362
11532
|
(data2, query2) => afterHooks && Promise.all([...afterHooks].map((fn) => fn(data2, query2)))
|
|
@@ -13287,5 +13457,5 @@ function copyTableData(query, arg) {
|
|
|
13287
13457
|
return q;
|
|
13288
13458
|
}
|
|
13289
13459
|
|
|
13290
|
-
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql$1 as rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
13460
|
+
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryGet, QueryHookUtils, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql$1 as rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
13291
13461
|
//# sourceMappingURL=index.mjs.map
|