Пример #1
0
        def handle(*arguments, **kw):
            if len(arguments) > 1 and arguments[1]:
                if isinstance(arguments[1], (DuplicateKeyError, )):
                    raise UniqueKeyViolationError.from_pymongo(str(arguments[1]), self.__klass__)
                else:
                    raise arguments[1]

            callback(document)
Пример #2
0
    async def save_document(self, document, alias=None):
        doc = document.to_son()

        if document._id is not None:
            try:
                await self.coll(alias).update({'_id': document._id}, doc)
            except DuplicateKeyError as e:
                raise UniqueKeyViolationError.from_pymongo(
                    str(e), self.__klass__)
        else:
            try:
                doc_id = await self.coll(alias).insert(doc)
            except DuplicateKeyError as e:
                raise UniqueKeyViolationError.from_pymongo(
                    str(e), self.__klass__)
            document._id = doc_id
        return document
Пример #3
0
        def handle(*arguments, **kw):
            if len(arguments) > 1 and arguments[1]:
                if isinstance(arguments[1], (DuplicateKeyError, )):
                    raise UniqueKeyViolationError.from_pymongo(str(arguments[1]), self.__klass__)
                else:
                    raise arguments[1]

            document._id = arguments[0]
            callback(document)