pqb 0.18.34 → 0.19.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.mjs CHANGED
@@ -1072,7 +1072,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs, not) => {
1072
1072
  const res = data(qb);
1073
1073
  const expr = res instanceof Expression ? res : res.q.expr;
1074
1074
  if (!(res instanceof Expression) && res.q.expr) {
1075
- const q = "relationConfig" in res ? res.relationConfig.joinQuery(table, res) : res.clone();
1075
+ const q = "relationConfig" in res ? res.relationConfig.joinQuery(res, table) : res.clone();
1076
1076
  q.q.select = [expr];
1077
1077
  ands.push(`${prefix}(${makeSQL(q, ctx).text})`);
1078
1078
  } else {
@@ -1306,7 +1306,7 @@ const processJoinItem = (ctx, table, query, item, quotedAs) => {
1306
1306
  if (typeof first === "string") {
1307
1307
  if (first in table.relations) {
1308
1308
  const { query: toQuery, joinQuery } = table.relations[first].relationConfig;
1309
- const jq = joinQuery(table, toQuery);
1309
+ const jq = joinQuery(toQuery, table);
1310
1310
  const { q: j } = jq;
1311
1311
  const tableName = typeof j.from === "string" ? j.from : jq.table;
1312
1312
  target = quoteSchemaAndTable(j.schema, tableName);
@@ -1434,8 +1434,8 @@ const processArgs = (args, ctx, table, query, first, joinAs, joinShape, quotedAs
1434
1434
  base = base.as(q.q.as);
1435
1435
  }
1436
1436
  const { q: query2 } = first.joinQueryAfterCallback(
1437
- table,
1438
- base
1437
+ base,
1438
+ table
1439
1439
  );
1440
1440
  if (query2.and) {
1441
1441
  pushQueryArray(q, "and", query2.and);
@@ -2429,16 +2429,18 @@ const makeRegexToFindInSql = (value) => {
2429
2429
  return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
2430
2430
  };
2431
2431
  const resolveSubQueryCallback = (q, cb) => {
2432
- const { isSubQuery } = q.q;
2432
+ const { isSubQuery, relChain } = q.q;
2433
2433
  q.q.isSubQuery = true;
2434
+ q.q.relChain = void 0;
2434
2435
  const result = cb(q);
2435
2436
  q.q.isSubQuery = isSubQuery;
2437
+ q.q.relChain = relChain;
2436
2438
  return result;
2437
2439
  };
2438
2440
  const joinSubQuery = (q, sub) => {
2439
2441
  if (!("relationConfig" in sub))
2440
2442
  return sub;
2441
- return sub.relationConfig.joinQuery(q, sub);
2443
+ return sub.relationConfig.joinQuery(sub, q);
2442
2444
  };
2443
2445
 
2444
2446
  const pushQueryArray = (q, key, value) => {
@@ -5814,8 +5816,8 @@ const _joinLateral = (q, type, arg, cb, as) => {
5814
5816
  let result = cb(query);
5815
5817
  if (relation) {
5816
5818
  result = relation.relationConfig.joinQuery(
5817
- q,
5818
- result
5819
+ result,
5820
+ q
5819
5821
  );
5820
5822
  }
5821
5823
  const joinKey = as || result.q.as || result.table;
@@ -5886,7 +5888,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5886
5888
  if (typeof value === "function") {
5887
5889
  value = resolveSubQueryCallback(q, value);
5888
5890
  if (!isExpression(value) && value.joinQuery) {
5889
- value = value.joinQuery(q, value);
5891
+ value = value.joinQuery(value, q);
5890
5892
  let query;
5891
5893
  const returnType = value.q.returnType;
5892
5894
  if (!returnType || returnType === "all") {