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