pqb 0.67.6 → 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.js CHANGED
@@ -338,6 +338,29 @@ const templateLiteralSQLToCode = (sql) => {
338
338
  code += parts[i];
339
339
  return code + "`";
340
340
  };
341
+ var SqlJoinExpression = class extends Expression {
342
+ constructor(items, separator) {
343
+ super();
344
+ this.items = items;
345
+ this.separator = separator;
346
+ this.result = { value: emptyObject };
347
+ this.q = { expr: this };
348
+ }
349
+ makeSQL(ctx, quotedAs) {
350
+ let sql = "";
351
+ for (let i = 0; i < this.items.length; i++) {
352
+ if (i > 0) sql += this.separator ? this.separator.toSQL(ctx, quotedAs) : ", ";
353
+ const item = this.items[i];
354
+ if (item instanceof Expression) sql += item.toSQL(ctx, quotedAs);
355
+ else {
356
+ ctx.values.push(item);
357
+ sql += `$${ctx.values.length}`;
358
+ }
359
+ }
360
+ return sql;
361
+ }
362
+ };
363
+ SqlJoinExpression.prototype.type = ExpressionTypeMethod.prototype.type;
341
364
  /**
342
365
  * Expression for a SQL identifier reference.
343
366
  * Used to safely quote identifiers in raw SQL queries.
@@ -458,6 +481,7 @@ const sqlFn = ((...args) => {
458
481
  return (...args) => new RawSql(args, arg);
459
482
  });
460
483
  sqlFn.ref = (name) => new SqlRefExpression(name);
484
+ sqlFn.join = (items, separator) => new SqlJoinExpression(items, separator);
461
485
  sqlFn.unsafe = (sql) => new UnsafeSqlExpression(sql);
462
486
  var UnsafeSqlExpression = class extends Expression {
463
487
  constructor(sql) {
@@ -1872,9 +1896,11 @@ const ordinalText = {
1872
1896
  };
1873
1897
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1874
1898
  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" : ""})`;
1899
+ const shouldEncodeJson = (ctx) => ctx.q.adapter.driverAdapter.schemaConfig?.jsonEncodedByDriver === false;
1875
1900
  const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
1876
1901
  if (arg && typeof arg === "object") {
1877
- if (IN && Array.isArray(arg)) return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value)) + "::jsonb").join(", ")})`;
1902
+ if (IN && Array.isArray(arg)) return `(${arg.map((value) => shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(value)) : addValue(ctx.values, value)).join(", ")})`;
1903
+ if (Array.isArray(arg)) return shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(arg)) : addValue(ctx.values, arg);
1878
1904
  if (isExpression(arg)) return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
1879
1905
  if ("toSQL" in arg) return `to_jsonb((${moveMutativeQueryToCte$1(ctx, arg)}))`;
1880
1906
  }
@@ -2059,8 +2085,8 @@ var IntervalColumn = class extends Column {
2059
2085
  }
2060
2086
  };
2061
2087
  var ArrayColumn = class ArrayColumn extends Column {
2062
- constructor(schema, item, inputType, defaultEncode, outputType, queryType) {
2063
- super(schema, inputType, outputType, queryType);
2088
+ constructor(schema, item, __inputType, defaultEncode, __outputType, __queryType) {
2089
+ super(schema, __inputType, __outputType, __queryType);
2064
2090
  this.dataType = "array";
2065
2091
  this.operators = Operators.array;
2066
2092
  item.data.isNullable = true;
@@ -2140,8 +2166,8 @@ const parsePostgresArray = (source, entries, transform) => {
2140
2166
  };
2141
2167
  const encodeJson = (x) => x === null ? x : JSON.stringify(x);
2142
2168
  var JSONColumn = class extends Column {
2143
- constructor(schema, inputType, encodedByDriver = true) {
2144
- super(schema, inputType);
2169
+ constructor(schema, __inputType, encodedByDriver = true) {
2170
+ super(schema, __inputType);
2145
2171
  this.dataType = "jsonb";
2146
2172
  this.operators = Operators.json;
2147
2173
  if (!encodedByDriver) this.data.encode = encodeJson;
@@ -2153,10 +2179,10 @@ var JSONColumn = class extends Column {
2153
2179
  };
2154
2180
  var JSONTextColumn = class JSONTextColumn extends Column {
2155
2181
  static get instance() {
2156
- return this._instance ??= new JSONTextColumn(internalSchemaConfig);
2182
+ return this._instance ??= new JSONTextColumn(internalSchemaConfig, void 0);
2157
2183
  }
2158
- constructor(schema) {
2159
- super(schema, schema.stringSchema());
2184
+ constructor(schema, __inputType) {
2185
+ super(schema, __inputType);
2160
2186
  this.dataType = "json";
2161
2187
  this.operators = Operators.text;
2162
2188
  }
@@ -2367,6 +2393,9 @@ const defaultSchemaConfig = (options) => {
2367
2393
  json() {
2368
2394
  return new JSONColumn(schemaConfig, void 0, options?.jsonEncodedByDriver);
2369
2395
  },
2396
+ jsonText() {
2397
+ return new JSONTextColumn(schemaConfig, void 0);
2398
+ },
2370
2399
  setErrors: noop,
2371
2400
  smallint: () => new SmallIntColumn(schemaConfig),
2372
2401
  integer: () => new IntegerColumn(schemaConfig),
@@ -2995,9 +3024,7 @@ const makeColumnTypes = (schema) => {
2995
3024
  return new XMLColumn(schema);
2996
3025
  },
2997
3026
  json: schema.json,
2998
- jsonText() {
2999
- return new JSONTextColumn(schema);
3000
- },
3027
+ jsonText: schema.jsonText,
3001
3028
  type(dataType) {
3002
3029
  return new CustomTypeColumn(schema, dataType);
3003
3030
  },
@@ -11145,7 +11172,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
11145
11172
  if (returnType === "value" || returnType === "valueOrThrow") {
11146
11173
  const type = it.q.getColumn;
11147
11174
  result[key] = type ? mapSubSelectColumn(type, isSubQuery) : UnknownColumn.instance;
11148
- } else result[key] = new JSONTextColumn(internalSchemaConfig);
11175
+ } else result[key] = new JSONTextColumn(internalSchemaConfig, void 0);
11149
11176
  }
11150
11177
  }
11151
11178
  }
@@ -14259,6 +14286,7 @@ function _createDbSqlMethod(columnTypes) {
14259
14286
  return sql;
14260
14287
  });
14261
14288
  fn.ref = sqlFn.ref;
14289
+ fn.join = sqlFn.join;
14262
14290
  fn.unsafe = sqlFn.unsafe;
14263
14291
  return fn;
14264
14292
  }