pqb 0.66.0 → 0.66.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
@@ -1089,12 +1089,6 @@ declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberA
1089
1089
  toSQL(): string;
1090
1090
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1091
1091
  }
1092
- /**
1093
- * Symbol that turns on a snake case column names.
1094
- * It is set on the column types.
1095
- * When it's on, column names in ORM are still as user types them, but they are translated to snake_case when generating SQL.
1096
- */
1097
- declare const snakeCaseKey: unique symbol;
1098
1092
  interface TimeInterval {
1099
1093
  years?: number;
1100
1094
  months?: number;
@@ -4560,9 +4554,6 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
4560
4554
  */
4561
4555
  nowSQL?: string;
4562
4556
  }
4563
- /**
4564
- * See {@link ScopeMethods}
4565
- */
4566
4557
  type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.QueryColumns, Keys extends string = string> = { [K in Keys]: (q: ScopeArgumentQuery<Table, Shape>) => IsQuery };
4567
4558
  interface QueryBuilder extends Query {
4568
4559
  returnType: undefined;
@@ -4571,7 +4562,6 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
4571
4562
  adapterNotInTransaction: Adapter;
4572
4563
  qb: QueryBuilder;
4573
4564
  table: Table;
4574
- shape: ShapeWithComputed;
4575
4565
  columnTypes: ColumnTypes;
4576
4566
  q: QueryData;
4577
4567
  __isQuery: true;
@@ -4596,7 +4586,8 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
4596
4586
  error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
4597
4587
  internal: QueryInternal<{ [K in keyof PrimaryKeys]: (keyof PrimaryKeys extends K ? never : keyof PrimaryKeys) extends never ? PrimaryKeys[K] : never }[keyof PrimaryKeys], PrimaryKeys | UniqueColumns, { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? K : never }[keyof Shape] | keyof PrimaryKeys, UniqueColumnTuples, UniqueConstraints>;
4598
4588
  catch: QueryCatch;
4599
- constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ShapeWithComputed | undefined, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData);
4589
+ shape: ShapeWithComputed;
4590
+ constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ShapeWithComputed, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData);
4600
4591
  /**
4601
4592
  * When in transaction, returns a db adapter object for the transaction,
4602
4593
  * returns a default adapter object otherwise.
@@ -10471,4 +10462,4 @@ declare const testTransaction: {
10471
10462
  */
10472
10463
  close(arg: Arg$1): Promise<void>;
10473
10464
  };
10474
- export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbRlsOptions, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableRlsConfig, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, snakeCaseKey, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
10465
+ export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbRlsOptions, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableRlsConfig, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
package/dist/index.js CHANGED
@@ -310,12 +310,6 @@ const rollbackSql = { text: "ROLLBACK" };
310
310
  const quoteIdentifier = (role) => {
311
311
  return `"${role.replace(/"/g, "\"\"")}"`;
312
312
  };
313
- /**
314
- * Symbol that turns on a snake case column names.
315
- * It is set on the column types.
316
- * When it's on, column names in ORM are still as user types them, but they are translated to snake_case when generating SQL.
317
- */
318
- const snakeCaseKey = Symbol("snakeCase");
319
313
  var Expression = class {
320
314
  toSQL(ctx, quotedAs) {
321
315
  let sql = this.makeSQL(ctx, quotedAs);
@@ -485,7 +479,7 @@ const makeIndex = (columns, first, second) => {
485
479
  } };
486
480
  else return { index: {
487
481
  columns,
488
- options: first ?? {}
482
+ options: { ...first }
489
483
  } };
490
484
  };
491
485
  const tableDataMethods = {
@@ -2051,10 +2045,10 @@ var ArrayColumn = class ArrayColumn extends Column {
2051
2045
  }
2052
2046
  const code = [open];
2053
2047
  const { item } = this.data;
2054
- const { isNullable } = item.data;
2055
- delete item.data.isNullable;
2056
- addCode(code, item.toCode(ctx, key));
2057
- item.data.isNullable = isNullable;
2048
+ const clonedItem = Object.create(item);
2049
+ const { isNullable: _, ...dataWithoutNullable } = item.data;
2050
+ clonedItem.data = dataWithoutNullable;
2051
+ addCode(code, clonedItem.toCode(ctx, key));
2058
2052
  addCode(code, `${close}${arrayDataToCode(this.data, ctx.migration)}`);
2059
2053
  return columnCode(this, ctx, key, code);
2060
2054
  }
@@ -3947,6 +3941,7 @@ const applyComputedColumns = (q, fn) => {
3947
3941
  for (const key in computed) {
3948
3942
  let item = computed[key];
3949
3943
  if (typeof item === "function") item = item.call(computed);
3944
+ item = Object.create(item);
3950
3945
  if (item instanceof ComputedColumn) q.q.runtimeComputeds = {
3951
3946
  ...q.q.runtimeComputeds,
3952
3947
  [key]: item
@@ -3954,7 +3949,7 @@ const applyComputedColumns = (q, fn) => {
3954
3949
  else {
3955
3950
  let col = item.result.value;
3956
3951
  if (!col) {
3957
- item.result.value = col = Object.create(UnknownColumn.instance);
3952
+ item.result = { value: col = Object.create(UnknownColumn.instance) };
3958
3953
  col.data = { ...col.data };
3959
3954
  }
3960
3955
  q.shape[key] = col;
@@ -3962,7 +3957,7 @@ const applyComputedColumns = (q, fn) => {
3962
3957
  data.computed = item;
3963
3958
  data.explicitSelect = true;
3964
3959
  data.readOnly = true;
3965
- const parse = item.result.value._parse;
3960
+ const parse = col._parse;
3966
3961
  if (parse) (q.q.defaultParsers ??= {})[key] = parse;
3967
3962
  }
3968
3963
  }
@@ -4881,7 +4876,7 @@ function queryFrom(self, arg) {
4881
4876
  arg = arg.slice(i + 1);
4882
4877
  } else if (w) data.schema = void 0;
4883
4878
  } else if (Array.isArray(arg)) {
4884
- const { shape } = data;
4879
+ const shape = { ...data.shape };
4885
4880
  const joinedParsers = {};
4886
4881
  for (const item of arg) if (typeof item === "string") {
4887
4882
  const w = data.withShapes[item];
@@ -13254,12 +13249,11 @@ const performQuery = async (q, args, method) => {
13254
13249
  }
13255
13250
  };
13256
13251
  var Db = class extends QueryMethods {
13257
- constructor(adapterNotInTransaction, qb, table = void 0, shape = anyShape, columnTypes, asyncStorage, options, tableData = {}) {
13252
+ constructor(adapterNotInTransaction, qb, table = void 0, shape, columnTypes, asyncStorage, options, tableData = {}) {
13258
13253
  super();
13259
13254
  this.adapterNotInTransaction = adapterNotInTransaction;
13260
13255
  this.qb = qb;
13261
13256
  this.table = table;
13262
- this.shape = shape;
13263
13257
  this.columnTypes = columnTypes;
13264
13258
  const self = this;
13265
13259
  const { softDelete } = options;
@@ -13276,8 +13270,12 @@ var Db = class extends QueryMethods {
13276
13270
  let runtimeDefaultColumns;
13277
13271
  let selectAllCount = 0;
13278
13272
  const { snakeCase } = options;
13273
+ if (shape !== anyShape) shape = { ...shape };
13274
+ this.shape = shape;
13279
13275
  for (const key in shape) {
13280
- const column = shape[key];
13276
+ const column = Object.create(shape[key]);
13277
+ shape[key] = column;
13278
+ column.data = { ...column.data };
13281
13279
  column.data.key = key;
13282
13280
  if (column._parse) {
13283
13281
  hasParsers = true;
@@ -13592,13 +13590,12 @@ const createDbWithAdapter = ({ log, logger, snakeCase, schemaConfig = defaultSch
13592
13590
  snakeCase
13593
13591
  };
13594
13592
  const ct = typeof ctOrFn === "function" ? ctOrFn(makeColumnTypes(schemaConfig)) : ctOrFn;
13595
- if (snakeCase) ct[snakeCaseKey] = true;
13596
13593
  const asyncStorage = new node_async_hooks.AsyncLocalStorage();
13597
13594
  const qb = _initQueryBuilder(adapter, ct, asyncStorage, commonOptions, options);
13598
13595
  commonOptions.schema = schema;
13599
13596
  const { nowSQL } = options;
13600
13597
  const tableConstructor = (table, shape, dataFn, options) => {
13601
- return new Db(adapter, qb, table, typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options?.language) : shape, ct, asyncStorage, {
13598
+ return new Db(adapter, qb, table, typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options?.language) : shape || anyShape, ct, asyncStorage, {
13602
13599
  ...commonOptions,
13603
13600
  ...options
13604
13601
  }, parseTableData(dataFn));
@@ -14407,7 +14404,6 @@ exports.setDefaultLanguage = setDefaultLanguage;
14407
14404
  exports.setFreeAlias = setFreeAlias;
14408
14405
  exports.setQueryObjectValueImmutable = setQueryObjectValueImmutable;
14409
14406
  exports.singleQuote = singleQuote;
14410
- exports.snakeCaseKey = snakeCaseKey;
14411
14407
  exports.tableDataMethods = tableDataMethods;
14412
14408
  exports.testTransaction = testTransaction;
14413
14409
  exports.toArray = toArray;