pqb 0.11.1 → 0.11.2

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
@@ -1,5 +1,5 @@
1
1
  import * as orchid_core from 'orchid-core';
2
- import { Sql, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, QueryResultRow, AdapterBase, QueryInput, ColumnsShapeBase, StringKey, ColumnOutput, NullableColumn, QueryInternal, QueryMetaBase, EmptyTuple, ColumnTypesBase, DbBase, ThenResult, ColumnShapeOutput, DefaultSelectColumns, SetOptional, Spread, CoalesceString, QueryBaseCommon, QueryCommon, BaseNumberData, Code, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateColumnData, dateTypeMethods, JSONTypeAny, record, ArrayMethodsData, arrayMethods, name, ColumnDataBase, BaseOperators, HiddenColumn, ValidationContext, MessageParam } from 'orchid-core';
2
+ import { Sql, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, QueryResultRow, AdapterBase, QueryInput, ColumnsShapeBase, StringKey, ColumnOutput, NullableColumn, QueryInternal, QueryMetaBase, EmptyTuple, ColumnTypesBase, DbBase, ThenResult, ColumnShapeOutput, DefaultSelectColumns, SetOptional, Spread, CoalesceString, QueryBaseCommon, QueryCommon, BaseNumberData, Code, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateColumnData, EncodeColumn, ParseColumn, dateTypeMethods, JSONTypeAny, record, ArrayMethodsData, arrayMethods, name, ColumnDataBase, BaseOperators, HiddenColumn, ValidationContext, MessageParam } from 'orchid-core';
3
3
  import { PoolConfig, Pool, PoolClient } from 'pg';
4
4
  import { inspect } from 'util';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -3023,9 +3023,9 @@ declare class CitextColumn extends TextBaseColumn {
3023
3023
  }
3024
3024
 
3025
3025
  type DateMethods = typeof dateTypeMethods;
3026
- interface DateBaseColumn extends ColumnType<string, typeof Operators.date, string | Date>, DateMethods {
3026
+ interface DateBaseColumn extends ColumnType<string, typeof Operators.date, string | number | Date>, DateMethods {
3027
3027
  }
3028
- declare abstract class DateBaseColumn extends ColumnType<string, typeof Operators.date, string | Date> {
3028
+ declare abstract class DateBaseColumn extends ColumnType<string, typeof Operators.date, string | number | Date> {
3029
3029
  data: DateColumnData;
3030
3030
  operators: {
3031
3031
  lt: ((key: string, value: orchid_core.RawExpression | Date | Query, values: unknown[]) => string) & {
@@ -3056,10 +3056,9 @@ declare abstract class DateBaseColumn extends ColumnType<string, typeof Operator
3056
3056
  type: orchid_core.RawExpression | Query | Date[];
3057
3057
  };
3058
3058
  };
3059
- asNumber(): IntegerColumn;
3060
- asDate<T extends ColumnType>(this: T): Omit<T, "type"> & {
3061
- type: Date;
3062
- };
3059
+ encodeFn: (input: string | number | Date) => Date;
3060
+ asNumber(): EncodeColumn<IntegerColumn, string | number | Date>;
3061
+ asDate<T extends ColumnType>(this: T): ParseColumn<T, Date>;
3063
3062
  }
3064
3063
  declare class DateColumn extends DateBaseColumn {
3065
3064
  dataType: "date";
@@ -3560,12 +3559,8 @@ declare abstract class ColumnType<Type = unknown, Ops extends BaseOperators = Ba
3560
3559
  };
3561
3560
  hidden<T extends ColumnType>(this: T): HiddenColumn<T>;
3562
3561
  nullable<T extends ColumnType>(this: T): NullableColumn<T>;
3563
- encode<T extends ColumnType, Input>(this: T, fn: (input: Input) => unknown): Omit<T, 'inputType'> & {
3564
- inputType: Input;
3565
- };
3566
- parse<T extends ColumnType, Output>(this: T, fn: (input: T['type']) => Output): Omit<T, 'type'> & {
3567
- type: Output;
3568
- };
3562
+ encode<T extends ColumnType, Input>(this: T, fn: (input: Input) => unknown): EncodeColumn<T, Input>;
3563
+ parse<T extends ColumnType, Output>(this: T, fn: (input: T['type']) => Output): ParseColumn<T, Output>;
3569
3564
  as<T extends ColumnType, C extends ColumnType<T['type'], BaseOperators, T['inputType']>>(this: T, column: C): C;
3570
3565
  toSQL(): string;
3571
3566
  index<T extends ColumnType>(this: T, options?: Omit<SingleColumnIndexOptions, 'column'>): T;
@@ -3636,7 +3631,7 @@ declare const foreignKeyArgumentToCode: (foreignKey: ForeignKey<string, string[]
3636
3631
  declare const columnIndexesToCode: (indexes: Exclude<ColumnData['indexes'], undefined>) => Code[];
3637
3632
  declare const columnCheckToCode: (t: string, check: RawExpression) => string;
3638
3633
  declare const identityToCode: (identity: TableData.Identity, dataType?: string) => Code[];
3639
- declare const columnCode: (type: ColumnType, t: string, code: Code, data?: ColumnData) => Code;
3634
+ declare const columnCode: (type: ColumnType, t: string, code: Code, data?: ColumnData, skip?: Record<'encodeFn', unknown>) => Code;
3640
3635
 
3641
3636
  declare const columnsByType: Record<string, new (...args: never[]) => ColumnType>;
3642
3637
 
package/dist/index.js CHANGED
@@ -677,7 +677,7 @@ const identityToCode = (identity, dataType) => {
677
677
  orchidCore.addCode(code, ")");
678
678
  return code;
679
679
  };
680
- const columnCode = (type, t, code, data = type.data) => {
680
+ const columnCode = (type, t, code, data = type.data, skip) => {
681
681
  code = orchidCore.toArray(code);
682
682
  let prepend = `${t}.`;
683
683
  if (data.name) {
@@ -699,7 +699,7 @@ const columnCode = (type, t, code, data = type.data) => {
699
699
  orchidCore.addCode(code, ".hidden()");
700
700
  if (data.isNullable)
701
701
  orchidCore.addCode(code, ".nullable()");
702
- if (type.encodeFn)
702
+ if (type.encodeFn && type.encodeFn !== (skip == null ? void 0 : skip.encodeFn))
703
703
  orchidCore.addCode(code, `.encode(${type.encodeFn.toString()})`);
704
704
  if (type.parseFn && !("hideFromCode" in type.parseFn))
705
705
  orchidCore.addCode(code, `.parse(${type.parseFn.toString()})`);
@@ -1231,13 +1231,18 @@ class CitextColumn extends TextBaseColumn {
1231
1231
  }
1232
1232
  }
1233
1233
 
1234
+ const dateTimeEncode = (input) => {
1235
+ return typeof input === "object" ? input : new Date(input);
1236
+ };
1237
+ const skip = { encodeFn: dateTimeEncode };
1234
1238
  class DateBaseColumn extends ColumnType {
1235
1239
  constructor() {
1236
1240
  super(...arguments);
1237
1241
  this.operators = Operators.date;
1242
+ this.encodeFn = dateTimeEncode;
1238
1243
  }
1239
1244
  asNumber() {
1240
- return this.encode((input) => new Date(input)).parse(Date.parse).as(
1245
+ return this.parse(Date.parse).as(
1241
1246
  new IntegerColumn({ [orchidCore.nameKey]: this.data.name })
1242
1247
  );
1243
1248
  }
@@ -1252,7 +1257,13 @@ class DateColumn extends DateBaseColumn {
1252
1257
  this.dataType = "date";
1253
1258
  }
1254
1259
  toCode(t) {
1255
- return columnCode(this, t, `date()${orchidCore.dateDataToCode(this.data)}`);
1260
+ return columnCode(
1261
+ this,
1262
+ t,
1263
+ `date()${orchidCore.dateDataToCode(this.data)}`,
1264
+ this.data,
1265
+ skip
1266
+ );
1256
1267
  }
1257
1268
  }
1258
1269
  class DateTimeBaseClass extends DateBaseColumn {
@@ -1281,7 +1292,9 @@ const timestampToCode = (self, t) => {
1281
1292
  return columnCode(
1282
1293
  self,
1283
1294
  t,
1284
- `${self instanceof TimestampColumn ? "timestampWithoutTimeZone" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data)}`
1295
+ `${self instanceof TimestampColumn ? "timestampWithoutTimeZone" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data)}`,
1296
+ self.data,
1297
+ skip
1285
1298
  );
1286
1299
  };
1287
1300
  class TimestampColumn extends DateTimeBaseClass {
@@ -1313,7 +1326,9 @@ class TimeColumn extends DateTimeBaseClass {
1313
1326
  return columnCode(
1314
1327
  this,
1315
1328
  t,
1316
- `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data)}`
1329
+ `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data)}`,
1330
+ this.data,
1331
+ skip
1317
1332
  );
1318
1333
  }
1319
1334
  }
@@ -1330,7 +1345,9 @@ class IntervalColumn extends ColumnType {
1330
1345
  return columnCode(
1331
1346
  this,
1332
1347
  t,
1333
- `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`
1348
+ `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
1349
+ this.data,
1350
+ skip
1334
1351
  );
1335
1352
  }
1336
1353
  toSQL() {