def query_biggest(self, hash_key, hash_value, num_items, index=None, forward=False):
"""Method to query for the largest N records
Args:
hash_key (str): Hash key name
hash_value (str): Hash key value
num_items (int): The number of items to return
index (str): Name of index if not primary
forward (bool): flag indicating sort direction
Returns:
dict
"""
params = {"ScanIndexForward": forward,
"KeyConditionExpression": Key(hash_key).eq(hash_value),
"Select": "ALL_ATTRIBUTES",
"Limit": num_items}
if index:
params["IndexName"] = index
params["Select"] = "ALL_PROJECTED_ATTRIBUTES"
else:
# If primary index, consistent read
params["ConsistentRead"] = True
response = self.table.query(**params)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception("Error getting item: {}".format(response['ResponseMetadata']))
if "Items" in response:
if response["Items"]:
return response["Items"]
else:
return []
else:
return []
评论列表
文章目录