pqb 0.67.7 → 0.68.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
@@ -315,6 +315,29 @@ const templateLiteralSQLToCode = (sql) => {
315
315
  code += parts[i];
316
316
  return code + "`";
317
317
  };
318
+ var SqlJoinExpression = class extends Expression {
319
+ constructor(items, separator) {
320
+ super();
321
+ this.items = items;
322
+ this.separator = separator;
323
+ this.result = { value: emptyObject };
324
+ this.q = { expr: this };
325
+ }
326
+ makeSQL(ctx, quotedAs) {
327
+ let sql = "";
328
+ for (let i = 0; i < this.items.length; i++) {
329
+ if (i > 0) sql += this.separator ? this.separator.toSQL(ctx, quotedAs) : ", ";
330
+ const item = this.items[i];
331
+ if (item instanceof Expression) sql += item.toSQL(ctx, quotedAs);
332
+ else {
333
+ ctx.values.push(item);
334
+ sql += `$${ctx.values.length}`;
335
+ }
336
+ }
337
+ return sql;
338
+ }
339
+ };
340
+ SqlJoinExpression.prototype.type = ExpressionTypeMethod.prototype.type;
318
341
  /**
319
342
  * Expression for a SQL identifier reference.
320
343
  * Used to safely quote identifiers in raw SQL queries.
@@ -435,6 +458,7 @@ const sqlFn = ((...args) => {
435
458
  return (...args) => new RawSql(args, arg);
436
459
  });
437
460
  sqlFn.ref = (name) => new SqlRefExpression(name);
461
+ sqlFn.join = (items, separator) => new SqlJoinExpression(items, separator);
438
462
  sqlFn.unsafe = (sql) => new UnsafeSqlExpression(sql);
439
463
  var UnsafeSqlExpression = class extends Expression {
440
464
  constructor(sql) {
@@ -1849,9 +1873,11 @@ const ordinalText = {
1849
1873
  };
1850
1874
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1851
1875
  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" : ""})`;
1876
+ const shouldEncodeJson = (ctx) => ctx.q.adapter.driverAdapter.schemaConfig?.jsonEncodedByDriver === false;
1852
1877
  const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
1853
1878
  if (arg && typeof arg === "object") {
1854
- if (IN && Array.isArray(arg)) return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value)) + "::jsonb").join(", ")})`;
1879
+ if (IN && Array.isArray(arg)) return `(${arg.map((value) => shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(value)) : addValue(ctx.values, value)).join(", ")})`;
1880
+ if (Array.isArray(arg)) return shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(arg)) : addValue(ctx.values, arg);
1855
1881
  if (isExpression(arg)) return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
1856
1882
  if ("toSQL" in arg) return `to_jsonb((${moveMutativeQueryToCte$1(ctx, arg)}))`;
1857
1883
  }
@@ -14237,6 +14263,7 @@ function _createDbSqlMethod(columnTypes) {
14237
14263
  return sql;
14238
14264
  });
14239
14265
  fn.ref = sqlFn.ref;
14266
+ fn.join = sqlFn.join;
14240
14267
  fn.unsafe = sqlFn.unsafe;
14241
14268
  return fn;
14242
14269
  }