bigal 15.7.0 → 15.9.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [15.9.0](https://github.com/bigalorm/bigal/compare/v15.8.0...v15.9.0) (2026-01-24)
2
+
3
+ ### Features
4
+
5
+ - Add through filtering and better relationship docs ([#285](https://github.com/bigalorm/bigal/issues/285)) ([915fed2](https://github.com/bigalorm/bigal/commit/915fed234a844715bcfc514972365f68850ec8ed))
6
+
7
+ # [15.8.0](https://github.com/bigalorm/bigal/compare/v15.7.0...v15.8.0) (2026-01-24)
8
+
9
+ ### Features
10
+
11
+ - Support .toJSON for create, update, and delete calls ([#284](https://github.com/bigalorm/bigal/issues/284)) ([d74c6f0](https://github.com/bigalorm/bigal/commit/d74c6f07a036b44cf43cdcce9224c3b256dbb3dc))
12
+
1
13
  # [15.7.0](https://github.com/bigalorm/bigal/compare/v15.6.0...v15.7.0) (2026-01-19)
2
14
 
3
15
  ### Features
package/README.md CHANGED
@@ -143,6 +143,8 @@ export class Product extends Entity {
143
143
  }
144
144
  ```
145
145
 
146
+ For detailed information about defining relationships and understanding the `QueryResult` type system, see the [Relationships Guide](docs/relationships.md).
147
+
146
148
  ### Initialize repositories
147
149
 
148
150
  ```ts
package/dist/index.cjs CHANGED
@@ -2399,7 +2399,8 @@ class ReadonlyRepository {
2399
2399
  sort: options?.sort,
2400
2400
  skip: options?.skip,
2401
2401
  limit: options?.limit,
2402
- pool: options?.pool ?? poolOverride
2402
+ pool: options?.pool ?? poolOverride,
2403
+ through: options?.through
2403
2404
  });
2404
2405
  return this;
2405
2406
  },
@@ -2594,7 +2595,8 @@ ${stack ?? ""}`;
2594
2595
  sort: options?.sort,
2595
2596
  skip: options?.skip,
2596
2597
  limit: options?.limit,
2597
- pool: options?.pool ?? poolOverride
2598
+ pool: options?.pool ?? poolOverride,
2599
+ through: options?.through
2598
2600
  });
2599
2601
  return this;
2600
2602
  },
@@ -3029,7 +3031,7 @@ ${stack ?? ""}`;
3029
3031
  const populateResultsByEntityId = groupBy(populateResults, column.via);
3030
3032
  for (const entity of entities) {
3031
3033
  const id = entity[primaryKeyPropertyName];
3032
- entity[populate.propertyName] = populateResultsByEntityId[id] || [];
3034
+ entity[populate.propertyName] = populateResultsByEntityId[id] ?? [];
3033
3035
  }
3034
3036
  }
3035
3037
  }
@@ -3052,11 +3054,14 @@ ${stack ?? ""}`;
3052
3054
  if (!relatedModelColumn) {
3053
3055
  throw new Error(`Unable to find property on related model for multi-map collection: ${column.through}. From ${column.target}#${populate.propertyName}`);
3054
3056
  }
3057
+ const throughWhere = {
3058
+ [column.via]: entityIds,
3059
+ ...populate.through?.where
3060
+ };
3055
3061
  const mapRecords = await throughRepository.find({
3056
3062
  select: [column.via, relatedModelColumn.via],
3057
- where: {
3058
- [column.via]: entityIds
3059
- },
3063
+ where: throughWhere,
3064
+ sort: populate.through?.sort,
3060
3065
  pool: populate.pool
3061
3066
  });
3062
3067
  const populateIds = /* @__PURE__ */ new Set();
@@ -3069,6 +3074,12 @@ ${stack ?? ""}`;
3069
3074
  entityPopulateIds.push(populatedId);
3070
3075
  populateIdsByEntityId[entityId] = entityPopulateIds;
3071
3076
  }
3077
+ if (populateIds.size === 0) {
3078
+ for (const entity of entities) {
3079
+ entity[populate.propertyName] = [];
3080
+ }
3081
+ return;
3082
+ }
3072
3083
  const populateWhere = {
3073
3084
  [populateModelPrimaryKeyPropertyName]: Array.from(populateIds),
3074
3085
  ...populate.where
@@ -3108,21 +3119,12 @@ class Repository extends ReadonlyRepository {
3108
3119
  * @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
3109
3120
  * @returns {object|object[]|void} Return value from the db
3110
3121
  */
3111
- async create(values, options) {
3122
+ create(values, options) {
3112
3123
  if (this.model.readonly) {
3113
3124
  throw new Error(`${this.model.name} is readonly.`);
3114
3125
  }
3115
- if (Array.isArray(values) && !values.length) {
3116
- return [];
3117
- }
3118
- const beforeCreate = this._type.beforeCreate;
3119
- if (beforeCreate) {
3120
- if (Array.isArray(values)) {
3121
- values = await Promise.all(values.map(async (value) => beforeCreate(value)));
3122
- } else {
3123
- values = await beforeCreate(values);
3124
- }
3125
- }
3126
+ const modelInstance = this;
3127
+ const isArray = Array.isArray(values);
3126
3128
  let returnRecords = true;
3127
3129
  let returnSelect;
3128
3130
  if (options) {
@@ -3132,26 +3134,56 @@ class Repository extends ReadonlyRepository {
3132
3134
  returnSelect = options.returnSelect;
3133
3135
  }
3134
3136
  }
3135
- const { query, params } = getInsertQueryAndParams({
3136
- repositoriesByModelNameLowered: this._repositoriesByModelNameLowered,
3137
- model: this.model,
3138
- values,
3139
- returnRecords,
3140
- returnSelect,
3141
- onConflict: options?.onConflict
3142
- });
3143
- const results = await this._pool.query(query, params);
3144
- if (returnRecords) {
3145
- if (Array.isArray(values)) {
3146
- return this._buildInstances(results.rows);
3147
- }
3148
- const firstResult = results.rows[0];
3149
- if (firstResult) {
3150
- return this._buildInstance(firstResult);
3137
+ let returnAsPlainObjects = false;
3138
+ const result = {
3139
+ toJSON() {
3140
+ returnAsPlainObjects = true;
3141
+ return result;
3142
+ },
3143
+ async then(resolve, reject) {
3144
+ try {
3145
+ if (isArray && !values.length) {
3146
+ return resolve ? await resolve([]) : [];
3147
+ }
3148
+ const beforeCreate = modelInstance._type.beforeCreate;
3149
+ if (beforeCreate) {
3150
+ if (isArray) {
3151
+ values = await Promise.all(values.map(async (value) => beforeCreate(value)));
3152
+ } else {
3153
+ values = await beforeCreate(values);
3154
+ }
3155
+ }
3156
+ const { query, params } = getInsertQueryAndParams({
3157
+ repositoriesByModelNameLowered: modelInstance._repositoriesByModelNameLowered,
3158
+ model: modelInstance.model,
3159
+ values,
3160
+ returnRecords,
3161
+ returnSelect,
3162
+ onConflict: options?.onConflict
3163
+ });
3164
+ const results = await modelInstance._pool.query(query, params);
3165
+ if (returnRecords) {
3166
+ if (isArray) {
3167
+ const entities = returnAsPlainObjects ? modelInstance._buildPlainObjects(results.rows) : modelInstance._buildInstances(results.rows);
3168
+ return resolve ? await resolve(entities) : entities;
3169
+ }
3170
+ const firstResult = results.rows[0];
3171
+ if (firstResult) {
3172
+ const entity = returnAsPlainObjects ? modelInstance._buildPlainObject(firstResult) : modelInstance._buildInstance(firstResult);
3173
+ return resolve ? await resolve(entity) : entity;
3174
+ }
3175
+ throw new Error("Unknown error getting created rows back from the database");
3176
+ }
3177
+ return resolve ? await resolve(void 0) : void 0;
3178
+ } catch (ex) {
3179
+ if (reject) {
3180
+ return reject(ex);
3181
+ }
3182
+ throw ex;
3183
+ }
3151
3184
  }
3152
- throw new Error("Unknown error getting created rows back from the database");
3153
- }
3154
- return void 0;
3185
+ };
3186
+ return result;
3155
3187
  }
3156
3188
  /**
3157
3189
  * Updates object(s) matching the where query, with the specified values
@@ -3162,16 +3194,14 @@ class Repository extends ReadonlyRepository {
3162
3194
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
3163
3195
  * @returns {object[]|void} Return values from the db or `true` if returnRecords=false
3164
3196
  */
3165
- async update(where, values, options) {
3197
+ update(where, values, options) {
3166
3198
  if (this.model.readonly) {
3167
3199
  throw new Error(`${this.model.name} is readonly.`);
3168
3200
  }
3169
3201
  if (typeof where === "string") {
3170
3202
  throw new Error("The query cannot be a string, it must be an object");
3171
3203
  }
3172
- if (this._type.beforeUpdate) {
3173
- values = await this._type.beforeUpdate(values);
3174
- }
3204
+ const modelInstance = this;
3175
3205
  let returnRecords = true;
3176
3206
  let returnSelect;
3177
3207
  if (options) {
@@ -3181,19 +3211,40 @@ class Repository extends ReadonlyRepository {
3181
3211
  returnSelect = options.returnSelect;
3182
3212
  }
3183
3213
  }
3184
- const { query, params } = getUpdateQueryAndParams({
3185
- repositoriesByModelNameLowered: this._repositoriesByModelNameLowered,
3186
- model: this.model,
3187
- where,
3188
- values,
3189
- returnRecords,
3190
- returnSelect
3191
- });
3192
- const results = await this._pool.query(query, params);
3193
- if (returnRecords) {
3194
- return this._buildInstances(results.rows);
3195
- }
3196
- return void 0;
3214
+ let returnAsPlainObjects = false;
3215
+ const result = {
3216
+ toJSON() {
3217
+ returnAsPlainObjects = true;
3218
+ return result;
3219
+ },
3220
+ async then(resolve, reject) {
3221
+ try {
3222
+ if (modelInstance._type.beforeUpdate) {
3223
+ values = await modelInstance._type.beforeUpdate(values);
3224
+ }
3225
+ const { query, params } = getUpdateQueryAndParams({
3226
+ repositoriesByModelNameLowered: modelInstance._repositoriesByModelNameLowered,
3227
+ model: modelInstance.model,
3228
+ where,
3229
+ values,
3230
+ returnRecords,
3231
+ returnSelect
3232
+ });
3233
+ const results = await modelInstance._pool.query(query, params);
3234
+ if (returnRecords) {
3235
+ const entities = returnAsPlainObjects ? modelInstance._buildPlainObjects(results.rows) : modelInstance._buildInstances(results.rows);
3236
+ return resolve ? await resolve(entities) : entities;
3237
+ }
3238
+ return resolve ? await resolve(void 0) : void 0;
3239
+ } catch (ex) {
3240
+ if (reject) {
3241
+ return reject(ex);
3242
+ }
3243
+ throw ex;
3244
+ }
3245
+ }
3246
+ };
3247
+ return result;
3197
3248
  }
3198
3249
  /**
3199
3250
  * Destroys object(s) matching the where query
@@ -3211,15 +3262,15 @@ class Repository extends ReadonlyRepository {
3211
3262
  const modelInstance = this;
3212
3263
  const returnSelect = options?.returnSelect;
3213
3264
  const returnRecords = options?.returnRecords ?? !!returnSelect;
3214
- return {
3215
- /**
3216
- * Filters the query
3217
- * @param {object} value - Object representing the where query
3218
- * @returns Query instance
3219
- */
3265
+ let returnAsPlainObjects = false;
3266
+ const result = {
3220
3267
  where(value) {
3221
3268
  where = value;
3222
- return this;
3269
+ return result;
3270
+ },
3271
+ toJSON() {
3272
+ returnAsPlainObjects = true;
3273
+ return result;
3223
3274
  },
3224
3275
  async then(resolve, reject) {
3225
3276
  if (typeof where === "string") {
@@ -3233,9 +3284,10 @@ class Repository extends ReadonlyRepository {
3233
3284
  returnRecords,
3234
3285
  returnSelect
3235
3286
  });
3236
- const result = await modelInstance._pool.query(query, params);
3287
+ const queryResult = await modelInstance._pool.query(query, params);
3237
3288
  if (returnRecords) {
3238
- return await resolve(modelInstance._buildInstances(result.rows));
3289
+ const entities = returnAsPlainObjects ? modelInstance._buildPlainObjects(queryResult.rows) : modelInstance._buildInstances(queryResult.rows);
3290
+ return await resolve(entities);
3239
3291
  }
3240
3292
  return await resolve();
3241
3293
  } catch (ex) {
@@ -3251,6 +3303,7 @@ ${stack}`;
3251
3303
  }
3252
3304
  }
3253
3305
  };
3306
+ return result;
3254
3307
  }
3255
3308
  }
3256
3309
 
package/dist/index.d.cts CHANGED
@@ -466,6 +466,47 @@ interface CountResult<TEntity extends Entity> extends PromiseLike<number> {
466
466
  where(args: WhereQuery<TEntity>): CountResult<TEntity> | number;
467
467
  }
468
468
 
469
+ /**
470
+ * Result of a create operation that returns a plain object (after calling toJSON())
471
+ */
472
+ interface CreateResultJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>> {
473
+ /**
474
+ * Returns results as plain objects instead of entity class instances.
475
+ * Useful for when data must be serializable.
476
+ */
477
+ toJSON(): CreateResultJSON<T>;
478
+ }
479
+ /**
480
+ * Result of a create operation that returns multiple plain objects (after calling toJSON())
481
+ */
482
+ interface CreateResultArrayJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>[]> {
483
+ /**
484
+ * Returns results as plain objects instead of entity class instances.
485
+ * Useful for when data must be serializable.
486
+ */
487
+ toJSON(): CreateResultArrayJSON<T>;
488
+ }
489
+ /**
490
+ * Result of a create operation that returns a single record
491
+ */
492
+ interface CreateResult<T extends Entity> extends PromiseLike<QueryResult<T>> {
493
+ /**
494
+ * Returns results as plain objects instead of entity class instances.
495
+ * Useful for when data must be serializable.
496
+ */
497
+ toJSON(): CreateResultJSON<T>;
498
+ }
499
+ /**
500
+ * Result of a create operation that returns multiple records
501
+ */
502
+ interface CreateResultArray<T extends Entity> extends PromiseLike<QueryResult<T>[]> {
503
+ /**
504
+ * Returns results as plain objects instead of entity class instances.
505
+ * Useful for when data must be serializable.
506
+ */
507
+ toJSON(): CreateResultArrayJSON<T>;
508
+ }
509
+
469
510
  declare class ScalarSubquery<TValue> {
470
511
  private readonly _resultType;
471
512
  readonly _aggregate: 'avg' | 'count' | 'max' | 'min' | 'sum';
@@ -654,9 +695,50 @@ interface ReturnRecords<T extends Entity, K extends keyof T> {
654
695
  }
655
696
  type DeleteOptions<T extends Entity, K extends keyof T = keyof T> = ReturnRecords<T, K> | ReturnSelect<T, K>;
656
697
 
698
+ /**
699
+ * Result of a destroy operation that returns plain objects (after calling toJSON())
700
+ */
701
+ interface DestroyResultJSON<TEntity extends Entity, TReturn> extends PromiseLike<PlainObject<TReturn>[]> {
702
+ where(args: WhereQuery<TEntity>): DestroyResultJSON<TEntity, TReturn>;
703
+ }
704
+ /**
705
+ * Result of a destroy operation that does not return records
706
+ */
657
707
  interface DestroyResult<TEntity extends Entity, TReturn> extends PromiseLike<TReturn> {
658
708
  where(args: WhereQuery<TEntity>): DestroyResult<TEntity, TReturn>;
659
709
  }
710
+ /**
711
+ * Result of a destroy operation that returns records (includes toJSON method)
712
+ */
713
+ interface DestroyResultWithRecords<TEntity extends Entity, TReturn> extends PromiseLike<TReturn[]> {
714
+ where(args: WhereQuery<TEntity>): DestroyResultWithRecords<TEntity, TReturn>;
715
+ /**
716
+ * Returns results as plain objects instead of entity class instances.
717
+ * Useful for when data must be serializable.
718
+ */
719
+ toJSON(): DestroyResultJSON<TEntity, TReturn>;
720
+ }
721
+
722
+ /**
723
+ * Result of an update operation that returns plain objects (after calling toJSON())
724
+ */
725
+ interface UpdateResultJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>[]> {
726
+ /**
727
+ * Returns results as plain objects instead of entity class instances.
728
+ * Useful for when data must be serializable.
729
+ */
730
+ toJSON(): UpdateResultJSON<T>;
731
+ }
732
+ /**
733
+ * Result of an update operation that returns records
734
+ */
735
+ interface UpdateResult<T extends Entity> extends PromiseLike<QueryResult<T>[]> {
736
+ /**
737
+ * Returns results as plain objects instead of entity class instances.
738
+ * Useful for when data must be serializable.
739
+ */
740
+ toJSON(): UpdateResultJSON<T>;
741
+ }
660
742
 
661
743
  interface FindOneArgs<T extends Entity, K extends keyof T = string & keyof OmitFunctions<OmitEntityCollections<T>> & keyof T> {
662
744
  select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
@@ -670,6 +752,16 @@ interface FindArgs<T extends Entity, K extends keyof T = keyof T> extends FindOn
670
752
  limit?: number;
671
753
  }
672
754
 
755
+ /**
756
+ * Options for filtering and sorting by junction table columns in through relationships.
757
+ * Uses looser typing since the junction table entity type is determined at runtime.
758
+ */
759
+ interface ThroughArgs {
760
+ /** Filter applied to the junction table query */
761
+ where?: Record<string, unknown>;
762
+ /** Sort applied to the junction table query - determines final ordering of populated items */
763
+ sort?: SortObject<Entity> | string;
764
+ }
673
765
  interface PopulateArgs<T extends Entity, K extends keyof T> {
674
766
  where?: WhereQuery<T>;
675
767
  select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
@@ -677,6 +769,11 @@ interface PopulateArgs<T extends Entity, K extends keyof T> {
677
769
  skip?: number;
678
770
  limit?: number;
679
771
  pool?: PoolLike;
772
+ /**
773
+ * Options for filtering/sorting by junction table columns.
774
+ * Only applicable to many-to-many relationships that use `through`.
775
+ */
776
+ through?: ThroughArgs;
680
777
  }
681
778
 
682
779
  interface FindOneResultJSON<T extends Entity, TReturn, TJoins extends JoinInfo = never> extends PromiseLike<PlainObject<TReturn> | null> {
@@ -795,7 +892,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
795
892
  * @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
796
893
  * @returns {object}
797
894
  */
798
- create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>>;
895
+ create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): CreateResult<T>;
799
896
  /**
800
897
  * Creates an object or objects using the specified values
801
898
  * @param {object|object[]} values - Values to insert as multiple new objects.
@@ -813,7 +910,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
813
910
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
814
911
  * @returns {object[]}
815
912
  */
816
- create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>[]>;
913
+ create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): CreateResultArray<T>;
817
914
  /**
818
915
  * Creates an object using the specified values
819
916
  * @param {object|object[]} values - Values to insert as a new object. If an array is specified, multiple rows will be inserted
@@ -823,7 +920,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
823
920
  * @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
824
921
  * @returns {object|object[]|void} Return value from the db
825
922
  */
826
- create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options?: CreateOptions<T>): Promise<QueryResult<T>[]> | Promise<QueryResult<T>> | Promise<void>;
923
+ create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options?: CreateOptions<T>): CreateResult<T> | CreateResultArray<T> | Promise<void>;
827
924
  /**
828
925
  * Updates object(s) matching the where query, with the specified values
829
926
  * @param {object} where - Object representing the where query
@@ -842,7 +939,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
842
939
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
843
940
  * @returns {object[]}
844
941
  */
845
- update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): Promise<QueryResult<T>[]>;
942
+ update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): UpdateResult<T>;
846
943
  /**
847
944
  * Updates object(s) matching the where query, with the specified values
848
945
  * @param {object} where - Object representing the where query
@@ -852,7 +949,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
852
949
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
853
950
  * @returns {object[]|void} Return values from the db or `true` if returnRecords=false
854
951
  */
855
- update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: CreateUpdateOptions<T>): Promise<QueryResult<T>[]> | Promise<void>;
952
+ update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: CreateUpdateOptions<T>): Promise<void> | UpdateResult<T>;
856
953
  /**
857
954
  * Destroys object(s) matching the where query
858
955
  * @param {object} [where] - Object representing the where query
@@ -867,16 +964,7 @@ interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
867
964
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
868
965
  * @returns {object[]}
869
966
  */
870
- destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResult<T, QueryResult<T>[]>;
871
- /**
872
- * Destroys object(s) matching the where query
873
- * @param {object} where - Object representing the where query
874
- * @param {object} [options]
875
- * @param {boolean} [options.returnRecords=false] - Determines if inserted records should be returned
876
- * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
877
- * @returns {object[]|void} `void` or records affected if returnRecords=true
878
- */
879
- destroy<TOptions extends DeleteOptions<T> = DeleteOptions<T>>(where: WhereQuery<T>, options?: TOptions): TOptions extends DeleteOptions<T> ? Promise<void> : DestroyResult<T, QueryResult<T>[]>;
967
+ destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResultWithRecords<T, QueryResult<T>>;
880
968
  }
881
969
 
882
970
  declare function subquery<T extends Entity>(repository: IReadonlyRepository<T> | IRepository<T>): SubqueryBuilder<T>;
@@ -958,6 +1046,10 @@ interface Populate {
958
1046
  limit?: number;
959
1047
  pool?: PoolLike;
960
1048
  asPlainObjects?: boolean;
1049
+ through?: {
1050
+ where?: Record<string, unknown>;
1051
+ sort?: SortObject<Entity> | string;
1052
+ };
961
1053
  }
962
1054
  declare class ReadonlyRepository<T extends Entity> implements IReadonlyRepository<T> {
963
1055
  private readonly _modelMetadata;
@@ -1017,7 +1109,7 @@ declare class Repository<T extends Entity> extends ReadonlyRepository<T> impleme
1017
1109
  * @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
1018
1110
  * @returns {object}
1019
1111
  */
1020
- create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>>;
1112
+ create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): CreateResult<T>;
1021
1113
  /**
1022
1114
  * Creates an object or objects using the specified values
1023
1115
  * @param {object|object[]} values - Values to insert as multiple new objects.
@@ -1035,7 +1127,7 @@ declare class Repository<T extends Entity> extends ReadonlyRepository<T> impleme
1035
1127
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
1036
1128
  * @returns {object[]}
1037
1129
  */
1038
- create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>[]>;
1130
+ create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): CreateResultArray<T>;
1039
1131
  /**
1040
1132
  * Updates object(s) matching the where query, with the specified values
1041
1133
  * @param {object} where - Object representing the where query
@@ -1053,7 +1145,7 @@ declare class Repository<T extends Entity> extends ReadonlyRepository<T> impleme
1053
1145
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
1054
1146
  * @returns {object[]}
1055
1147
  */
1056
- update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): Promise<QueryResult<T>[]>;
1148
+ update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): UpdateResult<T>;
1057
1149
  /**
1058
1150
  * Destroys object(s) matching the where query
1059
1151
  * @param {object} [where] - Object representing the where query
@@ -1068,7 +1160,7 @@ declare class Repository<T extends Entity> extends ReadonlyRepository<T> impleme
1068
1160
  * @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
1069
1161
  * @returns {object[]}
1070
1162
  */
1071
- destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResult<T, QueryResult<T>[]>;
1163
+ destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResultWithRecords<T, QueryResult<T>>;
1072
1164
  }
1073
1165
 
1074
1166
  interface ColumnBaseOptions {
@@ -1198,4 +1290,4 @@ interface InitializeOptions extends IConnection {
1198
1290
  declare function initialize({ models, pool, readonlyPool, connections, expose }: InitializeOptions): Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
1199
1291
 
1200
1292
  export { ColumnBaseMetadata, ColumnCollectionMetadata, ColumnModelMetadata, ColumnTypeMetadata, Entity, ModelMetadata, QueryError, ReadonlyRepository, Repository, ScalarSubquery, SelectBuilder, SubqueryBuilder, column, createDateColumn, getMetadataStorage, initialize, isSubqueryJoin, primaryColumn, subquery, table, updateDateColumn, versionColumn };
1201
- export type { AggregateBuilder, ClassLike, ColumnBaseMetadataOptions, ColumnCollectionMetadataOptions, ColumnMetadata, ColumnModelMetadataOptions, ColumnModifierMetadata, ColumnTypeMetadataOptions, Comparer, CountResult, CreateUpdateOptions, CreateUpdateParams, DeleteOptions, DestroyResult, DoNotReturnRecords, EntityFieldValue, EntityPrimitiveOrId, EntityStatic, ExcludeEntityCollections, ExcludeFunctions, FindArgs, FindOneArgs, FindOneResult, FindOneResultJSON, FindQueryWithCount, FindQueryWithCountJSON, FindResult, FindResultJSON, FindWithCountResult, GetValueType, HavingComparer, HavingCondition, IConnection, IReadonlyRepository, IRepository, IRepositoryOptions, IncludeFunctions, InitializeOptions, IsValueOfType, JoinDefinition, JoinInfo, JoinType, JoinedSort, JoinedWhereQuery, JsonConstraint, LiteralValues, ModelJoinDefinition, ModelMetadataOptions, ModelRelationshipKeys, MultipleSortString, NegatableConstraint, NotEntity, NotEntityBrand, NumberOrDateConstraint, NumberOrDateConstraintWithSubquery, OmitEntityCollections, OmitFunctions, OrderBy, PaginateOptions, PickAsType, PickByValueType, PickFunctions, PlainObject, PoolLike, PoolQueryResult, PopulateArgs, Populated, QueryResult, QueryResultOptionalPopulated, QueryResultPopulated, QueryResultRow, ReturnSelect$1 as ReturnSelect, ScalarSubqueryConstraint, SelectAggregateExpression, SelectItem, Sort, SortObject, SortObjectValue, SortString, StringConstraint, SubqueryBuilderLike, SubqueryInConstraint, SubqueryJoinDefinition, SubqueryJoinOnCondition, WhereClauseValue, WhereQuery, WhereQueryStatement };
1293
+ export type { AggregateBuilder, ClassLike, ColumnBaseMetadataOptions, ColumnCollectionMetadataOptions, ColumnMetadata, ColumnModelMetadataOptions, ColumnModifierMetadata, ColumnTypeMetadataOptions, Comparer, CountResult, CreateResult, CreateResultArray, CreateResultArrayJSON, CreateResultJSON, CreateUpdateOptions, CreateUpdateParams, DeleteOptions, DestroyResult, DestroyResultJSON, DestroyResultWithRecords, DoNotReturnRecords, EntityFieldValue, EntityPrimitiveOrId, EntityStatic, ExcludeEntityCollections, ExcludeFunctions, FindArgs, FindOneArgs, FindOneResult, FindOneResultJSON, FindQueryWithCount, FindQueryWithCountJSON, FindResult, FindResultJSON, FindWithCountResult, GetValueType, HavingComparer, HavingCondition, IConnection, IReadonlyRepository, IRepository, IRepositoryOptions, IncludeFunctions, InitializeOptions, IsValueOfType, JoinDefinition, JoinInfo, JoinType, JoinedSort, JoinedWhereQuery, JsonConstraint, LiteralValues, ModelJoinDefinition, ModelMetadataOptions, ModelRelationshipKeys, MultipleSortString, NegatableConstraint, NotEntity, NotEntityBrand, NumberOrDateConstraint, NumberOrDateConstraintWithSubquery, OmitEntityCollections, OmitFunctions, OrderBy, PaginateOptions, PickAsType, PickByValueType, PickFunctions, PlainObject, PoolLike, PoolQueryResult, PopulateArgs, Populated, QueryResult, QueryResultOptionalPopulated, QueryResultPopulated, QueryResultRow, ReturnSelect$1 as ReturnSelect, ScalarSubqueryConstraint, SelectAggregateExpression, SelectItem, Sort, SortObject, SortObjectValue, SortString, StringConstraint, SubqueryBuilderLike, SubqueryInConstraint, SubqueryJoinDefinition, SubqueryJoinOnCondition, ThroughArgs, UpdateResult, UpdateResultJSON, WhereClauseValue, WhereQuery, WhereQueryStatement };