macry
Advanced tools
| """Python object-document mapper (ODM) for google FireStore""" | ||
| __version__ = '0.0.2' | ||
| __version__ = '0.0.3' | ||
| from . import fields | ||
| from .builder import FireModel |
+3
-2
| from .connects import FireStore | ||
| from .fields import FireMap, FireArray | ||
| from .fields import FireMap, FireArray, Field | ||
| import weakref | ||
| class FireModel(FireStore): | ||
| class FireModel(FireStore, Field): | ||
| __type_name__ = 'BaseModel' | ||
@@ -8,0 +9,0 @@ def __init__(self, *args, **kwargs): |
@@ -89,2 +89,3 @@ from google.cloud import firestore | ||
| for key in self.items: | ||
| # logger.info(('update', key, self.items[key].update_stack)) | ||
| if self.items[key].update_stack: | ||
@@ -91,0 +92,0 @@ db = self.collection.document(key) |
+37
-8
@@ -30,9 +30,9 @@ from datetime import datetime | ||
| value = self.default | ||
| instance.__dict__[self.prop_name] = value | ||
| # -------------------------------------------------------- | ||
| if hasattr(instance, '__path__'): | ||
| instance.__path__["root"]().update_stack.setdefault( | ||
| f'{instance.__path__["path"]}.{self.prop_name}', value | ||
| ) | ||
| # -------------------------------------------------------- | ||
| # Compare for same values and assign to it. | ||
| compare_to = self if instance is None else instance.__dict__.get( | ||
| self.prop_name, None) | ||
| if compare_to != value: | ||
| instance.__dict__[self.prop_name] = value | ||
| self.register_update(instance, value) | ||
| else: | ||
@@ -54,3 +54,29 @@ if hasattr(self, 'entity') and self.entity: | ||
| def register_update(self, instance, value): | ||
| if hasattr(instance, '__path__'): | ||
| if hasattr(value, '__type_name__') and \ | ||
| value.__type_name__ == 'BaseModel': | ||
| update_value = value.to_dict() | ||
| instance.__dict__[self.prop_name].route_paths( | ||
| instance.__path__["root"], | ||
| ) | ||
| instance.__dict__[self.prop_name].__object_added__ = True | ||
| instance.__path__["root"]().update_stack[ | ||
| f'{instance.__path__["path"]}.{self.prop_name}' | ||
| ] = update_value | ||
| else: | ||
| update_value = value | ||
| if instance.__dict__.get('__object_added__', False): | ||
| instance.__path__["root"]().update_stack[ | ||
| instance.__path__["path"]][self.prop_name] = \ | ||
| update_value | ||
| else: | ||
| instance.__path__["root"]().update_stack[ | ||
| f'{instance.__path__["path"]}.{self.prop_name}' | ||
| ] = update_value | ||
| # logger.info(f'Set Update stack ' | ||
| # f'{instance.__path__["path"]}.{self.prop_name},' + \ | ||
| # f' Val: {value}, Object: {instance.__path__["root"]()}' | ||
| class FireObject(Field): | ||
@@ -147,4 +173,7 @@ def __init__(self, default=None, required=False): | ||
| required=False, | ||
| key=None): | ||
| key=None, | ||
| collection=None): | ||
| super().__init__() | ||
| if collection: | ||
| self.extend(collection) | ||
| self._type = 'array' | ||
@@ -151,0 +180,0 @@ self.default = default |
+8
-1
| Metadata-Version: 2.1 | ||
| Name: macry | ||
| Version: 0.0.2 | ||
| Version: 0.0.3 | ||
| Summary: Python object-document mapper (ODM) for google FireStore | ||
@@ -22,1 +22,8 @@ Author-email: Irakli Sivsivadze <iraklisivsivadze@gmail.com> | ||
| ## Development | ||
| Install all dependencies from a top project directory for the development environment with: | ||
| ```bash | ||
| pip install . | ||
| ``` | ||
+7
-0
@@ -8,1 +8,8 @@ # macry | ||
| ``` | ||
| ## Development | ||
| Install all dependencies from a top project directory for the development environment with: | ||
| ```bash | ||
| pip install . | ||
| ``` |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
19616
9.52%362
8.71%