的艺术家的所有专辑
我想获得许多videoid的项目,而不是像在这个代码中只有一个视频项目?是否有一种方法来查询多个项目从一个索引?
AWSDynamoDBObjectMapper *objectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];
queryExpression.indexName = @"getVideoItem";
queryExpression.keyConditionExpression = @"#id = :id";
queryExpression.expressionAttributeNames = @{
@"#id" : @"id",
};
queryExpression.expressionAttributeValues = @{
@":id" : videoId,
};
__weak typeof(self) weakSelf = self;
[objectMapper query:[PublicVideos class]
expression:queryExpression
completionHandler:^(AWSDynamoDBPaginatedOutput * _Nullable response, NSError * _Nullable error) {
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
if ([weakSelf.delegate respondsToSelector:@selector(ServerConnectionHandlerVideoListRecevied:)]) {
[weakSelf.delegate ServerConnectionHandlerVideoListRecevied:response.items];
}
});
}
}];
表的模式是什么样子的?是否为表启用了散列键和范围键?如果您没有任何范围键,那么每个哈希键将只有一个条目,并且您的查询将只返回一行。
如果你同时有哈希键和范围键,你可以这样查询:
AWSDynamoDBObjectMapper *objectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];
queryExpression.indexName = @"Artist-Album-index";
queryExpression.keyConditionExpression = @"#artist = :artist AND #album < :album";
queryExpression.expressionAttributeNames = @{
@"#artist" : @"Artist",
@"#album" : @"Album",
};
queryExpression.expressionAttributeValues = @{
@":artist" : @"valuetosearch",
@":album" : @"valuetosearch",
};
[objectMapper query:[Song class]
expression:queryExpression
completionHandler:^(AWSDynamoDBPaginatedOutput * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
// handle response
});
}];
在上面的代码片段中,它尝试查找符合条件'<'