Spaces:
Runtime error
Runtime error
feat: implement get all items in Table by setting name_of_key
Browse files- modules/db_modules.py +14 -2
modules/db_modules.py
CHANGED
@@ -52,10 +52,22 @@ def get_item(table, item):
|
|
52 |
|
53 |
def get_lastest_item(table, name_of_partition_key, value_of_partition_key, limit_num=10):
|
54 |
|
55 |
-
response = table.query
|
56 |
KeyConditionExpression=Key(name_of_partition_key).eq(value_of_partition_key),
|
57 |
ScanIndexForward=False,
|
58 |
Limit=limit_num
|
59 |
)
|
60 |
|
61 |
-
return response['Items']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
def get_lastest_item(table, name_of_partition_key, value_of_partition_key, limit_num=10):
|
54 |
|
55 |
+
response = table.query(
|
56 |
KeyConditionExpression=Key(name_of_partition_key).eq(value_of_partition_key),
|
57 |
ScanIndexForward=False,
|
58 |
Limit=limit_num
|
59 |
)
|
60 |
|
61 |
+
return response['Items']
|
62 |
+
|
63 |
+
def get_all_items(table, name_of_key):
|
64 |
+
|
65 |
+
response = table.scan()
|
66 |
+
data = response['Items']
|
67 |
+
|
68 |
+
while 'LastEvaluatedKey' in response:
|
69 |
+
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
|
70 |
+
data.extend(response['Items'])
|
71 |
+
|
72 |
+
items = set(d[name_of_key] for d in data)
|
73 |
+
return items
|