def query_hash(self, hash_name, hash_value, index=None, forward=True, limit=None, projection=None):
"""Method to query an index
Args:
data (dict): A dictionary of attributes to put
Returns:
(dict)
"""
params = {"ScanIndexForward": forward,
"KeyConditionExpression": Key(hash_name).eq(hash_value)}
if index:
params["IndexName"] = index
else:
# If primary index, consistent read
params["ConsistentRead"] = True
if limit:
params["Limit"] = limit
if projection:
params["ProjectionExpression"] = projection
response = self.table.query(**params)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception("Error getting item: {}".format(response['ResponseMetadata']))
return response["Items"]
评论列表
文章目录