pqb 0.43.2 → 0.43.4

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
@@ -1001,9 +1001,9 @@ const makeVarArg = (_op) => {
1001
1001
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1002
1002
  );
1003
1003
  };
1004
- const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
1004
+ const quoteValue = (arg, ctx, quotedAs, IN) => {
1005
1005
  if (arg && typeof arg === "object") {
1006
- if (!jsonArray && Array.isArray(arg)) {
1006
+ if (IN && Array.isArray(arg)) {
1007
1007
  return `(${arg.map((value) => addValue(ctx.values, value)).join(", ")})`;
1008
1008
  }
1009
1009
  if (isExpression(arg)) {
@@ -1039,10 +1039,10 @@ const base = {
1039
1039
  (key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`
1040
1040
  ),
1041
1041
  in: make(
1042
- (key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs)}`
1042
+ (key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs, true)}`
1043
1043
  ),
1044
1044
  notIn: make(
1045
- (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
1045
+ (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs, true)}`
1046
1046
  )
1047
1047
  };
1048
1048
  const boolean = {
@@ -1124,10 +1124,10 @@ const json = {
1124
1124
  { _op: jsonPathQueryOp }
1125
1125
  ),
1126
1126
  jsonSupersetOf: make(
1127
- (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs, true)}`
1127
+ (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs)}`
1128
1128
  ),
1129
1129
  jsonSubsetOf: make(
1130
- (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs, true)}`
1130
+ (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs)}`
1131
1131
  ),
1132
1132
  jsonSet: makeVarArg(
1133
1133
  (key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
@@ -1151,6 +1151,30 @@ const json = {
1151
1151
  (key, [path], ctx) => `(${key} #- ${encodeJsonPath(ctx, path)})`
1152
1152
  )
1153
1153
  };
1154
+ const array = {
1155
+ ...base,
1156
+ has: make(
1157
+ (key, value, ctx, quotedAs) => `${quoteValue(value, ctx, quotedAs)} = ANY(${key})`
1158
+ ),
1159
+ hasEvery: make(
1160
+ (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs)}`
1161
+ ),
1162
+ hasSome: make(
1163
+ (key, value, ctx, quotedAs) => `${key} && ${quoteValue(value, ctx, quotedAs)}`
1164
+ ),
1165
+ containedIn: make(
1166
+ (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs)}`
1167
+ ),
1168
+ length: make((key, value, ctx, quotedAs) => {
1169
+ const expr = `COALESCE(array_length(${key}, 1), 0)`;
1170
+ return typeof value === "number" ? `${expr} = ${quoteValue(value, ctx, quotedAs)}` : Object.keys(value).map(
1171
+ (key2) => (
1172
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1173
+ numeric[key2]._op(expr, value[key2], ctx, quotedAs)
1174
+ )
1175
+ ).join(" AND ");
1176
+ })
1177
+ };
1154
1178
  const Operators = {
1155
1179
  any: base,
1156
1180
  boolean,
@@ -1159,7 +1183,7 @@ const Operators = {
1159
1183
  time: numeric,
1160
1184
  text,
1161
1185
  json,
1162
- array: base
1186
+ array
1163
1187
  };
1164
1188
 
1165
1189
  class TextBaseColumn extends ColumnType {
@@ -2136,7 +2160,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2136
2160
  } else if (key === "SEARCH") {
2137
2161
  const search = value;
2138
2162
  ands.push(`${search.vectorSQL} @@ "${search.as}"`);
2139
- } else if (typeof value === "object" && value && !(value instanceof Date)) {
2163
+ } else if (typeof value === "object" && value && !(value instanceof Date) && !Array.isArray(value)) {
2140
2164
  if (isExpression(value)) {
2141
2165
  ands.push(
2142
2166
  `${columnToSql(
@@ -5763,9 +5787,10 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
5763
5787
  }
5764
5788
  pushWhereStatementSql(ctx, q, query, quotedAs);
5765
5789
  let returning;
5766
- if (inCTE?.selectNum) {
5790
+ if (inCTE) {
5791
+ const select = inCTE.returning?.select;
5767
5792
  returning = {
5768
- select: inCTE.returning?.select ? "1, " + inCTE.returning.select : "1",
5793
+ select: inCTE.selectNum || !select ? select ? "1, " + select : "1" : select,
5769
5794
  hookSelect: inCTE.returning?.hookSelect
5770
5795
  };
5771
5796
  } else {
@@ -5961,8 +5986,6 @@ const makeReturningSql = (ctx, q, data, quotedAs, hookSelectI, addHookSelectI) =
5961
5986
  let sql;
5962
5987
  if (tempSelect?.size || select?.length) {
5963
5988
  sql = selectToSql(ctx, q, data, quotedAs, tempSelect, void 0, true);
5964
- } else if (addHookSelectI) {
5965
- sql = "1";
5966
5989
  }
5967
5990
  return { select: sql, hookSelect: tempSelect };
5968
5991
  };
@@ -5986,7 +6009,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
5986
6009
  query,
5987
6010
  quotedAs
5988
6011
  );
5989
- return query.inCTE.selectNum ? select ? "0, " + select : "0" : select || "";
6012
+ return query.inCTE.selectNum || !select ? select ? "0, " + select : "0" : select;
5990
6013
  }
5991
6014
  let selected;
5992
6015
  const list = [];
@@ -6482,7 +6505,7 @@ const pushUpdateReturning = (ctx, table, query, quotedAs, keyword) => {
6482
6505
  1,
6483
6506
  inCTE && 2
6484
6507
  );
6485
- const s = inCTE?.selectNum ? select ? "0, " + select : "0" : select;
6508
+ const s = inCTE && (inCTE.selectNum || !select) ? select ? "0, " + select : "0" : select;
6486
6509
  if (s) ctx.sql.push(keyword, s);
6487
6510
  return hookSelect;
6488
6511
  };
@@ -7490,6 +7513,7 @@ function makeFnExpression(self, type, fn, args, options) {
7490
7513
  options,
7491
7514
  type
7492
7515
  );
7516
+ q.q.transform = void 0;
7493
7517
  return q;
7494
7518
  }
7495
7519