# @aws/dynamodb-query-iterator 中文文档

规范地址：https://npmcn.com/package/%40aws/dynamodb-query-iterator/

版本：0\.7\.1
npm 元数据更新时间：2026-10-15T22:06:38.148Z
中文译文更新时间：2026-11-07T12:00:37.063Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aws/dynamodb-query-iterator
原文对照：https://npmcn.com/package/%40aws/dynamodb-query-iterator/?lang=original
项目主页：https://awslabs.github.io/dynamodb-data-mapper-js/packages/dynamodb-scan-iterator/
源码仓库：https://github.com/awslabs/dynamodb-data-mapper-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：73.6 kB，43 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：aws-sdk ^2\.7\.0
- 首次发布：2018-06-16T18:35:46.804Z
- 最新版本发布：2018-07-21T00:24:32.314Z
- 近 30 天下载量：101741（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

DynamoDB 查询和扫描摘要 处理 pagination 和平行的工人协调

## 安装

```sh
npm install @aws/dynamodb-query-iterator
```

也可以使用：`pnpm add @aws/dynamodb-query-iterator`、`yarn add @aws/dynamodb-query-iterator`、`bun add @aws/dynamodb-query-iterator`

## README

# Amazon DynamoDB 查询和扫描迭代

[![Apache 2 License](https://img.shields.io/github/license/awslabs/dynamodb-data-mapper-js.svg?style=flat)](http://aws.amazon.com/apache-2-0/)

这个图书馆为整个DynamoDB自动巡回提供公用设施 通过查询或扫描操作返回的记录 [同步可移动](https://tc39.github.io/ecma262/#sec-asynciterable-interface)。 。 。 . 此软件包中包含的每个迭代和渐变自动轨道 DynamoDB 元数据,并支持在全数内从任何点恢复重迭 查询或扫描.

## 开始器

起动器是一种同步的可移动器,可以生成返回的每页结果 由迪纳摩DB公司制作 `query` 或者说 `scan` 操作。 对于相继起子,每个 援引 `next` 方法与援引基础 API 操作,直到没有其他页面可用为止.

### 查询辅助程序

获取一个 DynamoDB 的所有页面 `query` 以顺序.

#### 示例用途

```typescript
import { QueryPaginator } from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const paginator = new QueryPaginator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        KeyConditionExpression: 'partitionKey = :value',
        ExpressionAttributeValues: {
            ':value': {S: 'foo'}
        },
        ReturnConsumedCapacity: 'INDEXES'
    }
);

for await (const page of paginator) {
    // do something with `page`
}

// Inspect the total number of items yielded
console.log(paginator.count);

// Inspect the total number of items scanned by this operation
console.log(paginator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(paginator.consumedCapacity);
```

#### 暂停和恢复查询

您可以暂停任何运行中的查询 `for` 通过使用 `break` 关键词 如果还有页尚未取出 `lastEvaluatedKey` 将定义占卜器的属性。 这可以提供 作为 `ExclusiveStartKey` 用于另一个 `QueryPaginator` 实例:

```typescript
import { QueryPaginator } from '@aws/dynamodb-query-iterator';
import { QueryInput } from 'aws-sdk/clients/dynamodb';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const dynamoDb = new DynamoDB({region: 'us-west-2'});
const input: QueryInput = {
    TableName: 'my_table',
    KeyConditionExpression: 'partitionKey = :value',
    ExpressionAttributeValues: {
        ':value': {S: 'foo'}
    },
    ReturnConsumedCapacity: 'INDEXES'
};

const paginator = new QueryPaginator(dynamoDb, input);

for await (const page of paginator) {
    // do something with the first page of results
    break
}

for await (const page of new QueryPaginator(dynamoDb, {
    ...input,
    ExclusiveStartKey: paginator.lastEvaluatedKey
})) {
    // do something with the remaining pages
}
```

不支持暂停和恢复同一比特实例.

### 扫描辅助器

获取一个 DynamoDB 的所有页面 `scan` 以顺序.

#### 示例用途

```typescript
import { ScanPaginator } from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const paginator = new ScanPaginator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        ReturnConsumedCapacity: 'INDEXES'
    }
);

for await (const page of paginator) {
    // do something with `page`
}

// Inspect the total number of items yielded
console.log(paginator.count);

// Inspect the total number of items scanned by this operation
console.log(paginator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(paginator.consumedCapacity);
```

#### 暂停和恢复扫描

您可以中止任何运行中的扫描 `for` 通过使用 `break` 关键词 如果还有页尚未取出 `lastEvaluatedKey` 将定义占卜器的属性。 这可以提供 作为 `ExclusiveStartKey` 用于另一个 `ScanPaginator` 实例:

```typescript
import { ScanPaginator } from '@aws/dynamodb-query-iterator';
import { ScanInput } from 'aws-sdk/clients/dynamodb';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const dynamoDb = new DynamoDB({region: 'us-west-2'});
const input: ScanInput = {
    TableName: 'my_table',
    ReturnConsumedCapacity: 'INDEXES'
};

const paginator = new ScanPaginator(dynamoDb, input);

for await (const page of paginator) {
    // do something with the first page of results
    break
}

for await (const page of new ScanPaginator(dynamoDb, {
    ...input,
    ExclusiveStartKey: paginator.lastEvaluatedKey
})) {
    // do something with the remaining pages
}
```

不支持暂停和恢复同一比特实例.

### 并行扫描处理器

获取一个 DynamoDB 的所有页面 `scan` 使用可配置的扫描次数 平行运行的区段。 在进行平行扫描时,必须 指定您想要使用的片段的总数,而不是 `ExclusiveStartKey` 也没有 `Segment` 输入时可包含标识符 提供.

#### 示例用途

```typescript
import { ParallelScanPaginator } from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const paginator = new ParallelScanPaginator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        TotalSegments: 4,
        ReturnConsumedCapacity: 'INDEXES'
    }
);

for await (const page of paginator) {
    // do something with `page`
}

// Inspect the total number of items yielded
console.log(paginator.count);

// Inspect the total number of items scanned by this operation
console.log(paginator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(paginator.consumedCapacity);
```

#### 暂停和恢复平行扫描

您可以中止任何运行中的扫描 `for` 通过使用 `break` 关键词 如果还有页尚未取出 `scanState` 中断的起动器的属性可以提供给另一个起动器的构造者 `ParallelScanPaginator` 实例:

```typescript
import { 
    ParallelScanInput,
    ParallelScanPaginator,
} from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const client = new DynamoDB({region: 'us-west-2'});
const input: ParallelScanInput = {
    TableName: 'my_table',
    TotalSegments: 4,
    ReturnConsumedCapacity: 'INDEXES'
};

const paginator = new ParallelScanPaginator(client, input);

for await (const page of paginator) {
    // do something with the first page of results
    break
}

for await (const page of new ParallelScanPaginator(
    client,
    input,
    paginator.scanState
)) {
    // do something with the remaining pages
}
```

不支持暂停和恢复同一比特实例.

## 显示器

传动器是一种同步的传动器,它使每个记录都通过一个 迪纳摩DB `query` 或者说 `scan` 操作。 每一援引 `next` 方法可能 引用基础的 API 操作,直到不再有所有页面.

### 查询器

检索 DynamoDB 的全部记录 `query` 以顺序.

#### 示例用途

```typescript
import { QueryIterator } from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const iterator = new QueryIterator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        KeyConditionExpression: 'partitionKey = :value',
        ExpressionAttributeValues: {
            ':value': {S: 'foo'}
        },
        ReturnConsumedCapacity: 'INDEXES'
    },
    ['partitionKey']
);

for await (const record of iterator) {
    // do something with `record`
}

// Inspect the total number of items yielded
console.log(iterator.count);

// Inspect the total number of items scanned by this operation
console.log(iterator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(iterator.consumedCapacity);
```

### 扫描器

检索 DynamoDB 的全部记录 `scan` 以顺序.

#### 示例用途

```typescript
import { ScanIterator } from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const iterator = new ScanIterator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        ReturnConsumedCapacity: 'INDEXES'
    },
    ['partitionKey', 'sortKey']
);

for await (const record of iterator) {
    // do something with `record`
}

// Inspect the total number of items yielded
console.log(iterator.count);

// Inspect the total number of items scanned by this operation
console.log(iterator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(iterator.consumedCapacity);
```

### 平行扫描器

获取一个 DynamoDB 的所有页面 `scan` 使用可配置的扫描次数 平行运行的区段。 在进行平行扫描时,必须 指定您想要使用的片段的总数,而不是 `ExclusiveStartKey` 也没有 `Segment` 输入时可包含标识符 提供.

#### 示例用途

```typescript
import { ParallelScanIterator} from '@aws/dynamodb-query-iterator';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const iterator = new ParallelScanIterator(
    new DynamoDB({region: 'us-west-2'}),
    {
        TableName: 'my_table',
        TotalSegments: 4,
        ReturnConsumedCapacity: 'INDEXES'
    },
    ['partitionKey']
);

for await (const record of iterator) {
    // do something with `record`
}

// Inspect the total number of items yielded
console.log(iterator.count);

// Inspect the total number of items scanned by this operation
console.log(iterator.scannedCount);

// Inspect the capacity consumed by this operation 
// This will only be available if `ReturnConsumedCapacity` was set on the input
console.log(iterator.consumedCapacity);
```

## 常见问题

### @aws/dynamodb-query-iterator 是什么？

DynamoDB 查询和扫描摘要 处理 pagination 和平行的工人协调

### 如何安装 @aws/dynamodb-query-iterator？

在项目目录运行 npm install @aws/dynamodb-query-iterator，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：aws-sdk（^2\.7\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @aws/dynamodb-query-iterator 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @aws/dynamodb-query-iterator 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @aws/dynamodb-query-iterator 可以商用吗？

@aws/dynamodb-query-iterator 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @aws/dynamodb-query-iterator 的下载量有多少？

根据 npm 官方下载统计，@aws/dynamodb-query-iterator 在 2026/10/08 – 2026/11/06 这 30 天内被下载 101,741 次，日均约 3,391 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @aws/dynamodb-query-iterator 还在维护吗？

最新版本 0\.7\.1 发布于 2018/07/21（8 年前）；至今共发布 4 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/06/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

