Create repository when EntityRepository is deprecated typeorm

Viewed 3034

I usually use this code to create a repository:

import { EntityRepository, Repository } from 'typeorm'
import { User } from './user.entity'
    
@EntityRepository(User)
export class UserRepository extends Repository<User> {
  getInactiveUsers(): Promise<User[]> {
    return this.createQueryBuilder()
      .where('isActive = :active', { active: false })
      .getMany()
  }
}

However, now EntityRepository is deprecated. I found a reference but I think it's quite complex. I wonder if there is a simpler way to solve it?

2 Answers

Yes, it is deprecated, you can create custom repository with DataSource, you can read this.

But if you want to continue using the Repository class you can roll back to the next version and continue using this feature.

"typeorm": "0.2.45",
"@nestjs/typeorm": "8.0.3",

Use NPM:

npm i @nestjs/typeorm@8.0.3 typeorm@0.2.45

without ^

Related