pqb 0.51.2 → 0.51.4

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.d.ts CHANGED
@@ -380,7 +380,10 @@ interface CommonQueryData {
380
380
  aliases: string[];
381
381
  };
382
382
  selectAllColumns?: string[];
383
- selectableShape: RecordUnknown;
383
+ /**
384
+ * Subset of the `shape` that only includes columns with no `data.explicitSelect`.
385
+ */
386
+ selectAllShape: RecordUnknown;
384
387
  /**
385
388
  * column type for query with 'value' or 'valueOrThrow' return type
386
389
  * Is needed in {@link getShapeFromSelect} to get shape of sub-select that returns a single value.
@@ -2727,7 +2730,7 @@ declare class IntervalColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
2727
2730
  toSQL(): string;
2728
2731
  }
2729
2732
 
2730
- declare class EnumColumn<Schema extends ColumnTypeSchemaArg, SchemaType extends Schema['type'], U extends string = string, T extends readonly [U, ...U[]] = [U]> extends ColumnType<Schema, T[number], SchemaType, OperatorsAny> {
2733
+ declare class EnumColumn<Schema extends ColumnTypeSchemaArg, SchemaType extends Schema['type'], T extends readonly string[]> extends ColumnType<Schema, T[number], SchemaType, OperatorsAny> {
2731
2734
  enumName: string;
2732
2735
  options: T;
2733
2736
  operators: OperatorsAny;
@@ -3364,7 +3367,7 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
3364
3367
  };
3365
3368
  dateAsNumber<T extends ColumnType>(this: T): ParseColumn<T, unknown, number>;
3366
3369
  dateAsDate<T extends ColumnType>(this: T): ParseColumn<T, unknown, Date>;
3367
- enum<U extends string, T extends readonly [U, ...U[]]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, U, T>;
3370
+ enum<T extends readonly string[]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, T>;
3368
3371
  array<Item extends ArrayColumnValue>(item: Item): ArrayColumn<DefaultSchemaConfig, Item, unknown, unknown, unknown>;
3369
3372
  json<T>(): JSONColumn<unknown extends T ? MaybeArray<string | number | boolean | object> : T, DefaultSchemaConfig>;
3370
3373
  inputSchema(): undefined;
@@ -8566,7 +8569,7 @@ interface PostgisPoint {
8566
8569
  declare class PostgisGeographyPointColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, PostgisPoint, ReturnType<Schema['geographyPointSchema']>, OperatorsAny> {
8567
8570
  dataType: string;
8568
8571
  operators: OperatorsAny;
8569
- static encode: ({ srid, lon, lat, }: PostgisPoint) => string;
8572
+ static encode: ({ srid, lon, lat }: PostgisPoint) => string;
8570
8573
  static isDefaultPoint(typmod: number): boolean;
8571
8574
  constructor(schema: Schema);
8572
8575
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
package/dist/index.js CHANGED
@@ -880,12 +880,6 @@ const columnCode = (type, ctx, key, code) => {
880
880
  }
881
881
  if (data.explicitSelect) orchidCore.addCode(code, ".select(false)");
882
882
  if (data.isNullable) orchidCore.addCode(code, ".nullable()");
883
- if (data.encode && data.encode !== data.defaultEncode)
884
- orchidCore.addCode(code, `.encode(${data.encode.toString()})`);
885
- if (data.parse && data.parse !== data.defaultParse)
886
- orchidCore.addCode(code, `.parse(${data.parse.toString()})`);
887
- if (type.data.parseNull)
888
- orchidCore.addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
889
883
  if (data.as) orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
890
884
  if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
891
885
  orchidCore.addCode(
@@ -943,7 +937,7 @@ const addColumnParserToQuery = (q, key, column) => {
943
937
  }
944
938
  };
945
939
  const setColumnDefaultParse = (column, parse) => {
946
- column.data.parse = column.data.defaultParse = parse;
940
+ column.data.parse = parse;
947
941
  column._parse = (input) => input === null ? null : parse(input);
948
942
  };
949
943
  const setColumnParse = (column, fn, outputSchema) => {
@@ -1643,7 +1637,7 @@ class DateBaseColumn extends ColumnType {
1643
1637
  this.operators = Operators.date;
1644
1638
  this.asNumber = schema.dateAsNumber;
1645
1639
  this.asDate = schema.dateAsDate;
1646
- this.data.encode = this.data.defaultEncode = dateTimeEncode;
1640
+ this.data.encode = dateTimeEncode;
1647
1641
  }
1648
1642
  }
1649
1643
  class DateColumn extends DateBaseColumn {
@@ -1787,13 +1781,13 @@ class BooleanColumn extends ColumnType {
1787
1781
  }
1788
1782
  const parseItem = (input) => input[0] === "t";
1789
1783
 
1790
- const encode = (x) => x === null ? x : JSON.stringify(x);
1784
+ const encode$1 = (x) => x === null ? x : JSON.stringify(x);
1791
1785
  class JSONColumn extends ColumnType {
1792
1786
  constructor(schema, inputType) {
1793
1787
  super(schema, inputType);
1794
1788
  this.dataType = "jsonb";
1795
1789
  this.operators = Operators.json;
1796
- this.data.encode = this.data.defaultEncode = encode;
1790
+ this.data.encode = encode$1;
1797
1791
  this.data.parseItem = JSON.parse;
1798
1792
  }
1799
1793
  toCode(ctx, key) {
@@ -2406,7 +2400,7 @@ class ArrayColumn extends ColumnType {
2406
2400
  this.dataType = "array";
2407
2401
  this.operators = Operators.array;
2408
2402
  item.data.isNullable = true;
2409
- setColumnDefaultParse(this, (input) => parse.call(this, input));
2403
+ setColumnDefaultParse(this, (input) => parse$1.call(this, input));
2410
2404
  this.data.item = item instanceof ArrayColumn ? item.data.item : item;
2411
2405
  this.data.name = item.data.name;
2412
2406
  this.data.arrayDims = item instanceof ArrayColumn ? item.data.arrayDims + 1 : 1;
@@ -2431,7 +2425,7 @@ class ArrayColumn extends ColumnType {
2431
2425
  return columnCode(this, ctx, key, code);
2432
2426
  }
2433
2427
  }
2434
- const parse = function(source) {
2428
+ const parse$1 = function(source) {
2435
2429
  if (typeof source !== "string") return source;
2436
2430
  const entries = [];
2437
2431
  parsePostgresArray(source, entries, this.data.item.data.parseItem);
@@ -2694,14 +2688,10 @@ const defaultSchemaConfig = {
2694
2688
  return this;
2695
2689
  },
2696
2690
  dateAsNumber() {
2697
- const c = this.parse(Date.parse);
2698
- c.data.defaultParse = Date.parse;
2699
- return c;
2691
+ return this.parse(Date.parse);
2700
2692
  },
2701
2693
  dateAsDate() {
2702
- const c = this.parse(parseDateToDate);
2703
- c.data.defaultParse = parseDateToDate;
2704
- return c;
2694
+ return this.parse(parseDateToDate);
2705
2695
  },
2706
2696
  enum(dataType, type) {
2707
2697
  return new EnumColumn(defaultSchemaConfig, dataType, type, void 0);
@@ -4232,9 +4222,6 @@ const setParserForSelectedString = (query, arg, as, columnAs, columnAlias) => {
4232
4222
  return arg;
4233
4223
  };
4234
4224
  const selectColumn = (query, q, key, columnAs, columnAlias) => {
4235
- if (columnAlias === "pluck") {
4236
- throw new Error("?");
4237
- }
4238
4225
  if (columnAs && q.parsers) {
4239
4226
  const parser = q.parsers[key];
4240
4227
  if (parser) orchidCore.setObjectValueImmutable(q, "parsers", columnAs, parser);
@@ -4271,7 +4258,9 @@ const getShapeFromSelect = (q, isSubQuery) => {
4271
4258
  result = {};
4272
4259
  for (const key in shape) {
4273
4260
  const column = shape[key];
4274
- result[key] = column.data.name ? orchidCore.setColumnData(column, "name", void 0) : column;
4261
+ if (!column.data.explicitSelect) {
4262
+ result[key] = column.data.name ? orchidCore.setColumnData(column, "name", void 0) : column;
4263
+ }
4275
4264
  }
4276
4265
  } else {
4277
4266
  result = shape;
@@ -4331,10 +4320,12 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
4331
4320
  }
4332
4321
  } else if (arg === "*") {
4333
4322
  for (const key2 in shape) {
4334
- result[key2] = mapSubSelectColumn(
4335
- shape[key2],
4336
- isSubQuery
4337
- );
4323
+ if (!shape[key2].data.explicitSelect) {
4324
+ result[key2] = mapSubSelectColumn(
4325
+ shape[key2],
4326
+ isSubQuery
4327
+ );
4328
+ }
4338
4329
  }
4339
4330
  } else {
4340
4331
  result[key || arg] = mapSubSelectColumn(
@@ -4863,7 +4854,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
4863
4854
  if (hookSelect) {
4864
4855
  selected ?? (selected = {});
4865
4856
  selectedAs ?? (selectedAs = {});
4866
- for (const key in query.selectableShape) {
4857
+ for (const key in query.selectAllShape) {
4867
4858
  selected[key] = quotedAs;
4868
4859
  selectedAs[key] = key;
4869
4860
  }
@@ -5012,7 +5003,7 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
5012
5003
  }
5013
5004
  const selectAllSql = (query, quotedAs, jsonList) => {
5014
5005
  if (jsonList) {
5015
- Object.assign(jsonList, query.selectableShape);
5006
+ Object.assign(jsonList, query.selectAllShape);
5016
5007
  }
5017
5008
  return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
5018
5009
  };
@@ -7185,11 +7176,7 @@ class DomainColumn extends CustomTypeColumn {
7185
7176
  }
7186
7177
 
7187
7178
  const defaultSrid = 4326;
7188
- const defaultEncode = ({
7189
- srid = defaultSrid,
7190
- lon,
7191
- lat
7192
- }) => {
7179
+ const encode = ({ srid = defaultSrid, lon, lat }) => {
7193
7180
  const arr = new Uint8Array(25);
7194
7181
  const view = new DataView(arr.buffer);
7195
7182
  view.setInt8(0, 1);
@@ -7205,8 +7192,8 @@ class PostgisGeographyPointColumn extends ColumnType {
7205
7192
  super(schema, schema.geographyPointSchema());
7206
7193
  this.dataType = "geography(Point)";
7207
7194
  this.operators = Operators.any;
7208
- setColumnDefaultParse(this, defaultParse);
7209
- this.data.encode = this.data.defaultEncode = defaultEncode;
7195
+ setColumnDefaultParse(this, parse);
7196
+ this.data.encode = encode;
7210
7197
  }
7211
7198
  static isDefaultPoint(typmod) {
7212
7199
  return typmodType(typmod) === "Point" && typmodSrid(typmod) === defaultSrid;
@@ -7215,8 +7202,9 @@ class PostgisGeographyPointColumn extends ColumnType {
7215
7202
  return columnCode(this, ctx, key, `geography.point()`);
7216
7203
  }
7217
7204
  }
7218
- PostgisGeographyPointColumn.encode = defaultEncode;
7219
- const defaultParse = (input) => {
7205
+ // It is used by test-factory
7206
+ PostgisGeographyPointColumn.encode = encode;
7207
+ const parse = (input) => {
7220
7208
  const bytes = new Uint8Array(20);
7221
7209
  for (let i = 0; i < 40; i += 2) {
7222
7210
  bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
@@ -11812,7 +11800,7 @@ class ExpressionMethods {
11812
11800
  column(name) {
11813
11801
  const column = this.shape[name];
11814
11802
  return new ColumnRefExpression(
11815
- column,
11803
+ column || UnknownColumn.instance,
11816
11804
  name
11817
11805
  );
11818
11806
  }
@@ -11854,12 +11842,12 @@ class ExpressionMethods {
11854
11842
  if (table === as) {
11855
11843
  column = shape[col];
11856
11844
  } else {
11857
- column = q.q.joinedShapes[table][col];
11845
+ column = q.q.joinedShapes?.[table][col];
11858
11846
  }
11859
11847
  } else {
11860
11848
  column = shape[arg];
11861
11849
  }
11862
- return new RefExpression(column, q, arg);
11850
+ return new RefExpression(column || UnknownColumn.instance, q, arg);
11863
11851
  }
11864
11852
  val(value) {
11865
11853
  return new orchidCore.ValExpression(value);
@@ -12739,7 +12727,7 @@ const parseIndexOrExclude = (item) => {
12739
12727
 
12740
12728
  const anyShape = {};
12741
12729
  class Db extends QueryMethods {
12742
- constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = orchidCore.emptyObject) {
12730
+ constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = {}) {
12743
12731
  super();
12744
12732
  this.adapter = adapter;
12745
12733
  this.queryBuilder = queryBuilder;
@@ -12833,26 +12821,21 @@ class Db extends QueryMethods {
12833
12821
  );
12834
12822
  this.columns = columns;
12835
12823
  if (options.computed) applyComputedColumns(this, options.computed);
12836
- const selectableShape = this.q.selectableShape = {};
12837
12824
  if (prepareSelectAll) {
12825
+ const selectAllShape = this.q.selectAllShape = {};
12838
12826
  const list = [];
12839
12827
  for (const key in shape) {
12840
12828
  const column = shape[key];
12841
- if (!column.data.explicitSelect && !(column instanceof VirtualColumn)) {
12829
+ if (!column.data.explicitSelect) {
12842
12830
  list.push(
12843
12831
  column.data.name ? `"${column.data.name}" "${key}"` : `"${key}"`
12844
12832
  );
12845
- selectableShape[key] = column;
12833
+ selectAllShape[key] = column;
12846
12834
  }
12847
12835
  }
12848
12836
  this.q.selectAllColumns = list;
12849
12837
  } else {
12850
- for (const key in shape) {
12851
- const column = shape[key];
12852
- if (column instanceof VirtualColumn) {
12853
- selectableShape[key] = column;
12854
- }
12855
- }
12838
+ this.q.selectAllShape = shape;
12856
12839
  }
12857
12840
  if (modifyQuery) {
12858
12841
  for (const cb of modifyQuery) {