mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add function get_value for FSMContext
This commit is contained in:
parent
a585fb08de
commit
d762195704
2 changed files with 14 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ class FSMContext:
|
|||
async def get_data(self) -> Dict[str, Any]:
|
||||
return await self.storage.get_data(key=self.key)
|
||||
|
||||
async def get_value(self, key: str) -> Any:
|
||||
return await self.storage.get_value(key=self.key, data_key=key)
|
||||
|
||||
async def update_data(
|
||||
self, data: Optional[Dict[str, Any]] = None, **kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
|
|
|
|||
|
|
@ -64,6 +64,17 @@ class BaseStorage(ABC):
|
|||
"""
|
||||
pass
|
||||
|
||||
async def get_value(self, key: StorageKey, data_key: str) -> Any:
|
||||
"""
|
||||
Get selected value by key in current data
|
||||
|
||||
:param key: storage key
|
||||
:param data_key: key of selected data
|
||||
:return: value of current data by key
|
||||
"""
|
||||
current_data = await self.get_data(key=key)
|
||||
return current_data[data_key]
|
||||
|
||||
async def update_data(self, key: StorageKey, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Update date in the storage for key (like dict.update)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue