pqb 0.43.5 → 0.45.0
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 +95 -72
- package/dist/index.js +141 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -146
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2127,14 +2127,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2127
2127
|
} else {
|
|
2128
2128
|
const item = value;
|
|
2129
2129
|
const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
|
|
2130
|
-
const { on } = item;
|
|
2131
2130
|
const q = item.useOuterAliases ? {
|
|
2132
2131
|
joinedShapes: query.joinedShapes,
|
|
2133
2132
|
aliases: query.outerAliases,
|
|
2134
2133
|
shape: query.shape
|
|
2135
2134
|
} : query;
|
|
2136
2135
|
ands.push(
|
|
2137
|
-
`${onColumnToSql(ctx, q, joinAs,
|
|
2136
|
+
`${onColumnToSql(ctx, q, joinAs, item.from)} ${item.op || "="} ${onColumnToSql(ctx, q, joinAs, item.to)}`
|
|
2138
2137
|
);
|
|
2139
2138
|
}
|
|
2140
2139
|
} else if (key === "IN") {
|
|
@@ -2611,7 +2610,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
2611
2610
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
2612
2611
|
qb.q.subQuery = 1;
|
|
2613
2612
|
qb.q.outerAliases = qb.q.aliases;
|
|
2614
|
-
args[i] =
|
|
2613
|
+
args[i] = resolveSubQueryCallbackV2(qb, arg);
|
|
2615
2614
|
}
|
|
2616
2615
|
}
|
|
2617
2616
|
};
|
|
@@ -3388,6 +3387,11 @@ const pushQueryValue = (q, key, value) => {
|
|
|
3388
3387
|
);
|
|
3389
3388
|
return q;
|
|
3390
3389
|
};
|
|
3390
|
+
const pushQueryValueImmutable = (q, key, value) => {
|
|
3391
|
+
const arr = q.q[key];
|
|
3392
|
+
q.q[key] = arr ? [...arr, value] : [value];
|
|
3393
|
+
return q;
|
|
3394
|
+
};
|
|
3391
3395
|
const setQueryObjectValue = (q, object, key, value) => {
|
|
3392
3396
|
if (!q.q[object])
|
|
3393
3397
|
q.q[object] = {
|
|
@@ -3608,9 +3612,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
|
|
|
3608
3612
|
computeds
|
|
3609
3613
|
);
|
|
3610
3614
|
};
|
|
3611
|
-
const
|
|
3612
|
-
var _a, _b, _c;
|
|
3613
|
-
const q = self;
|
|
3615
|
+
const _joinLateralProcessArg = (q, arg, cb) => {
|
|
3614
3616
|
let relation;
|
|
3615
3617
|
if (typeof arg === "string") {
|
|
3616
3618
|
relation = q.relations[arg];
|
|
@@ -3632,29 +3634,36 @@ const _joinLateral = (self, type, arg, cb, as) => {
|
|
|
3632
3634
|
}
|
|
3633
3635
|
}
|
|
3634
3636
|
}
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
let result = resolveSubQueryCallback(query, cb);
|
|
3637
|
+
let result = resolveSubQueryCallbackV2(
|
|
3638
|
+
arg,
|
|
3639
|
+
cb
|
|
3640
|
+
);
|
|
3640
3641
|
if (relation) {
|
|
3641
3642
|
result = relation.relationConfig.joinQuery(
|
|
3642
3643
|
result,
|
|
3643
3644
|
q
|
|
3644
3645
|
);
|
|
3645
3646
|
}
|
|
3646
|
-
|
|
3647
|
+
return result;
|
|
3648
|
+
};
|
|
3649
|
+
const _joinLateral = (self, type, arg, as) => {
|
|
3650
|
+
var _a, _b, _c;
|
|
3651
|
+
const q = self;
|
|
3652
|
+
arg.q.joinTo = q;
|
|
3653
|
+
const joinedAs = getQueryAs(q);
|
|
3654
|
+
((_a = arg.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
|
|
3655
|
+
const joinKey = as || arg.q.as || arg.table;
|
|
3647
3656
|
if (joinKey) {
|
|
3648
|
-
const shape = getShapeFromSelect(
|
|
3657
|
+
const shape = getShapeFromSelect(arg, true);
|
|
3649
3658
|
setQueryObjectValue(q, "joinedShapes", joinKey, shape);
|
|
3650
|
-
setQueryObjectValue(q, "joinedParsers", joinKey,
|
|
3651
|
-
if (
|
|
3652
|
-
((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] =
|
|
3659
|
+
setQueryObjectValue(q, "joinedParsers", joinKey, arg.q.parsers);
|
|
3660
|
+
if (arg.q.batchParsers) {
|
|
3661
|
+
((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = arg.q.batchParsers;
|
|
3653
3662
|
}
|
|
3654
3663
|
}
|
|
3655
|
-
as || (as = getQueryAs(
|
|
3656
|
-
((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] =
|
|
3657
|
-
return pushQueryValue(q, "join", [type,
|
|
3664
|
+
as || (as = getQueryAs(arg));
|
|
3665
|
+
((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = arg.q.computeds;
|
|
3666
|
+
return pushQueryValue(q, "join", [type, arg, as]);
|
|
3658
3667
|
};
|
|
3659
3668
|
|
|
3660
3669
|
class EnumColumn extends ColumnType {
|
|
@@ -5203,7 +5212,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5203
5212
|
let value = arg[key];
|
|
5204
5213
|
let joinQuery;
|
|
5205
5214
|
if (typeof value === "function") {
|
|
5206
|
-
value =
|
|
5215
|
+
value = resolveSubQueryCallbackV2(q, value);
|
|
5207
5216
|
if (isQueryNone(value)) {
|
|
5208
5217
|
if (value.q.innerJoinLateral) {
|
|
5209
5218
|
return false;
|
|
@@ -5245,7 +5254,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5245
5254
|
q,
|
|
5246
5255
|
value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
5247
5256
|
query,
|
|
5248
|
-
(q2) => q2,
|
|
5249
5257
|
key
|
|
5250
5258
|
);
|
|
5251
5259
|
}
|
|
@@ -5262,7 +5270,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5262
5270
|
return { selectAs };
|
|
5263
5271
|
};
|
|
5264
5272
|
const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
5265
|
-
var _a
|
|
5273
|
+
var _a;
|
|
5266
5274
|
const index = arg.indexOf(".");
|
|
5267
5275
|
if (index !== -1) {
|
|
5268
5276
|
const table = getFullColumnTable(q, arg, index, as);
|
|
@@ -5291,7 +5299,7 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
|
5291
5299
|
const computeds = q.q.joinedComputeds?.[table];
|
|
5292
5300
|
if (computeds?.[column]) {
|
|
5293
5301
|
const computed = computeds[column];
|
|
5294
|
-
const map =
|
|
5302
|
+
const map = q.q.hookSelect = new Map(q.q.hookSelect);
|
|
5295
5303
|
for (const column2 of computed.deps) {
|
|
5296
5304
|
map.set(column2, { select: `${table}.${column2}` });
|
|
5297
5305
|
}
|
|
@@ -5311,10 +5319,9 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
|
5311
5319
|
}
|
|
5312
5320
|
};
|
|
5313
5321
|
const handleComputed = (q, computeds, column) => {
|
|
5314
|
-
var _a;
|
|
5315
5322
|
if (computeds?.[column]) {
|
|
5316
5323
|
const computed = computeds[column];
|
|
5317
|
-
const map =
|
|
5324
|
+
const map = q.q.hookSelect = new Map(q.q.hookSelect);
|
|
5318
5325
|
for (const column2 of computed.deps) {
|
|
5319
5326
|
map.set(column2, { select: column2 });
|
|
5320
5327
|
}
|
|
@@ -6657,16 +6664,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
6657
6664
|
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
6658
6665
|
};
|
|
6659
6666
|
|
|
6660
|
-
const toSQLCacheKey = Symbol("toSQLCache");
|
|
6661
6667
|
const toSQL = (table, options) => {
|
|
6662
|
-
if (table.q
|
|
6663
|
-
const cached = table.q
|
|
6668
|
+
if (table.q.sqlCache && !options?.clearCache) {
|
|
6669
|
+
const cached = table.q.sqlCache;
|
|
6664
6670
|
if (options?.values && "values" in cached && cached.values && options.values !== cached.values) {
|
|
6665
6671
|
options.values.push(...cached.values);
|
|
6666
6672
|
}
|
|
6667
6673
|
return cached;
|
|
6668
6674
|
}
|
|
6669
|
-
return table.q
|
|
6675
|
+
return table.q.sqlCache = makeSQL(table, options);
|
|
6670
6676
|
};
|
|
6671
6677
|
const makeSQL = (table, options) => {
|
|
6672
6678
|
const query = table.q;
|
|
@@ -6801,11 +6807,8 @@ function pushLimitSQL(sql, values, q) {
|
|
|
6801
6807
|
const cloneQuery = (q) => {
|
|
6802
6808
|
if (q.with) q.with = q.with.slice(0);
|
|
6803
6809
|
if (q.select) q.select = q.select.slice(0);
|
|
6804
|
-
if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
|
|
6805
6810
|
if (q.and) q.and = q.and.slice(0);
|
|
6806
6811
|
if (q.or) q.or = q.or.slice(0);
|
|
6807
|
-
if (q.before) q.before = q.before.slice(0);
|
|
6808
|
-
if (q.after) q.after = q.after.slice(0);
|
|
6809
6812
|
if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
|
|
6810
6813
|
if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
|
|
6811
6814
|
if (q.batchParsers) q.batchParsers = [...q.batchParsers];
|
|
@@ -6830,29 +6833,6 @@ const cloneQuery = (q) => {
|
|
|
6830
6833
|
q.values = Array.isArray(q.values) ? q.values.slice(0) : q.values;
|
|
6831
6834
|
if (q.using) q.using = q.using.slice(0);
|
|
6832
6835
|
if (q.join) q.join = q.join.slice(0);
|
|
6833
|
-
if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
|
|
6834
|
-
if (q.afterCreate) {
|
|
6835
|
-
q.afterCreate = q.afterCreate.slice(0);
|
|
6836
|
-
if (q.afterCreateSelect) {
|
|
6837
|
-
q.afterCreateSelect = new Set(q.afterCreateSelect);
|
|
6838
|
-
}
|
|
6839
|
-
}
|
|
6840
|
-
} else if (q.type === "update") {
|
|
6841
|
-
if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
|
|
6842
|
-
if (q.afterUpdate) {
|
|
6843
|
-
q.afterUpdate = q.afterUpdate.slice(0);
|
|
6844
|
-
if (q.afterUpdateSelect) {
|
|
6845
|
-
q.afterUpdateSelect = new Set(q.afterUpdateSelect);
|
|
6846
|
-
}
|
|
6847
|
-
}
|
|
6848
|
-
} else if (q.type === "delete") {
|
|
6849
|
-
if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
|
|
6850
|
-
if (q.afterDelete) {
|
|
6851
|
-
q.afterDelete = q.afterDelete.slice(0);
|
|
6852
|
-
if (q.afterDeleteSelect) {
|
|
6853
|
-
q.afterDeleteSelect = new Set(q.afterDeleteSelect);
|
|
6854
|
-
}
|
|
6855
|
-
}
|
|
6856
6836
|
}
|
|
6857
6837
|
};
|
|
6858
6838
|
|
|
@@ -6893,7 +6873,7 @@ const _chain = (fromQuery, toQuery, rel) => {
|
|
|
6893
6873
|
|
|
6894
6874
|
const getClonedQueryData = (query) => {
|
|
6895
6875
|
const cloned = { ...query };
|
|
6896
|
-
delete cloned
|
|
6876
|
+
delete cloned.sqlCache;
|
|
6897
6877
|
cloneQuery(cloned);
|
|
6898
6878
|
return cloned;
|
|
6899
6879
|
};
|
|
@@ -6903,13 +6883,13 @@ const getQueryAs = (q) => {
|
|
|
6903
6883
|
const makeRegexToFindInSql = (value) => {
|
|
6904
6884
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
6905
6885
|
};
|
|
6906
|
-
const
|
|
6907
|
-
let
|
|
6886
|
+
const resolveSubQueryCallbackV2 = (q, cb) => {
|
|
6887
|
+
let base;
|
|
6908
6888
|
if (q.table) {
|
|
6909
|
-
|
|
6910
|
-
|
|
6889
|
+
base = q.internal.callbackArg;
|
|
6890
|
+
if (!base) {
|
|
6891
|
+
base = Object.create(q.baseQuery);
|
|
6911
6892
|
base.baseQuery = base;
|
|
6912
|
-
q.internal.callbackArg = base;
|
|
6913
6893
|
const { relations } = q;
|
|
6914
6894
|
for (const key in relations) {
|
|
6915
6895
|
Object.defineProperty(base, key, {
|
|
@@ -6919,21 +6899,17 @@ const resolveSubQueryCallback = (q, cb) => {
|
|
|
6919
6899
|
}
|
|
6920
6900
|
});
|
|
6921
6901
|
}
|
|
6902
|
+
q.internal.callbackArg = base;
|
|
6922
6903
|
}
|
|
6923
|
-
arg = Object.create(q.internal.callbackArg);
|
|
6924
|
-
arg.q = q.q;
|
|
6925
6904
|
} else {
|
|
6926
|
-
|
|
6927
|
-
}
|
|
6928
|
-
const
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
q.q.relChain = relChain;
|
|
6935
|
-
q.q.outerAliases = outerAliases;
|
|
6936
|
-
return result;
|
|
6905
|
+
base = q;
|
|
6906
|
+
}
|
|
6907
|
+
const arg = Object.create(base);
|
|
6908
|
+
arg.q = getClonedQueryData(q.q);
|
|
6909
|
+
arg.q.subQuery = 1;
|
|
6910
|
+
arg.q.relChain = void 0;
|
|
6911
|
+
arg.q.outerAliases = q.q.aliases;
|
|
6912
|
+
return cb(arg);
|
|
6937
6913
|
};
|
|
6938
6914
|
const joinSubQuery = (q, sub) => {
|
|
6939
6915
|
if (!("relationConfig" in sub)) return sub;
|
|
@@ -8149,7 +8125,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
|
|
|
8149
8125
|
);
|
|
8150
8126
|
} else {
|
|
8151
8127
|
if (typeof item[key] === "function") {
|
|
8152
|
-
item[key] =
|
|
8128
|
+
item[key] = resolveSubQueryCallbackV2(
|
|
8153
8129
|
q,
|
|
8154
8130
|
item[key]
|
|
8155
8131
|
);
|
|
@@ -9075,21 +9051,22 @@ class Having {
|
|
|
9075
9051
|
}
|
|
9076
9052
|
}
|
|
9077
9053
|
|
|
9078
|
-
const before = (q, key, cb) =>
|
|
9079
|
-
const after = (
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
const
|
|
9054
|
+
const before = (q, key, cb) => pushQueryValueImmutable(q, `before${key}`, cb);
|
|
9055
|
+
const after = (query, key, select, cb, commit) => {
|
|
9056
|
+
const q = query;
|
|
9057
|
+
pushQueryValueImmutable(q, `after${key}${commit ? "Commit" : ""}`, cb);
|
|
9058
|
+
const prop = `after${key}Select`;
|
|
9059
|
+
const set = q.q[prop] = new Set(q.q[prop]);
|
|
9083
9060
|
for (const column of select) {
|
|
9084
9061
|
set.add(column);
|
|
9085
9062
|
}
|
|
9086
|
-
return
|
|
9063
|
+
return query;
|
|
9087
9064
|
};
|
|
9088
9065
|
const _queryHookBeforeQuery = (q, cb) => {
|
|
9089
|
-
return
|
|
9066
|
+
return pushQueryValueImmutable(q, "before", cb);
|
|
9090
9067
|
};
|
|
9091
9068
|
const _queryHookAfterQuery = (q, cb) => {
|
|
9092
|
-
return
|
|
9069
|
+
return pushQueryValueImmutable(q, "after", cb);
|
|
9093
9070
|
};
|
|
9094
9071
|
const _queryHookBeforeCreate = (q, cb) => {
|
|
9095
9072
|
return before(q, "Create", cb);
|
|
@@ -9905,11 +9882,11 @@ class Join {
|
|
|
9905
9882
|
* @param cb - {@link JoinLateralCallback}
|
|
9906
9883
|
*/
|
|
9907
9884
|
joinLateral(arg, cb) {
|
|
9885
|
+
const q = _clone(this);
|
|
9908
9886
|
return _joinLateral(
|
|
9909
|
-
|
|
9887
|
+
q,
|
|
9910
9888
|
"JOIN",
|
|
9911
|
-
arg,
|
|
9912
|
-
cb
|
|
9889
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9913
9890
|
);
|
|
9914
9891
|
}
|
|
9915
9892
|
/**
|
|
@@ -9928,28 +9905,32 @@ class Join {
|
|
|
9928
9905
|
* @param cb - {@link JoinLateralCallback}
|
|
9929
9906
|
*/
|
|
9930
9907
|
leftJoinLateral(arg, cb) {
|
|
9908
|
+
const q = _clone(this);
|
|
9931
9909
|
return _joinLateral(
|
|
9932
9910
|
_clone(this),
|
|
9933
9911
|
"LEFT JOIN",
|
|
9934
|
-
arg,
|
|
9935
|
-
cb
|
|
9912
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9936
9913
|
);
|
|
9937
9914
|
}
|
|
9938
9915
|
}
|
|
9939
9916
|
const makeOnItem = (joinTo, joinFrom, args) => ({
|
|
9940
9917
|
ON: {
|
|
9941
|
-
joinTo,
|
|
9942
9918
|
joinFrom,
|
|
9943
|
-
|
|
9919
|
+
from: args[0],
|
|
9920
|
+
joinTo,
|
|
9921
|
+
to: args.length === 2 ? args[1] : args[2],
|
|
9922
|
+
op: args.length === 2 ? void 0 : args[1]
|
|
9944
9923
|
}
|
|
9945
9924
|
});
|
|
9946
9925
|
const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
|
|
9947
9926
|
return pushQueryValue(q, "and", {
|
|
9948
9927
|
ON: {
|
|
9949
|
-
joinTo: joinFrom,
|
|
9950
9928
|
joinFrom: joinTo,
|
|
9929
|
+
from: on[0],
|
|
9930
|
+
joinTo: joinFrom,
|
|
9931
|
+
to: on.length === 2 ? on[1] : on[2],
|
|
9951
9932
|
useOuterAliases: true,
|
|
9952
|
-
on
|
|
9933
|
+
op: on.length === 2 ? void 0 : on[1]
|
|
9953
9934
|
}
|
|
9954
9935
|
});
|
|
9955
9936
|
};
|
|
@@ -10367,11 +10348,11 @@ const _queryUpdate = (query, arg) => {
|
|
|
10367
10348
|
} else {
|
|
10368
10349
|
let value = set[key];
|
|
10369
10350
|
if (typeof value === "function") {
|
|
10370
|
-
value =
|
|
10351
|
+
value = resolveSubQueryCallbackV2(
|
|
10371
10352
|
query.baseQuery,
|
|
10372
10353
|
value
|
|
10373
10354
|
);
|
|
10374
|
-
if (value instanceof Db && value.q.type) {
|
|
10355
|
+
if (value instanceof Db && value.q.type && value.q.subQuery) {
|
|
10375
10356
|
throw new OrchidOrmInternalError(
|
|
10376
10357
|
value,
|
|
10377
10358
|
`Only selecting queries are allowed inside callback of update, ${value.q.type} is given instead.`
|
|
@@ -10493,7 +10474,7 @@ class Update {
|
|
|
10493
10474
|
*
|
|
10494
10475
|
* // use query that returns a single value
|
|
10495
10476
|
* // returning multiple values will result in Postgres error
|
|
10496
|
-
* column3: db.otherTable.get('someColumn'),
|
|
10477
|
+
* column3: () => db.otherTable.get('someColumn'),
|
|
10497
10478
|
*
|
|
10498
10479
|
* // select a single value from a related record
|
|
10499
10480
|
* fromRelation: (q) => q.relatedTable.get('someColumn'),
|
|
@@ -10510,16 +10491,16 @@ class Update {
|
|
|
10510
10491
|
* ```ts
|
|
10511
10492
|
* await db.table.where({ ...conditions }).update({
|
|
10512
10493
|
* // `column` will be set to a value of the `otherColumn` of the created record.
|
|
10513
|
-
* column: db.otherTable.get('otherColumn').create({ ...data }),
|
|
10494
|
+
* column: () => db.otherTable.get('otherColumn').create({ ...data }),
|
|
10514
10495
|
*
|
|
10515
10496
|
* // `column2` will be set to a value of the `otherColumn` of the updated record.
|
|
10516
|
-
* column2: db.otherTable
|
|
10497
|
+
* column2: () => db.otherTable
|
|
10517
10498
|
* .get('otherColumn')
|
|
10518
10499
|
* .findBy({ ...conditions })
|
|
10519
10500
|
* .update({ key: 'value' }),
|
|
10520
10501
|
*
|
|
10521
10502
|
* // `column3` will be set to a value of the `otherColumn` of the deleted record.
|
|
10522
|
-
* column3: db.otherTable
|
|
10503
|
+
* column3: () => db.otherTable
|
|
10523
10504
|
* .get('otherColumn')
|
|
10524
10505
|
* .findBy({ ...conditions })
|
|
10525
10506
|
* .delete(),
|
|
@@ -11001,7 +10982,7 @@ function orCreate(query, data, updateData, mergeData) {
|
|
|
11001
10982
|
q.handleResult = (q2, t, r, s) => {
|
|
11002
10983
|
return created ? result : handleResult(q2, t, r, s);
|
|
11003
10984
|
};
|
|
11004
|
-
q.hookSelect
|
|
10985
|
+
q.hookSelect = new Map(q.hookSelect);
|
|
11005
10986
|
q.patchResult = async (q2, hookSelect, queryResult) => {
|
|
11006
10987
|
var _a, _b;
|
|
11007
10988
|
if (queryResult.rowCount === 0) {
|
|
@@ -12166,52 +12147,6 @@ class QueryMethods {
|
|
|
12166
12147
|
none() {
|
|
12167
12148
|
return _queryNone(this);
|
|
12168
12149
|
}
|
|
12169
|
-
/**
|
|
12170
|
-
* `modify` allows modifying the query with your function:
|
|
12171
|
-
*
|
|
12172
|
-
* ```ts
|
|
12173
|
-
* const doSomethingWithQuery = (q: typeof db.table) => {
|
|
12174
|
-
* // can use all query methods
|
|
12175
|
-
* return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
|
|
12176
|
-
* };
|
|
12177
|
-
*
|
|
12178
|
-
* const record = await db.table.select('id').modify(doSomethingWithQuery).find(1);
|
|
12179
|
-
*
|
|
12180
|
-
* record.id; // id was selected before `modify`
|
|
12181
|
-
* record.name; // name was selected by the function
|
|
12182
|
-
* ```
|
|
12183
|
-
*
|
|
12184
|
-
* It's possible to apply different `select`s inside the function, and then the result type will be a union of all possibilities:
|
|
12185
|
-
*
|
|
12186
|
-
* Use this sparingly as it complicates dealing with the result.
|
|
12187
|
-
*
|
|
12188
|
-
* ```ts
|
|
12189
|
-
* const doSomethingWithQuery = (q: typeof db.table) => {
|
|
12190
|
-
* if (Math.random() > 0.5) {
|
|
12191
|
-
* return q.select('one');
|
|
12192
|
-
* } else {
|
|
12193
|
-
* return q.select('two');
|
|
12194
|
-
* }
|
|
12195
|
-
* };
|
|
12196
|
-
*
|
|
12197
|
-
* const record = await db.table.modify(doSomethingWithQuery).find(1);
|
|
12198
|
-
*
|
|
12199
|
-
* // TS error: we don't know for sure if the `one` was selected.
|
|
12200
|
-
* record.one;
|
|
12201
|
-
*
|
|
12202
|
-
* // use `in` operator to disambiguate the result type
|
|
12203
|
-
* if ('one' in record) {
|
|
12204
|
-
* record.one;
|
|
12205
|
-
* } else {
|
|
12206
|
-
* record.two;
|
|
12207
|
-
* }
|
|
12208
|
-
* ```
|
|
12209
|
-
*
|
|
12210
|
-
* @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
|
|
12211
|
-
*/
|
|
12212
|
-
modify(fn) {
|
|
12213
|
-
return fn(this);
|
|
12214
|
-
}
|
|
12215
12150
|
/**
|
|
12216
12151
|
* Use `makeHelper` to make a query helper - a function where you can modify the query, and reuse this function across different places.
|
|
12217
12152
|
*
|
|
@@ -12273,6 +12208,65 @@ class QueryMethods {
|
|
|
12273
12208
|
return fn(q, ...args);
|
|
12274
12209
|
};
|
|
12275
12210
|
}
|
|
12211
|
+
/**
|
|
12212
|
+
* `modify` allows modifying the query with helpers defined with {@link makeHelper}:
|
|
12213
|
+
*
|
|
12214
|
+
* ```ts
|
|
12215
|
+
* const helper = db.table.makeHelper((q) => {
|
|
12216
|
+
* // all query methods are available
|
|
12217
|
+
* return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
|
|
12218
|
+
* });
|
|
12219
|
+
*
|
|
12220
|
+
* const record = await db.table.select('id').modify(helper).find(1);
|
|
12221
|
+
*
|
|
12222
|
+
* record.id; // id was selected before `modify`
|
|
12223
|
+
* record.name; // name was selected by the function
|
|
12224
|
+
* ```
|
|
12225
|
+
*
|
|
12226
|
+
* When the helper result isn't certain, it will result in a union of all possibilities.
|
|
12227
|
+
* Use this sparingly as it complicates dealing with the result.
|
|
12228
|
+
*
|
|
12229
|
+
* ```ts
|
|
12230
|
+
* const helper = db.table((q) => {
|
|
12231
|
+
* if (Math.random() > 0.5) {
|
|
12232
|
+
* return q.select('one');
|
|
12233
|
+
* } else {
|
|
12234
|
+
* return q.select('two');
|
|
12235
|
+
* }
|
|
12236
|
+
* });
|
|
12237
|
+
*
|
|
12238
|
+
* const record = await db.table.modify(helper).find(1);
|
|
12239
|
+
*
|
|
12240
|
+
* // TS error: we don't know for sure if the `one` was selected.
|
|
12241
|
+
* record.one;
|
|
12242
|
+
*
|
|
12243
|
+
* // use `in` operator to disambiguate the result type
|
|
12244
|
+
* if ('one' in record) {
|
|
12245
|
+
* record.one;
|
|
12246
|
+
* } else {
|
|
12247
|
+
* record.two;
|
|
12248
|
+
* }
|
|
12249
|
+
* ```
|
|
12250
|
+
*
|
|
12251
|
+
* You can define and pass parameters:
|
|
12252
|
+
*
|
|
12253
|
+
* ```ts
|
|
12254
|
+
* const helper = db.table.makeHelper((q, select: 'id' | 'name') => {
|
|
12255
|
+
* return q.select(select);
|
|
12256
|
+
* });
|
|
12257
|
+
*
|
|
12258
|
+
* const record = await db.table.modify(helper, 'id').find(1);
|
|
12259
|
+
* // record has type { id: number } | { name: string }
|
|
12260
|
+
* if ('id' in record) {
|
|
12261
|
+
* record.id;
|
|
12262
|
+
* }
|
|
12263
|
+
* ```
|
|
12264
|
+
*
|
|
12265
|
+
* @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
|
|
12266
|
+
*/
|
|
12267
|
+
modify(fn, ...args) {
|
|
12268
|
+
return fn(this, ...args);
|
|
12269
|
+
}
|
|
12276
12270
|
/**
|
|
12277
12271
|
* Narrows a part of the query output type.
|
|
12278
12272
|
* Use with caution, type-safety isn't guaranteed with it.
|
|
@@ -13142,6 +13136,7 @@ exports.pushQueryOn = pushQueryOn;
|
|
|
13142
13136
|
exports.pushQueryOnForOuter = pushQueryOnForOuter;
|
|
13143
13137
|
exports.pushQueryOrOn = pushQueryOrOn;
|
|
13144
13138
|
exports.pushQueryValue = pushQueryValue;
|
|
13139
|
+
exports.pushQueryValueImmutable = pushQueryValueImmutable;
|
|
13145
13140
|
exports.pushTableDataCode = pushTableDataCode;
|
|
13146
13141
|
exports.queryFrom = queryFrom;
|
|
13147
13142
|
exports.queryFromSql = queryFromSql;
|
|
@@ -13151,7 +13146,7 @@ exports.queryTypeWithLimitOne = queryTypeWithLimitOne;
|
|
|
13151
13146
|
exports.queryWrap = queryWrap;
|
|
13152
13147
|
exports.raw = raw;
|
|
13153
13148
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
13154
|
-
exports.
|
|
13149
|
+
exports.resolveSubQueryCallbackV2 = resolveSubQueryCallbackV2;
|
|
13155
13150
|
exports.rollbackSql = rollbackSql$1;
|
|
13156
13151
|
exports.saveSearchAlias = saveSearchAlias;
|
|
13157
13152
|
exports.setColumnDefaultParse = setColumnDefaultParse;
|
|
@@ -13170,5 +13165,4 @@ exports.testTransaction = testTransaction;
|
|
|
13170
13165
|
exports.throwIfJoinLateral = throwIfJoinLateral;
|
|
13171
13166
|
exports.throwIfNoWhere = throwIfNoWhere;
|
|
13172
13167
|
exports.toSQL = toSQL;
|
|
13173
|
-
exports.toSQLCacheKey = toSQLCacheKey;
|
|
13174
13168
|
//# sourceMappingURL=index.js.map
|