Exemplo n.º 1
0
 def to_internal(cls, key, pointer, *args, **kwargs):
     """
     :param key: document key,
     :param pointer: coltrane.appstorage.datatypes.Pointer
     :return: internal view of Pointer
     :rtype: :class:`DbRef`
     """
     bucket = pointer.bucket
     document_key = pointer.key
     id = _internal_id(*args, bucket=bucket, deleted=0, document_key=document_key)
     return key, DBRef(bucket, id)
Exemplo n.º 2
0
    def get(self, app_id, user_id, bucket, key):
        """ Read operation for CRUD service.
         Parameters:
         app_id: String, application id
         user_id: String, user id
         document_key: String, document key
         bucket: String, type of document

         Returns founded document or None if object not found """

        # validations
        if key is None:
            raise InvalidDocumentKeyError('Document key must be not null')

        # logic
        document_id = _internal_id(app_id, user_id, bucket, 0, key)
        res = self.entities.find_one({intf.ID: document_id, intf.DELETED: False})
        if res is None:
            return None

        return _to_external(res)
Exemplo n.º 3
0
 def _from_dict(doc):
     """
         Gets document as a parameter of dict type.
         Runs through top level keys. If object by key is dict
         type then invokes _from_doc recursively. If object by
         key is list then invokes _from_list.
     """
     internal = {}
     for key in doc:
         val = doc[key]
         if key == extf.KEY:
             document_key = val
             document_id = _internal_id(app_id, user_id, bucket, 0, document_key)
             internal[intf.ID] = document_id
         else:
             if type(val) == dict:
                 val = _from_dict(val)
             elif type(val) == list:
                 val = _from_list(val)
             elif isinstance(val, BaseType):
                 key, val = _convert_custom_type(key, val)
             internal[key] = val
     return internal