'Create repository when EntityRepository is deprecated typeorm
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?
Solution 1:[1]
Yes, it is deprecated, you can create custom repository with DataSource, you can read this.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dada |
| Solution 2 | Potier97 |
