@aws/dynamodb-query-iterator

中文文档
0.7.1发布于 2018/07/21Apache-2.0TypeScriptCommonJS近 30 天下载 10.2万

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

中文使用文档
文档目录8 节
  1. 开始器
  2. 查询辅助程序
  3. 扫描辅助器
  4. 并行扫描处理器
  5. 显示器
  6. 查询器
  7. 扫描器
  8. 平行扫描器

Amazon DynamoDB 查询和扫描迭代

Apache 2 License

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

开始器

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

查询辅助程序

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

示例用途

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 实例:

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 以顺序.

示例用途

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 实例:

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 输入时可包含标识符 提供.

示例用途

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 实例:

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 以顺序.

示例用途

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 以顺序.

示例用途

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 输入时可包含标识符 提供.

示例用途

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 共发布 4 个版本,首次发布于 2018/06/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.7.1latest2018/07/218 年前
0.7.02018/07/118 年前
0.6.12018/06/298 年前
0.6.02018/06/178 年前

关于 @aws/dynamodb-query-iterator 的常见问题

@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 和提交记录判断。