DynamoDB Repository
Repository
Manages all DynamoDB interactions for a single table.
Source code in templates/repository.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
__init__(table_name)
Initialize the repository with a DynamoDB table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
The name of the DynamoDB table to operate on. |
required |
Source code in templates/repository.py
7 8 9 10 11 12 13 | |
delete_item(keys)
Delete an item from the table by its primary key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
object
|
A mapping of key attribute names to their values. |
required |
Source code in templates/repository.py
42 43 44 45 46 47 48 | |
get_item(item_id)
Retrieve an item by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str
|
The unique identifier of the item to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
The item as a dictionary, or |
Source code in templates/repository.py
15 16 17 18 19 20 21 22 23 24 | |
list_items()
Retrieve all items from the table.
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of all items in the table. |
Source code in templates/repository.py
26 27 28 29 30 31 32 | |
put_item(item)
Write an item to the table, replacing any existing item with the same key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
dict
|
A dictionary representing the item to store. |
required |
Source code in templates/repository.py
34 35 36 37 38 39 40 | |