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.mjs
CHANGED
|
@@ -2125,14 +2125,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2125
2125
|
} else {
|
|
2126
2126
|
const item = value;
|
|
2127
2127
|
const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
|
|
2128
|
-
const { on } = item;
|
|
2129
2128
|
const q = item.useOuterAliases ? {
|
|
2130
2129
|
joinedShapes: query.joinedShapes,
|
|
2131
2130
|
aliases: query.outerAliases,
|
|
2132
2131
|
shape: query.shape
|
|
2133
2132
|
} : query;
|
|
2134
2133
|
ands.push(
|
|
2135
|
-
`${onColumnToSql(ctx, q, joinAs,
|
|
2134
|
+
`${onColumnToSql(ctx, q, joinAs, item.from)} ${item.op || "="} ${onColumnToSql(ctx, q, joinAs, item.to)}`
|
|
2136
2135
|
);
|
|
2137
2136
|
}
|
|
2138
2137
|
} else if (key === "IN") {
|
|
@@ -2609,7 +2608,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
2609
2608
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
2610
2609
|
qb.q.subQuery = 1;
|
|
2611
2610
|
qb.q.outerAliases = qb.q.aliases;
|
|
2612
|
-
args[i] =
|
|
2611
|
+
args[i] = resolveSubQueryCallbackV2(qb, arg);
|
|
2613
2612
|
}
|
|
2614
2613
|
}
|
|
2615
2614
|
};
|
|
@@ -3386,6 +3385,11 @@ const pushQueryValue = (q, key, value) => {
|
|
|
3386
3385
|
);
|
|
3387
3386
|
return q;
|
|
3388
3387
|
};
|
|
3388
|
+
const pushQueryValueImmutable = (q, key, value) => {
|
|
3389
|
+
const arr = q.q[key];
|
|
3390
|
+
q.q[key] = arr ? [...arr, value] : [value];
|
|
3391
|
+
return q;
|
|
3392
|
+
};
|
|
3389
3393
|
const setQueryObjectValue = (q, object, key, value) => {
|
|
3390
3394
|
if (!q.q[object])
|
|
3391
3395
|
q.q[object] = {
|
|
@@ -3606,9 +3610,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
|
|
|
3606
3610
|
computeds
|
|
3607
3611
|
);
|
|
3608
3612
|
};
|
|
3609
|
-
const
|
|
3610
|
-
var _a, _b, _c;
|
|
3611
|
-
const q = self;
|
|
3613
|
+
const _joinLateralProcessArg = (q, arg, cb) => {
|
|
3612
3614
|
let relation;
|
|
3613
3615
|
if (typeof arg === "string") {
|
|
3614
3616
|
relation = q.relations[arg];
|
|
@@ -3630,29 +3632,36 @@ const _joinLateral = (self, type, arg, cb, as) => {
|
|
|
3630
3632
|
}
|
|
3631
3633
|
}
|
|
3632
3634
|
}
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
let result = resolveSubQueryCallback(query, cb);
|
|
3635
|
+
let result = resolveSubQueryCallbackV2(
|
|
3636
|
+
arg,
|
|
3637
|
+
cb
|
|
3638
|
+
);
|
|
3638
3639
|
if (relation) {
|
|
3639
3640
|
result = relation.relationConfig.joinQuery(
|
|
3640
3641
|
result,
|
|
3641
3642
|
q
|
|
3642
3643
|
);
|
|
3643
3644
|
}
|
|
3644
|
-
|
|
3645
|
+
return result;
|
|
3646
|
+
};
|
|
3647
|
+
const _joinLateral = (self, type, arg, as) => {
|
|
3648
|
+
var _a, _b, _c;
|
|
3649
|
+
const q = self;
|
|
3650
|
+
arg.q.joinTo = q;
|
|
3651
|
+
const joinedAs = getQueryAs(q);
|
|
3652
|
+
((_a = arg.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
|
|
3653
|
+
const joinKey = as || arg.q.as || arg.table;
|
|
3645
3654
|
if (joinKey) {
|
|
3646
|
-
const shape = getShapeFromSelect(
|
|
3655
|
+
const shape = getShapeFromSelect(arg, true);
|
|
3647
3656
|
setQueryObjectValue(q, "joinedShapes", joinKey, shape);
|
|
3648
|
-
setQueryObjectValue(q, "joinedParsers", joinKey,
|
|
3649
|
-
if (
|
|
3650
|
-
((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] =
|
|
3657
|
+
setQueryObjectValue(q, "joinedParsers", joinKey, arg.q.parsers);
|
|
3658
|
+
if (arg.q.batchParsers) {
|
|
3659
|
+
((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = arg.q.batchParsers;
|
|
3651
3660
|
}
|
|
3652
3661
|
}
|
|
3653
|
-
as || (as = getQueryAs(
|
|
3654
|
-
((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] =
|
|
3655
|
-
return pushQueryValue(q, "join", [type,
|
|
3662
|
+
as || (as = getQueryAs(arg));
|
|
3663
|
+
((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = arg.q.computeds;
|
|
3664
|
+
return pushQueryValue(q, "join", [type, arg, as]);
|
|
3656
3665
|
};
|
|
3657
3666
|
|
|
3658
3667
|
class EnumColumn extends ColumnType {
|
|
@@ -5201,7 +5210,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5201
5210
|
let value = arg[key];
|
|
5202
5211
|
let joinQuery;
|
|
5203
5212
|
if (typeof value === "function") {
|
|
5204
|
-
value =
|
|
5213
|
+
value = resolveSubQueryCallbackV2(q, value);
|
|
5205
5214
|
if (isQueryNone(value)) {
|
|
5206
5215
|
if (value.q.innerJoinLateral) {
|
|
5207
5216
|
return false;
|
|
@@ -5243,7 +5252,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5243
5252
|
q,
|
|
5244
5253
|
value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
5245
5254
|
query,
|
|
5246
|
-
(q2) => q2,
|
|
5247
5255
|
key
|
|
5248
5256
|
);
|
|
5249
5257
|
}
|
|
@@ -5260,7 +5268,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5260
5268
|
return { selectAs };
|
|
5261
5269
|
};
|
|
5262
5270
|
const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
5263
|
-
var _a
|
|
5271
|
+
var _a;
|
|
5264
5272
|
const index = arg.indexOf(".");
|
|
5265
5273
|
if (index !== -1) {
|
|
5266
5274
|
const table = getFullColumnTable(q, arg, index, as);
|
|
@@ -5289,7 +5297,7 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
|
5289
5297
|
const computeds = q.q.joinedComputeds?.[table];
|
|
5290
5298
|
if (computeds?.[column]) {
|
|
5291
5299
|
const computed = computeds[column];
|
|
5292
|
-
const map =
|
|
5300
|
+
const map = q.q.hookSelect = new Map(q.q.hookSelect);
|
|
5293
5301
|
for (const column2 of computed.deps) {
|
|
5294
5302
|
map.set(column2, { select: `${table}.${column2}` });
|
|
5295
5303
|
}
|
|
@@ -5309,10 +5317,9 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
|
5309
5317
|
}
|
|
5310
5318
|
};
|
|
5311
5319
|
const handleComputed = (q, computeds, column) => {
|
|
5312
|
-
var _a;
|
|
5313
5320
|
if (computeds?.[column]) {
|
|
5314
5321
|
const computed = computeds[column];
|
|
5315
|
-
const map =
|
|
5322
|
+
const map = q.q.hookSelect = new Map(q.q.hookSelect);
|
|
5316
5323
|
for (const column2 of computed.deps) {
|
|
5317
5324
|
map.set(column2, { select: column2 });
|
|
5318
5325
|
}
|
|
@@ -6655,16 +6662,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
6655
6662
|
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
6656
6663
|
};
|
|
6657
6664
|
|
|
6658
|
-
const toSQLCacheKey = Symbol("toSQLCache");
|
|
6659
6665
|
const toSQL = (table, options) => {
|
|
6660
|
-
if (table.q
|
|
6661
|
-
const cached = table.q
|
|
6666
|
+
if (table.q.sqlCache && !options?.clearCache) {
|
|
6667
|
+
const cached = table.q.sqlCache;
|
|
6662
6668
|
if (options?.values && "values" in cached && cached.values && options.values !== cached.values) {
|
|
6663
6669
|
options.values.push(...cached.values);
|
|
6664
6670
|
}
|
|
6665
6671
|
return cached;
|
|
6666
6672
|
}
|
|
6667
|
-
return table.q
|
|
6673
|
+
return table.q.sqlCache = makeSQL(table, options);
|
|
6668
6674
|
};
|
|
6669
6675
|
const makeSQL = (table, options) => {
|
|
6670
6676
|
const query = table.q;
|
|
@@ -6799,11 +6805,8 @@ function pushLimitSQL(sql, values, q) {
|
|
|
6799
6805
|
const cloneQuery = (q) => {
|
|
6800
6806
|
if (q.with) q.with = q.with.slice(0);
|
|
6801
6807
|
if (q.select) q.select = q.select.slice(0);
|
|
6802
|
-
if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
|
|
6803
6808
|
if (q.and) q.and = q.and.slice(0);
|
|
6804
6809
|
if (q.or) q.or = q.or.slice(0);
|
|
6805
|
-
if (q.before) q.before = q.before.slice(0);
|
|
6806
|
-
if (q.after) q.after = q.after.slice(0);
|
|
6807
6810
|
if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
|
|
6808
6811
|
if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
|
|
6809
6812
|
if (q.batchParsers) q.batchParsers = [...q.batchParsers];
|
|
@@ -6828,29 +6831,6 @@ const cloneQuery = (q) => {
|
|
|
6828
6831
|
q.values = Array.isArray(q.values) ? q.values.slice(0) : q.values;
|
|
6829
6832
|
if (q.using) q.using = q.using.slice(0);
|
|
6830
6833
|
if (q.join) q.join = q.join.slice(0);
|
|
6831
|
-
if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
|
|
6832
|
-
if (q.afterCreate) {
|
|
6833
|
-
q.afterCreate = q.afterCreate.slice(0);
|
|
6834
|
-
if (q.afterCreateSelect) {
|
|
6835
|
-
q.afterCreateSelect = new Set(q.afterCreateSelect);
|
|
6836
|
-
}
|
|
6837
|
-
}
|
|
6838
|
-
} else if (q.type === "update") {
|
|
6839
|
-
if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
|
|
6840
|
-
if (q.afterUpdate) {
|
|
6841
|
-
q.afterUpdate = q.afterUpdate.slice(0);
|
|
6842
|
-
if (q.afterUpdateSelect) {
|
|
6843
|
-
q.afterUpdateSelect = new Set(q.afterUpdateSelect);
|
|
6844
|
-
}
|
|
6845
|
-
}
|
|
6846
|
-
} else if (q.type === "delete") {
|
|
6847
|
-
if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
|
|
6848
|
-
if (q.afterDelete) {
|
|
6849
|
-
q.afterDelete = q.afterDelete.slice(0);
|
|
6850
|
-
if (q.afterDeleteSelect) {
|
|
6851
|
-
q.afterDeleteSelect = new Set(q.afterDeleteSelect);
|
|
6852
|
-
}
|
|
6853
|
-
}
|
|
6854
6834
|
}
|
|
6855
6835
|
};
|
|
6856
6836
|
|
|
@@ -6891,7 +6871,7 @@ const _chain = (fromQuery, toQuery, rel) => {
|
|
|
6891
6871
|
|
|
6892
6872
|
const getClonedQueryData = (query) => {
|
|
6893
6873
|
const cloned = { ...query };
|
|
6894
|
-
delete cloned
|
|
6874
|
+
delete cloned.sqlCache;
|
|
6895
6875
|
cloneQuery(cloned);
|
|
6896
6876
|
return cloned;
|
|
6897
6877
|
};
|
|
@@ -6901,13 +6881,13 @@ const getQueryAs = (q) => {
|
|
|
6901
6881
|
const makeRegexToFindInSql = (value) => {
|
|
6902
6882
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
6903
6883
|
};
|
|
6904
|
-
const
|
|
6905
|
-
let
|
|
6884
|
+
const resolveSubQueryCallbackV2 = (q, cb) => {
|
|
6885
|
+
let base;
|
|
6906
6886
|
if (q.table) {
|
|
6907
|
-
|
|
6908
|
-
|
|
6887
|
+
base = q.internal.callbackArg;
|
|
6888
|
+
if (!base) {
|
|
6889
|
+
base = Object.create(q.baseQuery);
|
|
6909
6890
|
base.baseQuery = base;
|
|
6910
|
-
q.internal.callbackArg = base;
|
|
6911
6891
|
const { relations } = q;
|
|
6912
6892
|
for (const key in relations) {
|
|
6913
6893
|
Object.defineProperty(base, key, {
|
|
@@ -6917,21 +6897,17 @@ const resolveSubQueryCallback = (q, cb) => {
|
|
|
6917
6897
|
}
|
|
6918
6898
|
});
|
|
6919
6899
|
}
|
|
6900
|
+
q.internal.callbackArg = base;
|
|
6920
6901
|
}
|
|
6921
|
-
arg = Object.create(q.internal.callbackArg);
|
|
6922
|
-
arg.q = q.q;
|
|
6923
6902
|
} else {
|
|
6924
|
-
|
|
6925
|
-
}
|
|
6926
|
-
const
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
q.q.relChain = relChain;
|
|
6933
|
-
q.q.outerAliases = outerAliases;
|
|
6934
|
-
return result;
|
|
6903
|
+
base = q;
|
|
6904
|
+
}
|
|
6905
|
+
const arg = Object.create(base);
|
|
6906
|
+
arg.q = getClonedQueryData(q.q);
|
|
6907
|
+
arg.q.subQuery = 1;
|
|
6908
|
+
arg.q.relChain = void 0;
|
|
6909
|
+
arg.q.outerAliases = q.q.aliases;
|
|
6910
|
+
return cb(arg);
|
|
6935
6911
|
};
|
|
6936
6912
|
const joinSubQuery = (q, sub) => {
|
|
6937
6913
|
if (!("relationConfig" in sub)) return sub;
|
|
@@ -8147,7 +8123,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
|
|
|
8147
8123
|
);
|
|
8148
8124
|
} else {
|
|
8149
8125
|
if (typeof item[key] === "function") {
|
|
8150
|
-
item[key] =
|
|
8126
|
+
item[key] = resolveSubQueryCallbackV2(
|
|
8151
8127
|
q,
|
|
8152
8128
|
item[key]
|
|
8153
8129
|
);
|
|
@@ -9073,21 +9049,22 @@ class Having {
|
|
|
9073
9049
|
}
|
|
9074
9050
|
}
|
|
9075
9051
|
|
|
9076
|
-
const before = (q, key, cb) =>
|
|
9077
|
-
const after = (
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
const
|
|
9052
|
+
const before = (q, key, cb) => pushQueryValueImmutable(q, `before${key}`, cb);
|
|
9053
|
+
const after = (query, key, select, cb, commit) => {
|
|
9054
|
+
const q = query;
|
|
9055
|
+
pushQueryValueImmutable(q, `after${key}${commit ? "Commit" : ""}`, cb);
|
|
9056
|
+
const prop = `after${key}Select`;
|
|
9057
|
+
const set = q.q[prop] = new Set(q.q[prop]);
|
|
9081
9058
|
for (const column of select) {
|
|
9082
9059
|
set.add(column);
|
|
9083
9060
|
}
|
|
9084
|
-
return
|
|
9061
|
+
return query;
|
|
9085
9062
|
};
|
|
9086
9063
|
const _queryHookBeforeQuery = (q, cb) => {
|
|
9087
|
-
return
|
|
9064
|
+
return pushQueryValueImmutable(q, "before", cb);
|
|
9088
9065
|
};
|
|
9089
9066
|
const _queryHookAfterQuery = (q, cb) => {
|
|
9090
|
-
return
|
|
9067
|
+
return pushQueryValueImmutable(q, "after", cb);
|
|
9091
9068
|
};
|
|
9092
9069
|
const _queryHookBeforeCreate = (q, cb) => {
|
|
9093
9070
|
return before(q, "Create", cb);
|
|
@@ -9903,11 +9880,11 @@ class Join {
|
|
|
9903
9880
|
* @param cb - {@link JoinLateralCallback}
|
|
9904
9881
|
*/
|
|
9905
9882
|
joinLateral(arg, cb) {
|
|
9883
|
+
const q = _clone(this);
|
|
9906
9884
|
return _joinLateral(
|
|
9907
|
-
|
|
9885
|
+
q,
|
|
9908
9886
|
"JOIN",
|
|
9909
|
-
arg,
|
|
9910
|
-
cb
|
|
9887
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9911
9888
|
);
|
|
9912
9889
|
}
|
|
9913
9890
|
/**
|
|
@@ -9926,28 +9903,32 @@ class Join {
|
|
|
9926
9903
|
* @param cb - {@link JoinLateralCallback}
|
|
9927
9904
|
*/
|
|
9928
9905
|
leftJoinLateral(arg, cb) {
|
|
9906
|
+
const q = _clone(this);
|
|
9929
9907
|
return _joinLateral(
|
|
9930
9908
|
_clone(this),
|
|
9931
9909
|
"LEFT JOIN",
|
|
9932
|
-
arg,
|
|
9933
|
-
cb
|
|
9910
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9934
9911
|
);
|
|
9935
9912
|
}
|
|
9936
9913
|
}
|
|
9937
9914
|
const makeOnItem = (joinTo, joinFrom, args) => ({
|
|
9938
9915
|
ON: {
|
|
9939
|
-
joinTo,
|
|
9940
9916
|
joinFrom,
|
|
9941
|
-
|
|
9917
|
+
from: args[0],
|
|
9918
|
+
joinTo,
|
|
9919
|
+
to: args.length === 2 ? args[1] : args[2],
|
|
9920
|
+
op: args.length === 2 ? void 0 : args[1]
|
|
9942
9921
|
}
|
|
9943
9922
|
});
|
|
9944
9923
|
const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
|
|
9945
9924
|
return pushQueryValue(q, "and", {
|
|
9946
9925
|
ON: {
|
|
9947
|
-
joinTo: joinFrom,
|
|
9948
9926
|
joinFrom: joinTo,
|
|
9927
|
+
from: on[0],
|
|
9928
|
+
joinTo: joinFrom,
|
|
9929
|
+
to: on.length === 2 ? on[1] : on[2],
|
|
9949
9930
|
useOuterAliases: true,
|
|
9950
|
-
on
|
|
9931
|
+
op: on.length === 2 ? void 0 : on[1]
|
|
9951
9932
|
}
|
|
9952
9933
|
});
|
|
9953
9934
|
};
|
|
@@ -10365,11 +10346,11 @@ const _queryUpdate = (query, arg) => {
|
|
|
10365
10346
|
} else {
|
|
10366
10347
|
let value = set[key];
|
|
10367
10348
|
if (typeof value === "function") {
|
|
10368
|
-
value =
|
|
10349
|
+
value = resolveSubQueryCallbackV2(
|
|
10369
10350
|
query.baseQuery,
|
|
10370
10351
|
value
|
|
10371
10352
|
);
|
|
10372
|
-
if (value instanceof Db && value.q.type) {
|
|
10353
|
+
if (value instanceof Db && value.q.type && value.q.subQuery) {
|
|
10373
10354
|
throw new OrchidOrmInternalError(
|
|
10374
10355
|
value,
|
|
10375
10356
|
`Only selecting queries are allowed inside callback of update, ${value.q.type} is given instead.`
|
|
@@ -10491,7 +10472,7 @@ class Update {
|
|
|
10491
10472
|
*
|
|
10492
10473
|
* // use query that returns a single value
|
|
10493
10474
|
* // returning multiple values will result in Postgres error
|
|
10494
|
-
* column3: db.otherTable.get('someColumn'),
|
|
10475
|
+
* column3: () => db.otherTable.get('someColumn'),
|
|
10495
10476
|
*
|
|
10496
10477
|
* // select a single value from a related record
|
|
10497
10478
|
* fromRelation: (q) => q.relatedTable.get('someColumn'),
|
|
@@ -10508,16 +10489,16 @@ class Update {
|
|
|
10508
10489
|
* ```ts
|
|
10509
10490
|
* await db.table.where({ ...conditions }).update({
|
|
10510
10491
|
* // `column` will be set to a value of the `otherColumn` of the created record.
|
|
10511
|
-
* column: db.otherTable.get('otherColumn').create({ ...data }),
|
|
10492
|
+
* column: () => db.otherTable.get('otherColumn').create({ ...data }),
|
|
10512
10493
|
*
|
|
10513
10494
|
* // `column2` will be set to a value of the `otherColumn` of the updated record.
|
|
10514
|
-
* column2: db.otherTable
|
|
10495
|
+
* column2: () => db.otherTable
|
|
10515
10496
|
* .get('otherColumn')
|
|
10516
10497
|
* .findBy({ ...conditions })
|
|
10517
10498
|
* .update({ key: 'value' }),
|
|
10518
10499
|
*
|
|
10519
10500
|
* // `column3` will be set to a value of the `otherColumn` of the deleted record.
|
|
10520
|
-
* column3: db.otherTable
|
|
10501
|
+
* column3: () => db.otherTable
|
|
10521
10502
|
* .get('otherColumn')
|
|
10522
10503
|
* .findBy({ ...conditions })
|
|
10523
10504
|
* .delete(),
|
|
@@ -10999,7 +10980,7 @@ function orCreate(query, data, updateData, mergeData) {
|
|
|
10999
10980
|
q.handleResult = (q2, t, r, s) => {
|
|
11000
10981
|
return created ? result : handleResult(q2, t, r, s);
|
|
11001
10982
|
};
|
|
11002
|
-
q.hookSelect
|
|
10983
|
+
q.hookSelect = new Map(q.hookSelect);
|
|
11003
10984
|
q.patchResult = async (q2, hookSelect, queryResult) => {
|
|
11004
10985
|
var _a, _b;
|
|
11005
10986
|
if (queryResult.rowCount === 0) {
|
|
@@ -12164,52 +12145,6 @@ class QueryMethods {
|
|
|
12164
12145
|
none() {
|
|
12165
12146
|
return _queryNone(this);
|
|
12166
12147
|
}
|
|
12167
|
-
/**
|
|
12168
|
-
* `modify` allows modifying the query with your function:
|
|
12169
|
-
*
|
|
12170
|
-
* ```ts
|
|
12171
|
-
* const doSomethingWithQuery = (q: typeof db.table) => {
|
|
12172
|
-
* // can use all query methods
|
|
12173
|
-
* return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
|
|
12174
|
-
* };
|
|
12175
|
-
*
|
|
12176
|
-
* const record = await db.table.select('id').modify(doSomethingWithQuery).find(1);
|
|
12177
|
-
*
|
|
12178
|
-
* record.id; // id was selected before `modify`
|
|
12179
|
-
* record.name; // name was selected by the function
|
|
12180
|
-
* ```
|
|
12181
|
-
*
|
|
12182
|
-
* It's possible to apply different `select`s inside the function, and then the result type will be a union of all possibilities:
|
|
12183
|
-
*
|
|
12184
|
-
* Use this sparingly as it complicates dealing with the result.
|
|
12185
|
-
*
|
|
12186
|
-
* ```ts
|
|
12187
|
-
* const doSomethingWithQuery = (q: typeof db.table) => {
|
|
12188
|
-
* if (Math.random() > 0.5) {
|
|
12189
|
-
* return q.select('one');
|
|
12190
|
-
* } else {
|
|
12191
|
-
* return q.select('two');
|
|
12192
|
-
* }
|
|
12193
|
-
* };
|
|
12194
|
-
*
|
|
12195
|
-
* const record = await db.table.modify(doSomethingWithQuery).find(1);
|
|
12196
|
-
*
|
|
12197
|
-
* // TS error: we don't know for sure if the `one` was selected.
|
|
12198
|
-
* record.one;
|
|
12199
|
-
*
|
|
12200
|
-
* // use `in` operator to disambiguate the result type
|
|
12201
|
-
* if ('one' in record) {
|
|
12202
|
-
* record.one;
|
|
12203
|
-
* } else {
|
|
12204
|
-
* record.two;
|
|
12205
|
-
* }
|
|
12206
|
-
* ```
|
|
12207
|
-
*
|
|
12208
|
-
* @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.
|
|
12209
|
-
*/
|
|
12210
|
-
modify(fn) {
|
|
12211
|
-
return fn(this);
|
|
12212
|
-
}
|
|
12213
12148
|
/**
|
|
12214
12149
|
* Use `makeHelper` to make a query helper - a function where you can modify the query, and reuse this function across different places.
|
|
12215
12150
|
*
|
|
@@ -12271,6 +12206,65 @@ class QueryMethods {
|
|
|
12271
12206
|
return fn(q, ...args);
|
|
12272
12207
|
};
|
|
12273
12208
|
}
|
|
12209
|
+
/**
|
|
12210
|
+
* `modify` allows modifying the query with helpers defined with {@link makeHelper}:
|
|
12211
|
+
*
|
|
12212
|
+
* ```ts
|
|
12213
|
+
* const helper = db.table.makeHelper((q) => {
|
|
12214
|
+
* // all query methods are available
|
|
12215
|
+
* return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
|
|
12216
|
+
* });
|
|
12217
|
+
*
|
|
12218
|
+
* const record = await db.table.select('id').modify(helper).find(1);
|
|
12219
|
+
*
|
|
12220
|
+
* record.id; // id was selected before `modify`
|
|
12221
|
+
* record.name; // name was selected by the function
|
|
12222
|
+
* ```
|
|
12223
|
+
*
|
|
12224
|
+
* When the helper result isn't certain, it will result in a union of all possibilities.
|
|
12225
|
+
* Use this sparingly as it complicates dealing with the result.
|
|
12226
|
+
*
|
|
12227
|
+
* ```ts
|
|
12228
|
+
* const helper = db.table((q) => {
|
|
12229
|
+
* if (Math.random() > 0.5) {
|
|
12230
|
+
* return q.select('one');
|
|
12231
|
+
* } else {
|
|
12232
|
+
* return q.select('two');
|
|
12233
|
+
* }
|
|
12234
|
+
* });
|
|
12235
|
+
*
|
|
12236
|
+
* const record = await db.table.modify(helper).find(1);
|
|
12237
|
+
*
|
|
12238
|
+
* // TS error: we don't know for sure if the `one` was selected.
|
|
12239
|
+
* record.one;
|
|
12240
|
+
*
|
|
12241
|
+
* // use `in` operator to disambiguate the result type
|
|
12242
|
+
* if ('one' in record) {
|
|
12243
|
+
* record.one;
|
|
12244
|
+
* } else {
|
|
12245
|
+
* record.two;
|
|
12246
|
+
* }
|
|
12247
|
+
* ```
|
|
12248
|
+
*
|
|
12249
|
+
* You can define and pass parameters:
|
|
12250
|
+
*
|
|
12251
|
+
* ```ts
|
|
12252
|
+
* const helper = db.table.makeHelper((q, select: 'id' | 'name') => {
|
|
12253
|
+
* return q.select(select);
|
|
12254
|
+
* });
|
|
12255
|
+
*
|
|
12256
|
+
* const record = await db.table.modify(helper, 'id').find(1);
|
|
12257
|
+
* // record has type { id: number } | { name: string }
|
|
12258
|
+
* if ('id' in record) {
|
|
12259
|
+
* record.id;
|
|
12260
|
+
* }
|
|
12261
|
+
* ```
|
|
12262
|
+
*
|
|
12263
|
+
* @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.
|
|
12264
|
+
*/
|
|
12265
|
+
modify(fn, ...args) {
|
|
12266
|
+
return fn(this, ...args);
|
|
12267
|
+
}
|
|
12274
12268
|
/**
|
|
12275
12269
|
* Narrows a part of the query output type.
|
|
12276
12270
|
* Use with caution, type-safety isn't guaranteed with it.
|
|
@@ -12908,5 +12902,5 @@ function copyTableData(query, arg) {
|
|
|
12908
12902
|
return q;
|
|
12909
12903
|
}
|
|
12910
12904
|
|
|
12911
|
-
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, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, 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, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode,
|
|
12905
|
+
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, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, 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, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql$1 as rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
12912
12906
|
//# sourceMappingURL=index.mjs.map
|