# 分页

> 英文标题：Pagination
> 官网原文：https://typeorm.io/docs/performance-optimization/pagination
> 文档版本：TypeORM v1.1
> 体例：英文原文（EN）与中文译文（ZH）逐块并列，共 5 块

---

<!-- EN -->
# Pagination

<!-- ZH -->
# 分页

<!-- EN -->
Pagination is a crucial technique for improving performance when retrieving large amounts of data. Instead of fetching all data at once, pagination divides data into smaller pages, reducing database load and optimizing memory usage.

<!-- ZH -->
分页是在读取大量数据时提升性能的关键技术。分页不是一次性取回所有数据，而是把数据分成较小的页，从而降低数据库负载并优化内存占用。

<!-- EN -->
In TypeORM, you can use `limit` and `offset` for pagination.

<!-- ZH -->
在 TypeORM 中，你可以用 `limit` 和 `offset` 实现分页。

<!-- EN -->
```typescript
const users = await userRepository
    .createQueryBuilder("user")
    .limit(10) // Number of records to fetch per page
    .offset(20) // Skip the first 20 records
    .getMany()
```

<!-- ZH -->
```typescript
const users = await userRepository
    .createQueryBuilder("user")
    .limit(10) // 每页取回的记录数
    .offset(20) // 跳过前 20 条记录
    .getMany()
```

<!-- EN -->
Pagination helps prevent fetching large amounts of data at once, minimizing latency and optimizing memory usage. When implementing pagination, consider using pagination cursors for more efficient handling of dynamic data.

<!-- ZH -->
分页有助于避免一次性取回大量数据，从而降低延迟并优化内存占用。实现分页时，可以考虑使用分页游标（pagination cursors），以更高效地处理动态数据。
