Add function get_value for FSMContext

This commit is contained in:
wrrrzr 2024-03-03 00:28:10 +03:00
parent a585fb08de
commit d762195704
2 changed files with 14 additions and 0 deletions

View file

@ -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]:

View file

@ -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)