pqb 0.40.9 → 0.40.10

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.mjs CHANGED
@@ -2576,6 +2576,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2576
2576
  s: joinSubQuery
2577
2577
  };
2578
2578
  };
2579
+ const preprocessJoinArg = (q, arg) => {
2580
+ if (typeof arg !== "function")
2581
+ return arg;
2582
+ arg = arg(q.relations);
2583
+ arg.joinQueryAfterCallback = arg.joinQuery;
2584
+ return arg;
2585
+ };
2579
2586
  const makeJoinQueryBuilder = (joinedQuery, joinedShapes, joinTo) => {
2580
2587
  const q = joinedQuery.baseQuery.clone();
2581
2588
  q.baseQuery = q;
@@ -2638,10 +2645,7 @@ const _join = (query, require2, type, first, args) => {
2638
2645
  let batchParsers;
2639
2646
  let computeds;
2640
2647
  let joinSubQuery = false;
2641
- if (typeof first === "function") {
2642
- first = first(query.relations);
2643
- first.joinQueryAfterCallback = first.joinQuery;
2644
- }
2648
+ first = preprocessJoinArg(query, first);
2645
2649
  if (typeof first === "object") {
2646
2650
  if (require2 && isQueryNone(first)) {
2647
2651
  return _queryNone(query);
@@ -9812,7 +9816,13 @@ const _queryWhereIn = (q, and, arg, values, not) => {
9812
9816
  return q;
9813
9817
  };
9814
9818
  const existsArgs = (self, q, args) => {
9815
- const joinArgs = processJoinArgs(self, q, args, false, true);
9819
+ const joinArgs = processJoinArgs(
9820
+ self,
9821
+ preprocessJoinArg(self, q),
9822
+ args,
9823
+ false,
9824
+ true
9825
+ );
9816
9826
  return [
9817
9827
  {
9818
9828
  EXISTS: joinArgs
@@ -10455,6 +10465,10 @@ class Where {
10455
10465
  * // find by a relation name if it's defined
10456
10466
  * db.user.whereExists('account');
10457
10467
  *
10468
+ * // find users who have an account with positive balance
10469
+ * // `accounts` is a relation name
10470
+ * db.user.whereExists((q) => q.accounts.where({ balance: { gt: 0 } }));
10471
+ *
10458
10472
  * // find using a table and a join conditions
10459
10473
  * db.user.whereExists(db.account, 'account.id', 'user.id');
10460
10474
  *