pqb 0.43.3 → 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(
@@ -7489,6 +7513,7 @@ function makeFnExpression(self, type, fn, args, options) {
7489
7513
  options,
7490
7514
  type
7491
7515
  );
7516
+ q.q.transform = void 0;
7492
7517
  return q;
7493
7518
  }
7494
7519