What is Repository
Repository is just like EntityManager but its operations are limited to a concrete entity.
You can access repository via getRepository(Entity), Connection#getRepository, or EntityManager#getRepository. Example:
1
import {getRepository} from "typeorm";
2
import {User} from "./entity/User";
3
​
4
const userRepository = getRepository(User); // you can also get it via getConnection().getRepository() or getManager().getRepository()
5
const user = await userRepository.findOne(1);
6
user.name = "Umed";
7
await userRepository.save(user);
Copied!
There are 3 types of repositories:
    Repository - Regular repository for any entity.
    TreeRepository - Repository, extensions of Repository used for tree-entities
    (like entities marked with @Tree decorator).
    Has special methods to work with tree structures.
    MongoRepository - Repository with special functions used only with MongoDB.
Last modified 1mo ago
Copy link