added basic save, update, load and delate methods

This commit is contained in:
collerek
2020-08-03 19:59:04 +02:00
parent d7355b8c9b
commit e0bb7e2cda
10 changed files with 316 additions and 106 deletions

27
orm/helpers.py Normal file
View File

@ -0,0 +1,27 @@
from typing import Union, Set, Dict # pragma no cover
class Excludable: # pragma no cover
@staticmethod
def get_excluded(exclude: Union[Set, Dict, None], key: str = None):
# print(f'checking excluded for {key}', exclude)
if isinstance(exclude, dict):
if isinstance(exclude.get(key, {}), dict) and '__all__' in exclude.get(key, {}).keys():
return exclude.get(key).get('__all__')
return exclude.get(key, {})
return exclude
@staticmethod
def is_excluded(exclude: Union[Set, Dict, None], key: str = None):
if exclude is None:
return False
to_exclude = Excludable.get_excluded(exclude, key)
# print(f'to exclude for current key = {key}', to_exclude)
if isinstance(to_exclude, Set):
return key in to_exclude
elif to_exclude is ...:
return True
else:
return False