pqb 0.56.2 → 0.56.3

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
@@ -5712,7 +5712,7 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5712
5712
  }))
5713
5713
  );
5714
5714
  }
5715
- if (query.hookSelect || query.parsers || query.transform) {
5715
+ if (query.hookSelect || query.parsers || query.transform || query.returnType === "oneOrThrow" || query.returnType === "valueOrThrow" || query.returnType === "one" || query.returnType === "value") {
5716
5716
  pushQueryValueImmutable(q, "batchParsers", {
5717
5717
  path: [key],
5718
5718
  fn: (path, queryResult) => {
@@ -5753,7 +5753,7 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5753
5753
  if (returnType === "one") {
5754
5754
  for (const batch of batches) {
5755
5755
  if (batch.data) parseRecord(parsers, batch.data);
5756
- else batch.data = void 0;
5756
+ else batch.parent[batch.key] = batch.data = void 0;
5757
5757
  }
5758
5758
  } else {
5759
5759
  for (const { data } of batches) {
@@ -5763,7 +5763,8 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5763
5763
  }
5764
5764
  } else if (returnType === "one") {
5765
5765
  for (const batch of batches) {
5766
- if (!batch.data) batch.data = void 0;
5766
+ if (!batch.data)
5767
+ batch.parent[batch.key] = batch.data = void 0;
5767
5768
  }
5768
5769
  } else {
5769
5770
  for (const { data } of batches) {
@@ -5790,22 +5791,30 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5790
5791
  }
5791
5792
  case "value":
5792
5793
  case "valueOrThrow": {
5794
+ const notNullable = !query.getColumn?.data.isNullable;
5793
5795
  const parse = query.parsers?.[getValueKey];
5794
5796
  if (parse) {
5795
5797
  if (returnType === "value") {
5796
5798
  for (const item of batches) {
5797
- item.parent[item.key] = item.data = item.data === void 0 ? query.notFoundDefault : parse(item.data);
5799
+ item.parent[item.key] = item.data = item.data === null ? query.notFoundDefault : parse(item.data);
5798
5800
  }
5799
5801
  } else {
5800
5802
  for (const item of batches) {
5801
- if (item.data === void 0)
5803
+ if (notNullable && item.data === null) {
5802
5804
  throw new NotFoundError(arg);
5805
+ }
5803
5806
  item.parent[item.key] = item.data = parse(item.data);
5804
5807
  }
5805
5808
  }
5806
- } else if (returnType !== "value") {
5809
+ } else if (returnType === "value") {
5810
+ for (const item of batches) {
5811
+ if (item.data === null) {
5812
+ item.parent[item.key] = item.data = query.notFoundDefault;
5813
+ }
5814
+ }
5815
+ } else if (notNullable) {
5807
5816
  for (const { data } of batches) {
5808
- if (data === void 0) throw new NotFoundError(arg);
5817
+ if (data === null) throw new NotFoundError(arg);
5809
5818
  }
5810
5819
  }
5811
5820
  if (hookSelect) {
@@ -7839,14 +7848,18 @@ const isSelectingCount = (q) => {
7839
7848
  const { expr } = q.q;
7840
7849
  return expr instanceof FnExpression && expr.fn === "count" && expr.args[0] === "*";
7841
7850
  };
7842
- const int = new IntegerColumn(defaultSchemaConfig).parse(parseInt);
7843
- const float = new RealColumn(defaultSchemaConfig).parse(parseFloat);
7844
- const stringAsNumber = new NumberAsStringBaseColumn(
7851
+ const intNullable = new IntegerColumn(defaultSchemaConfig).nullable().parse(parseInt);
7852
+ const floatNullable = new RealColumn(defaultSchemaConfig).nullable().parse(parseFloat);
7853
+ const booleanNullable = BooleanColumn.instance.nullable();
7854
+ const textNullable = TextColumn.instance.nullable();
7855
+ const jsonTextNullable = JSONTextColumn.instance.nullable();
7856
+ const xmlNullable = XMLColumn.instance.nullable();
7857
+ const stringAsNumberNullable = new NumberAsStringBaseColumn(
7845
7858
  defaultSchemaConfig
7846
- );
7859
+ ).nullable();
7847
7860
  const numericResultColumn = (q, arg) => {
7848
7861
  const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
7849
- return type instanceof NumberBaseColumn ? float : stringAsNumber;
7862
+ return type instanceof NumberBaseColumn ? floatNullable : stringAsNumberNullable;
7850
7863
  };
7851
7864
  class AggregateMethods {
7852
7865
  /**
@@ -7889,7 +7902,13 @@ class AggregateMethods {
7889
7902
  * @param options - aggregation options
7890
7903
  */
7891
7904
  count(arg = "*", options) {
7892
- return makeFnExpression(this, int, "count", [arg], options);
7905
+ return makeFnExpression(
7906
+ this,
7907
+ intNullable,
7908
+ "count",
7909
+ [arg],
7910
+ options
7911
+ );
7893
7912
  }
7894
7913
  /**
7895
7914
  * Get the minimum value for the specified numeric column, returns number or `null` if there are no records.
@@ -8084,7 +8103,7 @@ class AggregateMethods {
8084
8103
  boolAnd(arg, options) {
8085
8104
  return makeFnExpression(
8086
8105
  this,
8087
- BooleanColumn.instance,
8106
+ booleanNullable,
8088
8107
  "bool_and",
8089
8108
  [arg],
8090
8109
  options
@@ -8113,7 +8132,7 @@ class AggregateMethods {
8113
8132
  boolOr(arg, options) {
8114
8133
  return makeFnExpression(
8115
8134
  this,
8116
- BooleanColumn.instance,
8135
+ booleanNullable,
8117
8136
  "bool_or",
8118
8137
  [arg],
8119
8138
  options
@@ -8125,7 +8144,7 @@ class AggregateMethods {
8125
8144
  every(arg, options) {
8126
8145
  return makeFnExpression(
8127
8146
  this,
8128
- BooleanColumn.instance,
8147
+ booleanNullable,
8129
8148
  "every",
8130
8149
  [arg],
8131
8150
  options
@@ -8158,7 +8177,7 @@ class AggregateMethods {
8158
8177
  jsonAgg(arg, options) {
8159
8178
  return makeFnExpression(
8160
8179
  this,
8161
- JSONTextColumn.instance,
8180
+ jsonTextNullable,
8162
8181
  "json_agg",
8163
8182
  [arg],
8164
8183
  options
@@ -8170,7 +8189,7 @@ class AggregateMethods {
8170
8189
  jsonbAgg(arg, options) {
8171
8190
  return makeFnExpression(
8172
8191
  this,
8173
- JSONTextColumn.instance,
8192
+ jsonTextNullable,
8174
8193
  "jsonb_agg",
8175
8194
  [arg],
8176
8195
  options
@@ -8211,7 +8230,7 @@ class AggregateMethods {
8211
8230
  jsonObjectAgg(arg, options) {
8212
8231
  return makeFnExpression(
8213
8232
  this,
8214
- JSONTextColumn.instance,
8233
+ jsonTextNullable,
8215
8234
  "json_object_agg",
8216
8235
  [{ pairs: arg }],
8217
8236
  options
@@ -8223,7 +8242,7 @@ class AggregateMethods {
8223
8242
  jsonbObjectAgg(arg, options) {
8224
8243
  return makeFnExpression(
8225
8244
  this,
8226
- JSONTextColumn.instance,
8245
+ jsonTextNullable,
8227
8246
  "jsonb_object_agg",
8228
8247
  [{ pairs: arg }],
8229
8248
  options
@@ -8254,7 +8273,7 @@ class AggregateMethods {
8254
8273
  stringAgg(arg, delimiter, options) {
8255
8274
  return makeFnExpression(
8256
8275
  this,
8257
- TextColumn.instance,
8276
+ textNullable,
8258
8277
  "string_agg",
8259
8278
  [arg, { value: delimiter }],
8260
8279
  options
@@ -8280,7 +8299,7 @@ class AggregateMethods {
8280
8299
  xmlAgg(arg, options) {
8281
8300
  return makeFnExpression(
8282
8301
  this,
8283
- XMLColumn.instance,
8302
+ xmlNullable,
8284
8303
  "xmlagg",
8285
8304
  [arg],
8286
8305
  options
@@ -8305,7 +8324,7 @@ class AggregateMethods {
8305
8324
  * @param over - OVER clause config
8306
8325
  */
8307
8326
  rowNumber(over) {
8308
- return makeFnExpression(this, int, "row_number", emptyArray, {
8327
+ return makeFnExpression(this, intNullable, "row_number", emptyArray, {
8309
8328
  over
8310
8329
  });
8311
8330
  }
@@ -8328,7 +8347,7 @@ class AggregateMethods {
8328
8347
  * @param over - OVER clause config
8329
8348
  */
8330
8349
  rank(over) {
8331
- return makeFnExpression(this, int, "rank", emptyArray, {
8350
+ return makeFnExpression(this, intNullable, "rank", emptyArray, {
8332
8351
  over
8333
8352
  });
8334
8353
  }
@@ -8351,7 +8370,7 @@ class AggregateMethods {
8351
8370
  * @param over - OVER clause config
8352
8371
  */
8353
8372
  denseRank(over) {
8354
- return makeFnExpression(this, int, "dense_rank", emptyArray, {
8373
+ return makeFnExpression(this, intNullable, "dense_rank", emptyArray, {
8355
8374
  over
8356
8375
  });
8357
8376
  }
@@ -8374,7 +8393,7 @@ class AggregateMethods {
8374
8393
  * @param over - OVER clause config
8375
8394
  */
8376
8395
  percentRank(over) {
8377
- return makeFnExpression(this, int, "percent_rank", emptyArray, {
8396
+ return makeFnExpression(this, intNullable, "percent_rank", emptyArray, {
8378
8397
  over
8379
8398
  });
8380
8399
  }
@@ -8397,7 +8416,7 @@ class AggregateMethods {
8397
8416
  * @param over - OVER clause config
8398
8417
  */
8399
8418
  cumeDist(over) {
8400
- return makeFnExpression(this, float, "cume_dist", emptyArray, {
8419
+ return makeFnExpression(this, floatNullable, "cume_dist", emptyArray, {
8401
8420
  over
8402
8421
  });
8403
8422
  }