• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.33
/src/repository/Repository.ts
1
import { FindManyOptions } from "../find-options/FindManyOptions"
2
import { ObjectLiteral } from "../common/ObjectLiteral"
3
import { FindOneOptions } from "../find-options/FindOneOptions"
4
import { DeepPartial } from "../common/DeepPartial"
5
import { SaveOptions } from "./SaveOptions"
6
import { RemoveOptions } from "./RemoveOptions"
7
import { EntityManager } from "../entity-manager/EntityManager"
8
import { QueryRunner } from "../query-runner/QueryRunner"
9
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder"
10
import { DeleteResult } from "../query-builder/result/DeleteResult"
11
import { UpdateResult } from "../query-builder/result/UpdateResult"
12
import { InsertResult } from "../query-builder/result/InsertResult"
13
import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity"
14
import { ObjectId } from "../driver/mongodb/typings"
15
import { FindOptionsWhere } from "../find-options/FindOptionsWhere"
16
import { UpsertOptions } from "./UpsertOptions"
17
import { EntityTarget } from "../common/EntityTarget"
18
import { PickKeysByType } from "../common/PickKeysByType"
19
import { buildSqlTag } from "../util/SqlTagUtils"
1✔
20

21
/**
22
 * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
23
 */
24
export class Repository<Entity extends ObjectLiteral> {
1✔
25
    // -------------------------------------------------------------------------
26
    // Public Properties
27
    // -------------------------------------------------------------------------
28

29
    /**
30
     * Entity target that is managed by this repository.
31
     * If this repository manages entity from schema,
32
     * then it returns a name of that schema instead.
33
     */
34
    readonly target: EntityTarget<Entity>
35

36
    /**
37
     * Entity Manager used by this repository.
38
     */
39
    readonly manager: EntityManager
40

41
    /**
42
     * Query runner provider used for this repository.
43
     */
44
    readonly queryRunner?: QueryRunner
45

46
    // -------------------------------------------------------------------------
47
    // Accessors
48
    // -------------------------------------------------------------------------
49

50
    /**
51
     * Entity metadata of the entity current repository manages.
52
     */
53
    get metadata() {
54
        return this.manager.connection.getMetadata(this.target)
214✔
55
    }
56

57
    // -------------------------------------------------------------------------
58
    // Constructor
59
    // -------------------------------------------------------------------------
60

61
    constructor(
62
        target: EntityTarget<Entity>,
63
        manager: EntityManager,
64
        queryRunner?: QueryRunner,
65
    ) {
66
        this.target = target
47✔
67
        this.manager = manager
47✔
68
        this.queryRunner = queryRunner
47✔
69
    }
70

71
    // -------------------------------------------------------------------------
72
    // Public Methods
73
    // -------------------------------------------------------------------------
74

75
    /**
76
     * Creates a new query builder that can be used to build a SQL query.
77
     */
78
    createQueryBuilder(
79
        alias?: string,
80
        queryRunner?: QueryRunner,
81
    ): SelectQueryBuilder<Entity> {
UNCOV
82
        return this.manager.createQueryBuilder<Entity>(
×
83
            this.metadata.target as any,
84
            alias || this.metadata.targetName,
×
85
            queryRunner || this.queryRunner,
×
86
        )
87
    }
88

89
    /**
90
     * Checks if entity has an id.
91
     * If entity composite compose ids, it will check them all.
92
     */
93
    hasId(entity: Entity): boolean {
94
        return this.manager.hasId(this.metadata.target, entity)
1✔
95
    }
96

97
    /**
98
     * Gets entity mixed id.
99
     */
100
    getId(entity: Entity): any {
101
        return this.manager.getId(this.metadata.target, entity)
×
102
    }
103

104
    /**
105
     * Creates a new entity instance.
106
     */
107
    create(): Entity
108

109
    /**
110
     * Creates new entities and copies all entity properties from given objects into their new entities.
111
     * Note that it copies only properties that are present in entity schema.
112
     */
113
    create(entityLikeArray: DeepPartial<Entity>[]): Entity[]
114

115
    /**
116
     * Creates a new entity instance and copies all entity properties from this object into a new entity.
117
     * Note that it copies only properties that are present in entity schema.
118
     */
119
    create(entityLike: DeepPartial<Entity>): Entity
120

121
    /**
122
     * Creates a new entity instance or instances.
123
     * Can copy properties from the given object into new entities.
124
     */
125
    create(
126
        plainEntityLikeOrPlainEntityLikes?:
127
            | DeepPartial<Entity>
128
            | DeepPartial<Entity>[],
129
    ): Entity | Entity[] {
130
        return this.manager.create(
4✔
131
            this.metadata.target as any,
132
            plainEntityLikeOrPlainEntityLikes as any,
133
        )
134
    }
135

136
    /**
137
     * Merges multiple entities (or entity-like objects) into a given entity.
138
     */
139
    merge(
140
        mergeIntoEntity: Entity,
141
        ...entityLikes: DeepPartial<Entity>[]
142
    ): Entity {
143
        return this.manager.merge(
2✔
144
            this.metadata.target as any,
145
            mergeIntoEntity,
146
            ...entityLikes,
147
        )
148
    }
149

150
    /**
151
     * Creates a new entity from the given plain javascript object. If entity already exist in the database, then
152
     * it loads it (and everything related to it), replaces all values with the new ones from the given object
153
     * and returns this new entity. This new entity is actually a loaded from the db entity with all properties
154
     * replaced from the new object.
155
     *
156
     * Note that given entity-like object must have an entity id / primary key to find entity by.
157
     * Returns undefined if entity with given id was not found.
158
     */
159
    preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined> {
160
        return this.manager.preload(this.metadata.target as any, entityLike)
1✔
161
    }
162

163
    /**
164
     * Saves all given entities in the database.
165
     * If entities do not exist in the database then inserts, otherwise updates.
166
     */
167
    save<T extends DeepPartial<Entity>>(
168
        entities: T[],
169
        options: SaveOptions & { reload: false },
170
    ): Promise<T[]>
171

172
    /**
173
     * Saves all given entities in the database.
174
     * If entities do not exist in the database then inserts, otherwise updates.
175
     */
176
    save<T extends DeepPartial<Entity>>(
177
        entities: T[],
178
        options?: SaveOptions,
179
    ): Promise<(T & Entity)[]>
180

181
    /**
182
     * Saves a given entity in the database.
183
     * If entity does not exist in the database then inserts, otherwise updates.
184
     */
185
    save<T extends DeepPartial<Entity>>(
186
        entity: T,
187
        options: SaveOptions & { reload: false },
188
    ): Promise<T>
189

190
    /**
191
     * Saves a given entity in the database.
192
     * If entity does not exist in the database then inserts, otherwise updates.
193
     */
194
    save<T extends DeepPartial<Entity>>(
195
        entity: T,
196
        options?: SaveOptions,
197
    ): Promise<T & Entity>
198

199
    /**
200
     * Saves one or many given entities.
201
     */
202
    save<T extends DeepPartial<Entity>>(
203
        entityOrEntities: T | T[],
204
        options?: SaveOptions,
205
    ): Promise<T | T[]> {
206
        return this.manager.save<Entity, T>(
91✔
207
            this.metadata.target as any,
208
            entityOrEntities as any,
209
            options,
210
        )
211
    }
212

213
    /**
214
     * Removes a given entities from the database.
215
     */
216
    remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>
217

218
    /**
219
     * Removes a given entity from the database.
220
     */
221
    remove(entity: Entity, options?: RemoveOptions): Promise<Entity>
222

223
    /**
224
     * Removes one or many given entities.
225
     */
226
    remove(
227
        entityOrEntities: Entity | Entity[],
228
        options?: RemoveOptions,
229
    ): Promise<Entity | Entity[]> {
230
        return this.manager.remove(
4✔
231
            this.metadata.target as any,
232
            entityOrEntities as any,
233
            options,
234
        )
235
    }
236

237
    /**
238
     * Records the delete date of all given entities.
239
     */
240
    softRemove<T extends DeepPartial<Entity>>(
241
        entities: T[],
242
        options: SaveOptions & { reload: false },
243
    ): Promise<T[]>
244

245
    /**
246
     * Records the delete date of all given entities.
247
     */
248
    softRemove<T extends DeepPartial<Entity>>(
249
        entities: T[],
250
        options?: SaveOptions,
251
    ): Promise<(T & Entity)[]>
252

253
    /**
254
     * Records the delete date of a given entity.
255
     */
256
    softRemove<T extends DeepPartial<Entity>>(
257
        entity: T,
258
        options: SaveOptions & { reload: false },
259
    ): Promise<T>
260

261
    /**
262
     * Records the delete date of a given entity.
263
     */
264
    softRemove<T extends DeepPartial<Entity>>(
265
        entity: T,
266
        options?: SaveOptions,
267
    ): Promise<T & Entity>
268

269
    /**
270
     * Records the delete date of one or many given entities.
271
     */
272
    softRemove<T extends DeepPartial<Entity>>(
273
        entityOrEntities: T | T[],
274
        options?: SaveOptions,
275
    ): Promise<T | T[]> {
276
        return this.manager.softRemove<Entity, T>(
3✔
277
            this.metadata.target as any,
278
            entityOrEntities as any,
279
            options,
280
        )
281
    }
282

283
    /**
284
     * Recovers all given entities in the database.
285
     */
286
    recover<T extends DeepPartial<Entity>>(
287
        entities: T[],
288
        options: SaveOptions & { reload: false },
289
    ): Promise<T[]>
290

291
    /**
292
     * Recovers all given entities in the database.
293
     */
294
    recover<T extends DeepPartial<Entity>>(
295
        entities: T[],
296
        options?: SaveOptions,
297
    ): Promise<(T & Entity)[]>
298

299
    /**
300
     * Recovers a given entity in the database.
301
     */
302
    recover<T extends DeepPartial<Entity>>(
303
        entity: T,
304
        options: SaveOptions & { reload: false },
305
    ): Promise<T>
306

307
    /**
308
     * Recovers a given entity in the database.
309
     */
310
    recover<T extends DeepPartial<Entity>>(
311
        entity: T,
312
        options?: SaveOptions,
313
    ): Promise<T & Entity>
314

315
    /**
316
     * Recovers one or many given entities.
317
     */
318
    recover<T extends DeepPartial<Entity>>(
319
        entityOrEntities: T | T[],
320
        options?: SaveOptions,
321
    ): Promise<T | T[]> {
UNCOV
322
        return this.manager.recover<Entity, T>(
×
323
            this.metadata.target as any,
324
            entityOrEntities as any,
325
            options,
326
        )
327
    }
328

329
    /**
330
     * Inserts a given entity into the database.
331
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
332
     * Executes fast and efficient INSERT query.
333
     * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
334
     */
335
    insert(
336
        entity:
337
            | QueryDeepPartialEntity<Entity>
338
            | QueryDeepPartialEntity<Entity>[],
339
    ): Promise<InsertResult> {
340
        return this.manager.insert(this.metadata.target as any, entity)
4✔
341
    }
342

343
    /**
344
     * Updates entity partially. Entity can be found by a given conditions.
345
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
346
     * Executes fast and efficient UPDATE query.
347
     * Does not check if entity exist in the database.
348
     */
349
    update(
350
        criteria:
351
            | string
352
            | string[]
353
            | number
354
            | number[]
355
            | Date
356
            | Date[]
357
            | ObjectId
358
            | ObjectId[]
359
            | FindOptionsWhere<Entity>
360
            | FindOptionsWhere<Entity>[],
361
        partialEntity: QueryDeepPartialEntity<Entity>,
362
    ): Promise<UpdateResult> {
363
        return this.manager.update(
1✔
364
            this.metadata.target,
365
            criteria,
366
            partialEntity,
367
        )
368
    }
369

370
    /**
371
     * Updates all entities of target type, setting fields from supplied partial entity.
372
     * This is a primitive operation without cascades, relations or other operations included.
373
     * Executes fast and efficient UPDATE query without WHERE clause.
374
     *
375
     * WARNING! This method updates ALL rows in the target table.
376
     */
377
    updateAll(
378
        partialEntity: QueryDeepPartialEntity<Entity>,
379
    ): Promise<UpdateResult> {
UNCOV
380
        return this.manager.updateAll(this.metadata.target, partialEntity)
×
381
    }
382

383
    /**
384
     * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
385
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
386
     * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
387
     */
388
    upsert(
389
        entityOrEntities:
390
            | QueryDeepPartialEntity<Entity>
391
            | QueryDeepPartialEntity<Entity>[],
392
        conflictPathsOrOptions: string[] | UpsertOptions<Entity>,
393
    ): Promise<InsertResult> {
UNCOV
394
        return this.manager.upsert(
×
395
            this.metadata.target as any,
396
            entityOrEntities,
397
            conflictPathsOrOptions,
398
        )
399
    }
400

401
    /**
402
     * Deletes entities by a given criteria.
403
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
404
     * Executes fast and efficient DELETE query.
405
     * Does not check if entity exist in the database.
406
     */
407
    delete(
408
        criteria:
409
            | string
410
            | string[]
411
            | number
412
            | number[]
413
            | Date
414
            | Date[]
415
            | ObjectId
416
            | ObjectId[]
417
            | FindOptionsWhere<Entity>
418
            | FindOptionsWhere<Entity>[],
419
    ): Promise<DeleteResult> {
420
        return this.manager.delete(this.metadata.target, criteria)
2✔
421
    }
422

423
    /**
424
     * Deletes all entities of target type.
425
     * This is a primitive operation without cascades, relations or other operations included.
426
     * Executes fast and efficient DELETE query without WHERE clause.
427
     *
428
     * WARNING! This method deletes ALL rows in the target table.
429
     */
430
    deleteAll(): Promise<DeleteResult> {
UNCOV
431
        return this.manager.deleteAll(this.metadata.target)
×
432
    }
433

434
    /**
435
     * Records the delete date of entities by a given criteria.
436
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
437
     * Executes fast and efficient SOFT-DELETE query.
438
     * Does not check if entity exist in the database.
439
     */
440
    softDelete(
441
        criteria:
442
            | string
443
            | string[]
444
            | number
445
            | number[]
446
            | Date
447
            | Date[]
448
            | ObjectId
449
            | ObjectId[]
450
            | FindOptionsWhere<Entity>
451
            | FindOptionsWhere<Entity>[],
452
    ): Promise<UpdateResult> {
UNCOV
453
        return this.manager.softDelete(
×
454
            this.metadata.target as any,
455
            criteria as any,
456
        )
457
    }
458

459
    /**
460
     * Restores entities by a given criteria.
461
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
462
     * Executes fast and efficient SOFT-DELETE query.
463
     * Does not check if entity exist in the database.
464
     */
465
    restore(
466
        criteria:
467
            | string
468
            | string[]
469
            | number
470
            | number[]
471
            | Date
472
            | Date[]
473
            | ObjectId
474
            | ObjectId[]
475
            | FindOptionsWhere<Entity>
476
            | FindOptionsWhere<Entity>[],
477
    ): Promise<UpdateResult> {
UNCOV
478
        return this.manager.restore(
×
479
            this.metadata.target as any,
480
            criteria as any,
481
        )
482
    }
483

484
    /**
485
     * Checks whether any entity exists that matches the given options.
486
     *
487
     * @deprecated use `exists` method instead, for example:
488
     *
489
     * .exists()
490
     */
491
    exist(options?: FindManyOptions<Entity>): Promise<boolean> {
492
        return this.manager.exists(this.metadata.target, options)
×
493
    }
494

495
    /**
496
     * Checks whether any entity exists that matches the given options.
497
     */
498
    exists(options?: FindManyOptions<Entity>): Promise<boolean> {
UNCOV
499
        return this.manager.exists(this.metadata.target, options)
×
500
    }
501

502
    /**
503
     * Checks whether any entity exists that matches the given conditions.
504
     */
505
    existsBy(
506
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
507
    ): Promise<boolean> {
508
        return this.manager.existsBy(this.metadata.target, where)
×
509
    }
510

511
    /**
512
     * Counts entities that match given options.
513
     * Useful for pagination.
514
     */
515
    count(options?: FindManyOptions<Entity>): Promise<number> {
UNCOV
516
        return this.manager.count(this.metadata.target, options)
×
517
    }
518

519
    /**
520
     * Counts entities that match given conditions.
521
     * Useful for pagination.
522
     */
523
    countBy(
524
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
525
    ): Promise<number> {
UNCOV
526
        return this.manager.countBy(this.metadata.target, where)
×
527
    }
528

529
    /**
530
     * Return the SUM of a column
531
     */
532
    sum(
533
        columnName: PickKeysByType<Entity, number>,
534
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
535
    ): Promise<number | null> {
UNCOV
536
        return this.manager.sum(this.metadata.target, columnName, where)
×
537
    }
538

539
    /**
540
     * Return the AVG of a column
541
     */
542
    average(
543
        columnName: PickKeysByType<Entity, number>,
544
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
545
    ): Promise<number | null> {
UNCOV
546
        return this.manager.average(this.metadata.target, columnName, where)
×
547
    }
548

549
    /**
550
     * Return the MIN of a column
551
     */
552
    minimum(
553
        columnName: PickKeysByType<Entity, number>,
554
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
555
    ): Promise<number | null> {
UNCOV
556
        return this.manager.minimum(this.metadata.target, columnName, where)
×
557
    }
558

559
    /**
560
     * Return the MAX of a column
561
     */
562
    maximum(
563
        columnName: PickKeysByType<Entity, number>,
564
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
565
    ): Promise<number | null> {
UNCOV
566
        return this.manager.maximum(this.metadata.target, columnName, where)
×
567
    }
568

569
    /**
570
     * Finds entities that match given find options.
571
     */
572
    async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {
UNCOV
573
        return this.manager.find(this.metadata.target, options)
×
574
    }
575

576
    /**
577
     * Finds entities that match given find options.
578
     */
579
    async findBy(
580
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
581
    ): Promise<Entity[]> {
UNCOV
582
        return this.manager.findBy(this.metadata.target, where)
×
583
    }
584

585
    /**
586
     * Finds entities that match given find options.
587
     * Also counts all entities that match given conditions,
588
     * but ignores pagination settings (from and take options).
589
     */
590
    findAndCount(
591
        options?: FindManyOptions<Entity>,
592
    ): Promise<[Entity[], number]> {
UNCOV
593
        return this.manager.findAndCount(this.metadata.target, options)
×
594
    }
595

596
    /**
597
     * Finds entities that match given WHERE conditions.
598
     * Also counts all entities that match given conditions,
599
     * but ignores pagination settings (from and take options).
600
     */
601
    findAndCountBy(
602
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
603
    ): Promise<[Entity[], number]> {
604
        return this.manager.findAndCountBy(this.metadata.target, where)
×
605
    }
606

607
    /**
608
     * Finds entities with ids.
609
     * Optionally find options or conditions can be applied.
610
     *
611
     * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:
612
     *
613
     * .findBy({
614
     *     id: In([1, 2, 3])
615
     * })
616
     */
617
    async findByIds(ids: any[]): Promise<Entity[]> {
UNCOV
618
        return this.manager.findByIds(this.metadata.target, ids)
×
619
    }
620

621
    /**
622
     * Finds first entity by a given find options.
623
     * If entity was not found in the database - returns null.
624
     */
625
    async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {
UNCOV
626
        return this.manager.findOne(this.metadata.target, options)
×
627
    }
628

629
    /**
630
     * Finds first entity that matches given where condition.
631
     * If entity was not found in the database - returns null.
632
     */
633
    async findOneBy(
634
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
635
    ): Promise<Entity | null> {
UNCOV
636
        return this.manager.findOneBy(this.metadata.target, where)
×
637
    }
638

639
    /**
640
     * Finds first entity that matches given id.
641
     * If entity was not found in the database - returns null.
642
     *
643
     * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:
644
     *
645
     * .findOneBy({
646
     *     id: 1 // where "id" is your primary column name
647
     * })
648
     */
649
    async findOneById(
650
        id: number | string | Date | ObjectId,
651
    ): Promise<Entity | null> {
UNCOV
652
        return this.manager.findOneById(this.metadata.target, id)
×
653
    }
654

655
    /**
656
     * Finds first entity by a given find options.
657
     * If entity was not found in the database - rejects with error.
658
     */
659
    async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {
UNCOV
660
        return this.manager.findOneOrFail(this.metadata.target, options)
×
661
    }
662

663
    /**
664
     * Finds first entity that matches given where condition.
665
     * If entity was not found in the database - rejects with error.
666
     */
667
    async findOneByOrFail(
668
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
669
    ): Promise<Entity> {
UNCOV
670
        return this.manager.findOneByOrFail(this.metadata.target, where)
×
671
    }
672

673
    /**
674
     * Executes a raw SQL query and returns a raw database results.
675
     * Raw query execution is supported only by relational databases (MongoDB is not supported).
676
     *
677
     * @see [Official docs](https://typeorm.io/repository-api) for examples.
678
     */
679
    query<T = any>(query: string, parameters?: any[]): Promise<T> {
UNCOV
680
        return this.manager.query(query, parameters)
×
681
    }
682

683
    /**
684
     * Tagged template function that executes raw SQL query and returns raw database results.
685
     * Template expressions are automatically transformed into database parameters.
686
     * Raw query execution is supported only by relational databases (MongoDB is not supported).
687
     * Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal.
688
     * Example: repository.sql`SELECT * FROM table_name WHERE id = ${id}`
689
     */
690
    async sql<T = any>(
691
        strings: TemplateStringsArray,
692
        ...values: unknown[]
693
    ): Promise<T> {
694
        const { query, parameters } = buildSqlTag({
×
695
            driver: this.manager.connection.driver,
696
            strings: strings,
697
            expressions: values,
698
        })
699

700
        return await this.query(query, parameters)
×
701
    }
702

703
    /**
704
     * Clears all the data from the given table/collection (truncates/drops it).
705
     *
706
     * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
707
     * @see https://stackoverflow.com/a/5972738/925151
708
     */
709
    clear(): Promise<void> {
710
        return this.manager.clear(this.metadata.target)
2✔
711
    }
712

713
    /**
714
     * Increments some column by provided value of the entities matched given conditions.
715
     */
716
    increment(
717
        conditions: FindOptionsWhere<Entity>,
718
        propertyPath: string,
719
        value: number | string,
720
    ): Promise<UpdateResult> {
UNCOV
721
        return this.manager.increment(
×
722
            this.metadata.target,
723
            conditions,
724
            propertyPath,
725
            value,
726
        )
727
    }
728

729
    /**
730
     * Decrements some column by provided value of the entities matched given conditions.
731
     */
732
    decrement(
733
        conditions: FindOptionsWhere<Entity>,
734
        propertyPath: string,
735
        value: number | string,
736
    ): Promise<UpdateResult> {
UNCOV
737
        return this.manager.decrement(
×
738
            this.metadata.target,
739
            conditions,
740
            propertyPath,
741
            value,
742
        )
743
    }
744

745
    /**
746
     * Extends repository with provided functions.
747
     */
748
    extend<CustomRepository>(
749
        customs: CustomRepository & ThisType<this & CustomRepository>,
750
    ): this & CustomRepository {
751
        // return {
752
        //     ...this,
753
        //     ...custom
754
        // };
UNCOV
755
        const thisRepo: any = this.constructor
×
UNCOV
756
        const { target, manager, queryRunner } = this
×
UNCOV
757
        const ChildClass = class extends thisRepo {
×
758
            constructor(
759
                target: EntityTarget<Entity>,
760
                manager: EntityManager,
761
                queryRunner?: QueryRunner,
762
            ) {
UNCOV
763
                super(target, manager, queryRunner)
×
764
            }
765
        }
UNCOV
766
        for (const custom in customs)
×
UNCOV
767
            ChildClass.prototype[custom] = customs[custom]
×
UNCOV
768
        return new ChildClass(target, manager, queryRunner) as any
×
769
    }
770
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc