【发布时间】:2020-01-19 04:29:56
【问题描述】:
我正在尝试使用官方 AWS 库 dynamodb-data-mapper-js 在 Node.js 中设置 DynamoDB 数据库,以创建持久模型对象和数据映射器。但是,它似乎没有提及有关使用本地二级索引或 GSI 创建表的任何内容。
我发现an issue in Github 提供了有关如何使用 LSI 创建表的参考,提供的示例解释了引用 rangeKey 和声明 LSI 之间的区别:
@table('items')
class Item {
@hashKey({ // <-- this is your normal hash key (shared by table and of LSI)
indexKeyConfigurations:{
ItemIdIndex: 'HASH' // The key (ItemIdIndex) is the name of the index; the value is the key type ('HASH' or 'RANGE')
}
})
itemId: string;
@rangeKey() // <-- this is your normal range key (not part of LSI)
displayName: string;
@attribute({
// And this other attribute acts as the LSI's RangeKey
indexKeyConfigurations: {
ItemIdIndex: 'RANGE'
}
})
foo: string;
@attribute()
bar: string;
}
但是,我使用完全相同的表模型创建了一个表,但出现以下错误:
Error: No options provided for ItemIdIndex index at indexDefinitions
我无法获得更多信息,即使他们说他们支持 LSI 或 GSI,文档也没有说明任何内容。
【问题讨论】:
标签: javascript node.js typescript amazon-web-services amazon-dynamodb