# Repository

> 英文标题：Repository
> 官网原文：https://typeorm.io/docs/working-with-entity-manager/working-with-repository
> 文档版本：TypeORM v1.1
> 体例：英文原文（EN）与中文译文（ZH）逐块并列，共 6 块

---

<!-- EN -->
# Repository

<!-- ZH -->
# Repository

<!-- EN -->
`Repository` is just like `EntityManager` but its operations are limited to a concrete entity. You can access the repository via EntityManager.

<!-- ZH -->
`Repository` 就像 `EntityManager`，但它的操作仅限于某个具体实体。你可以通过 EntityManager 访问 repository。

<!-- EN -->
Example:

<!-- ZH -->
示例：

<!-- EN -->
```typescript
import { User } from "./entity/User"

const userRepository = dataSource.getRepository(User)
const user = await userRepository.findOneBy({
    id: 1,
})
user.name = "Umed"
await userRepository.save(user)
```

<!-- ZH -->
```typescript
import { User } from "./entity/User"

const userRepository = dataSource.getRepository(User)
const user = await userRepository.findOneBy({
    id: 1,
})
user.name = "Umed"
await userRepository.save(user)
```

<!-- EN -->
There are 3 types of repositories:

<!-- ZH -->
repository 有 3 种类型：

<!-- EN -->
* `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.

<!-- ZH -->
* `Repository` - 适用于任何实体的常规 repository。
* `TreeRepository` - `Repository` 的扩展，用于树形实体（比如用 `@Tree` 装饰器标记的实体）。它有处理树形结构的特殊方法。
* `MongoRepository` - 带特殊功能的 repository，仅用于 MongoDB。
