pqb 0.3.3 → 0.3.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
@@ -505,13 +505,6 @@ declare type MaybeArray<T> = T | T[];
505
505
  declare type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
506
506
  [P in K]?: P extends keyof T ? T[P] : never;
507
507
  };
508
- declare type GetTypesOrRaw<T extends [...unknown[]]> = T extends [
509
- infer Head,
510
- ...infer Tail
511
- ] ? [GetTypeOrRaw<Head>, ...GetTypesOrRaw<Tail>] : [];
512
- declare type GetTypeOrRaw<T> = T | RawExpression;
513
- declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
514
- declare type UnionToOvlds<U> = UnionToIntersection<U extends any ? (f: U) => void : never>;
515
508
  declare type OptionalPropertyNames<T> = {
516
509
  [K in keyof T]-?: {} extends {
517
510
  [P in K]: T[K];
@@ -833,7 +826,8 @@ interface Db<Table extends string | undefined = undefined, Shape extends Columns
833
826
  onQueryBuilder: Query['onQueryBuilder'];
834
827
  table: Table;
835
828
  shape: Shape;
836
- schema: TableSchema<Shape>;
829
+ singlePrimaryKey: SinglePrimaryKey<Shape>;
830
+ primaryKeys: Query['primaryKeys'];
837
831
  type: ColumnShapeOutput<Shape>;
838
832
  inputType: ColumnShapeInput<Shape>;
839
833
  query: QueryData;
@@ -1284,10 +1278,10 @@ declare class QueryMethods {
1284
1278
  toSql(this: Query, options?: ToSqlOptions): Sql;
1285
1279
  distinct<T extends Query>(this: T, ...columns: Expression<T>[]): T;
1286
1280
  _distinct<T extends Query>(this: T, ...columns: Expression<T>[]): T;
1287
- find<T extends Query>(this: T, ...args: GetTypesOrRaw<T['schema']['primaryTypes']>): SetQueryReturnsOne<WhereResult<T>>;
1288
- _find<T extends Query>(this: T, ...args: GetTypesOrRaw<T['schema']['primaryTypes']>): SetQueryReturnsOne<WhereResult<T>>;
1289
- findOptional<T extends Query>(this: T, ...args: GetTypesOrRaw<T['schema']['primaryTypes']>): SetQueryReturnsOneOptional<WhereResult<T>>;
1290
- _findOptional<T extends Query>(this: T, ...args: GetTypesOrRaw<T['schema']['primaryTypes']>): SetQueryReturnsOneOptional<WhereResult<T>>;
1281
+ find<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOne<WhereResult<T>>;
1282
+ _find<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOne<WhereResult<T>>;
1283
+ findOptional<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOneOptional<WhereResult<T>>;
1284
+ _findOptional<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOneOptional<WhereResult<T>>;
1291
1285
  findBy<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
1292
1286
  _findBy<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
1293
1287
  findByOptional<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOneOptional<WhereResult<T>>;
@@ -1480,10 +1474,8 @@ declare type Query = QueryMethods & {
1480
1474
  onQueryBuilder: typeof OnQueryBuilder;
1481
1475
  table?: string;
1482
1476
  shape: ColumnsShape;
1483
- schema: Omit<TableSchema<ColumnsShape>, 'primaryKeys' | 'primaryTypes'> & {
1484
- primaryKeys: any[];
1485
- primaryTypes: any[];
1486
- };
1477
+ singlePrimaryKey: string;
1478
+ primaryKeys: string[];
1487
1479
  type: Record<string, unknown>;
1488
1480
  inputType: Record<string, unknown>;
1489
1481
  query: QueryData;
@@ -2159,30 +2151,13 @@ declare class ArrayOfColumnsObjects<Shape extends ColumnsShape> extends ColumnTy
2159
2151
  }
2160
2152
  declare abstract class PluckResultColumnType<C extends ColumnType> extends ColumnType<C['type'][], typeof Operators.any> {
2161
2153
  }
2162
- declare type UnionKeyofToOvlds<S, U> = UnionToIntersection<U extends keyof S ? (f: U) => void : never>;
2163
- declare type PopKeyofColumnShapeUnion<S extends ColumnsShape, U extends keyof S> = UnionKeyofToOvlds<S, U> extends (a: infer A extends keyof S) => void ? A : never;
2164
- declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
2165
- declare type UnionToArray<S extends ColumnsShape, T extends keyof S, A extends [...(keyof S)[]] = []> = IsUnion<T> extends true ? UnionToArray<S, Exclude<T, PopKeyofColumnShapeUnion<S, T>>, [
2166
- PopKeyofColumnShapeUnion<S, T>,
2167
- ...A
2168
- ]> : [T, ...A];
2169
- declare type GetPrimaryKeys<S extends ColumnsShape> = UnionToArray<S, {
2170
- [K in keyof S]: S[K] extends {
2171
- isPrimaryKey: true;
2172
- } ? K : never;
2173
- }[keyof S]>;
2174
- declare type GetPrimaryTypes<S extends ColumnsShape, Keys extends [...(keyof S | string)[]] = GetPrimaryKeys<S>> = GetTypesFromKeys<S, Keys>;
2175
- declare type GetTypesFromKeys<S extends ColumnsShape, T extends [...(keyof S)[]]> = T extends [
2176
- infer Head extends keyof S,
2177
- ...infer Tail extends [...(keyof S)[]]
2178
- ] ? [GetTypeFromKey<S, Head>, ...GetTypesFromKeys<S, Tail>] : [];
2179
- declare type GetTypeFromKey<S extends ColumnsShape, T extends keyof S> = S[T]['type'];
2180
- declare class TableSchema<Shape extends ColumnsShape> {
2181
- shape: Shape;
2182
- primaryKeys: string extends keyof Shape ? string[] : GetPrimaryKeys<Shape>;
2183
- primaryTypes: GetPrimaryTypes<Shape>;
2184
- constructor(shape: Shape);
2185
- }
2154
+ declare type SinglePrimaryKey<Shape extends ColumnsShape> = StringKey<{
2155
+ [K in keyof Shape]: Shape[K]['isPrimaryKey'] extends true ? [
2156
+ {
2157
+ [S in keyof Shape]: Shape[S]['isPrimaryKey'] extends true ? S extends K ? never : S : never;
2158
+ }[keyof Shape]
2159
+ ] extends [never] ? K : never : never;
2160
+ }[keyof Shape]>;
2186
2161
 
2187
2162
  declare type ColumnOutput<T extends ColumnType> = T['type'];
2188
2163
  declare type ColumnInput<T extends ColumnType> = T['inputType'];
@@ -4293,4 +4268,4 @@ declare class UnhandledTypeError extends PormInternalError {
4293
4268
  constructor(value: never);
4294
4269
  }
4295
4270
 
4296
- export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, GetTypeOrRaw, GetTypesOrRaw, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TableSchema, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionToArray, UnionToIntersection, UnionToOvlds, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
4271
+ export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SinglePrimaryKey, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
package/dist/index.esm.js CHANGED
@@ -3004,14 +3004,6 @@ class ArrayOfColumnsObjects extends ColumnType {
3004
3004
  }
3005
3005
  class PluckResultColumnType extends ColumnType {
3006
3006
  }
3007
- class TableSchema {
3008
- constructor(shape) {
3009
- this.shape = shape;
3010
- this.primaryKeys = Object.entries(this.shape).filter(([, column]) => {
3011
- return column.isPrimaryKey;
3012
- }).map(([key]) => key);
3013
- }
3014
- }
3015
3007
 
3016
3008
  var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
3017
3009
  var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
@@ -5040,7 +5032,7 @@ class Update {
5040
5032
  return q._update(...args);
5041
5033
  }
5042
5034
  _update(...args) {
5043
- var _a, _b;
5035
+ var _a, _b, _c;
5044
5036
  const { query } = this;
5045
5037
  const data = args[0];
5046
5038
  const set = __spreadValues$1({}, data);
@@ -5082,12 +5074,14 @@ class Update {
5082
5074
  if ((state == null ? void 0 : state.updateLater) || appendRelationKeys.length && originalReturnType !== "all") {
5083
5075
  query.returnType = "all";
5084
5076
  if (state == null ? void 0 : state.updateLater) {
5085
- this.schema.primaryKeys.forEach((key) => {
5086
- var _a2, _b2;
5087
- if (!((_a2 = query.select) == null ? void 0 : _a2.includes("*")) && !((_b2 = query.select) == null ? void 0 : _b2.includes(key))) {
5088
- this._select(key);
5089
- }
5090
- });
5077
+ if (!((_c = query.select) == null ? void 0 : _c.includes("*"))) {
5078
+ this.primaryKeys.forEach((key) => {
5079
+ var _a2;
5080
+ if (!((_a2 = query.select) == null ? void 0 : _a2.includes(key))) {
5081
+ this._select(key);
5082
+ }
5083
+ });
5084
+ }
5091
5085
  }
5092
5086
  const { handleResult } = query;
5093
5087
  query.handleResult = async (q, queryResult) => {
@@ -5095,7 +5089,7 @@ class Update {
5095
5089
  if (state == null ? void 0 : state.updateLater) {
5096
5090
  await Promise.all(state.updateLaterPromises);
5097
5091
  const t = this.__model.clone().transacting(q);
5098
- const keys = this.schema.primaryKeys;
5092
+ const keys = this.primaryKeys;
5099
5093
  t._whereIn(
5100
5094
  keys,
5101
5095
  resultOfTypeAll.map((item) => keys.map((key) => item[key]))
@@ -5346,22 +5340,20 @@ class QueryMethods {
5346
5340
  _distinct(...columns) {
5347
5341
  return pushQueryArray(this, "distinct", columns);
5348
5342
  }
5349
- find(...args) {
5350
- return this.clone()._find(...args);
5343
+ find(value) {
5344
+ return this.clone()._find(value);
5351
5345
  }
5352
- _find(...args) {
5353
- const conditions = {};
5354
- this.schema.primaryKeys.forEach((key, i) => {
5355
- conditions[key] = args[i];
5356
- });
5357
- return this._where(conditions)._take();
5346
+ _find(value) {
5347
+ return this._where({
5348
+ [this.singlePrimaryKey]: value
5349
+ })._take();
5358
5350
  }
5359
- findOptional(...args) {
5360
- return this.clone()._findOptional(...args);
5351
+ findOptional(value) {
5352
+ return this.clone()._findOptional(value);
5361
5353
  }
5362
- _findOptional(...args) {
5354
+ _findOptional(value) {
5363
5355
  return this._find(
5364
- ...args
5356
+ value
5365
5357
  ).takeOptional();
5366
5358
  }
5367
5359
  findBy(...args) {
@@ -5528,7 +5520,12 @@ class Db {
5528
5520
  if (options == null ? void 0 : options.schema) {
5529
5521
  this.query.schema = options.schema;
5530
5522
  }
5531
- this.schema = new TableSchema(shape);
5523
+ this.primaryKeys = Object.keys(shape).filter(
5524
+ (key) => shape[key].isPrimaryKey
5525
+ );
5526
+ if (this.primaryKeys.length === 1) {
5527
+ this.singlePrimaryKey = this.primaryKeys[0];
5528
+ }
5532
5529
  const columns = Object.keys(
5533
5530
  shape
5534
5531
  );
@@ -5607,5 +5604,5 @@ const createDb = (_a) => {
5607
5604
  const relationQueryKey = Symbol("relationQuery");
5608
5605
  const isRequiredRelationKey = Symbol("isRequiredRelation");
5609
5606
 
5610
- export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, Insert, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryGet, QueryLog, QueryMethods, QueryUpsert, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TableSchema, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
5607
+ export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, Insert, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryGet, QueryLog, QueryMethods, QueryUpsert, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
5611
5608
  //# sourceMappingURL=index.esm.js.map