pqb 0.36.14 → 0.36.16

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
@@ -1268,11 +1268,17 @@ class TextBaseColumn extends ColumnType {
1268
1268
  }
1269
1269
  class LimitedTextBaseColumn extends TextBaseColumn {
1270
1270
  constructor(schema, limit) {
1271
- super(schema, schema.stringMax(limit));
1271
+ super(
1272
+ schema,
1273
+ limit !== void 0 ? schema.stringMax(limit) : schema.stringSchema()
1274
+ );
1272
1275
  this.data.maxChars = limit;
1273
1276
  }
1274
1277
  toSQL() {
1275
- return joinTruthy(this.dataType, `(${this.data.maxChars})`);
1278
+ return joinTruthy(
1279
+ this.dataType,
1280
+ this.data.maxChars !== void 0 && `(${this.data.maxChars})`
1281
+ );
1276
1282
  }
1277
1283
  }
1278
1284
  class VarCharColumn extends LimitedTextBaseColumn {
@@ -2591,7 +2597,7 @@ var __spreadValues$g = (a, b) => {
2591
2597
  return a;
2592
2598
  };
2593
2599
  var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
2594
- const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2600
+ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2595
2601
  var _a;
2596
2602
  if (typeof first === "string") {
2597
2603
  if (first in joinTo.relations) {
@@ -2601,7 +2607,11 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2601
2607
  const r = args[0](
2602
2608
  makeJoinQueryBuilder(j, j.q.joinedShapes, joinTo)
2603
2609
  );
2604
- return { j: j.merge(r), s: joinSubQuery || getIsJoinSubQuery(r), r };
2610
+ return {
2611
+ j: j.merge(r),
2612
+ s: whereExists ? false : joinSubQuery || getIsJoinSubQuery(r),
2613
+ r
2614
+ };
2605
2615
  }
2606
2616
  return { j, s: joinSubQuery };
2607
2617
  } else if (typeof args[0] !== "function") {
@@ -2633,7 +2643,11 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2633
2643
  joinTo
2634
2644
  )
2635
2645
  );
2636
- return { w: first, r, s: joinSubQuery || getIsJoinSubQuery(r) };
2646
+ return {
2647
+ w: first,
2648
+ r,
2649
+ s: whereExists ? false : joinSubQuery || getIsJoinSubQuery(r)
2650
+ };
2637
2651
  }
2638
2652
  }
2639
2653
  const args0 = args.length ? args[0] : returnArg$1;
@@ -5258,7 +5272,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
5258
5272
  const column = q.shape[key];
5259
5273
  quotedColumns[0] = `"${(column == null ? void 0 : column.data.name) || key}"`;
5260
5274
  if (Array.isArray(values) && Array.isArray(values[0])) {
5261
- values = [[void 0]];
5275
+ values = values.map(() => [void 0]);
5262
5276
  }
5263
5277
  }
5264
5278
  ctx.sql.push(
@@ -7148,7 +7162,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
7148
7162
  item[key]
7149
7163
  );
7150
7164
  }
7151
- if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape)) {
7165
+ if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
7152
7166
  ctx.columns.set(key, ctx.columns.size);
7153
7167
  encoders[key] = (_c = shape[key]) == null ? void 0 : _c.encodeFn;
7154
7168
  }
@@ -7159,11 +7173,6 @@ const createCtx = () => ({
7159
7173
  columns: /* @__PURE__ */ new Map(),
7160
7174
  resultAll: void 0
7161
7175
  });
7162
- const mapColumnValues = (columns, encoders, data) => {
7163
- return columns.map(
7164
- (key) => encoders[key] && !isExpression(data[key]) ? encoders[key](data[key]) : data[key]
7165
- );
7166
- };
7167
7176
  const handleOneData = (q, data, ctx) => {
7168
7177
  const encoders = {};
7169
7178
  const defaults = q.q.defaults;
@@ -7172,7 +7181,14 @@ const handleOneData = (q, data, ctx) => {
7172
7181
  }
7173
7182
  processCreateItem(q, data, 0, ctx, encoders);
7174
7183
  const columns = Array.from(ctx.columns.keys());
7175
- const values = [mapColumnValues(columns, encoders, data)];
7184
+ const values = [
7185
+ columns.map(
7186
+ (key) => (
7187
+ // undefined values were stripped and no need to check for them
7188
+ encoders[key] && !isExpression(data[key]) ? encoders[key](data[key]) : data[key]
7189
+ )
7190
+ )
7191
+ ];
7176
7192
  return { columns, values };
7177
7193
  };
7178
7194
  const handleManyData = (q, data, ctx) => {
@@ -7187,7 +7203,9 @@ const handleManyData = (q, data, ctx) => {
7187
7203
  const values = Array(data.length);
7188
7204
  const columns = Array.from(ctx.columns.keys());
7189
7205
  data.forEach((item, i) => {
7190
- values[i] = mapColumnValues(columns, encoders, item);
7206
+ values[i] = columns.map(
7207
+ (key) => encoders[key] && item[key] !== void 0 && !isExpression(item[key]) ? encoders[key](item[key]) : item[key]
7208
+ );
7191
7209
  });
7192
7210
  return { columns, values };
7193
7211
  };
@@ -9452,20 +9470,7 @@ const _queryWhereIn = (q, and, arg, values, not) => {
9452
9470
  return q;
9453
9471
  };
9454
9472
  const existsArgs = (self, q, args) => {
9455
- let joinSubQuery;
9456
- if (typeof q === "object") {
9457
- joinSubQuery = getIsJoinSubQuery(q);
9458
- if (joinSubQuery) {
9459
- q = q.clone();
9460
- q.shape = getShapeFromSelect(
9461
- q,
9462
- true
9463
- );
9464
- }
9465
- } else {
9466
- joinSubQuery = false;
9467
- }
9468
- const joinArgs = processJoinArgs(self, q, args, joinSubQuery);
9473
+ const joinArgs = processJoinArgs(self, q, args, false, true);
9469
9474
  return [
9470
9475
  {
9471
9476
  EXISTS: joinArgs