How to use the fireo.utils.utils function in fireo

To help you get started, we’ve selected a few fireo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github octabytes / FireO / src / fireo / models / model.py View on Github external
Firestore transaction

        batch:
            Firestore batch writes
        """

        # Check doc key is given or not
        if key:
            self._update_doc = key

        # make sure update doc in not None
        if self._update_doc is not None and '@temp_doc_id' not in self._update_doc:
            # set parent doc from this updated document key
            self.parent = utils.get_parent_doc(self._update_doc)
            # Get id from key and set it for model
            setattr(self, '_id', utils.get_id(self._update_doc))
            # Add the temp id field if user is not specified any
            if self._id is None and self.id:
                setattr(self._meta, 'id', ('id', fields.IDField()))
        elif self._update_doc is None and '@temp_doc_id' in self.key:
            raise InvalidKey(f'Invalid key to update model "{self.__class__.__name__}" ')

        # Get the updated fields
        updated_fields = {}
        for k, v in self._get_fields().items():
            if k in self._field_changed:
                updated_fields[k] = v
            # Get nested fields if any
            # Nested model store as dict in firestore so check values type is dict
            if type(v) is dict:
                # nested field name and value
                for name, value in v.items():
github octabytes / FireO / src / fireo / models / model_meta.py View on Github external
def __init__(self):
                # Convert Model class into collection name
                # change it to lower case and snake case
                # e.g UserCollection into user_collection
                self.collection_name = utils.collection_name(cls.__name__)
                self.abstract = False
                self.missing_field = 'merge'
                self.to_lowercase = False
                self._referenceDoc = None
                self._firestore_create_time = None
                self._firestore_update_time = None
github octabytes / FireO / src / fireo / queries / base_query.py View on Github external
def set_collection_path(self, path=None, key=None):
        """Set collection path"""
        # Check collection path is given if not then get it from model key
        if path:
            self.collection_path = path + '/' + self.model_cls.collection_name
        elif key:
            self.collection_path = utils.collection_path(key)