pqb 0.45.4 → 0.45.5

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
@@ -1104,8 +1104,35 @@ const text = {
1104
1104
  };
1105
1105
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1106
1106
  const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${options?.vars ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
1107
+ const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
1108
+ if (arg && typeof arg === "object") {
1109
+ if (IN && Array.isArray(arg)) {
1110
+ return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value)) + "::jsonb").join(", ")})`;
1111
+ }
1112
+ if (isExpression(arg)) {
1113
+ return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
1114
+ }
1115
+ if ("toSQL" in arg) {
1116
+ return `to_jsonb((${getSqlText(
1117
+ arg.toSQL({ values: ctx.values })
1118
+ )}))`;
1119
+ }
1120
+ }
1121
+ return addValue(ctx.values, JSON.stringify(arg)) + "::jsonb";
1122
+ };
1107
1123
  const json = {
1108
- ...base,
1124
+ equals: make(
1125
+ (key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NULL` : `${key} = ${quoteJsonValue(value, ctx, quotedAs)}`
1126
+ ),
1127
+ not: make(
1128
+ (key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NOT NULL` : `${key} != ${quoteJsonValue(value, ctx, quotedAs)}`
1129
+ ),
1130
+ in: make(
1131
+ (key, value, ctx, quotedAs) => `${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`
1132
+ ),
1133
+ notIn: make(
1134
+ (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`
1135
+ ),
1109
1136
  jsonPathQueryFirst: Object.assign(
1110
1137
  function(path, options) {
1111
1138
  const { q, columnTypes } = this;