示例#1
0
文件: database.py 项目: nndii/yadm
    def update_one(self,
                   document,
                   *,
                   reload=True,
                   set=None,
                   unset=None,
                   inc=None,
                   push=None,
                   pull=None,
                   **collection_params):  # TODO: extend
        """ Update one document.
        """
        update_data = build_update_query(set=set,
                                         unset=unset,
                                         inc=inc,
                                         push=push,
                                         pull=pull)

        if update_data:
            collection = self._get_collection(document, collection_params)
            result = collection.update_one(
                {'_id': document.id},
                update_data,
                upsert=False,
            )
            document.__log__.append(UpdateOne(update_data=update_data))
        else:
            result = None

        if reload:
            self.reload(document, **collection_params)

        return result
示例#2
0
文件: database.py 项目: vlad-ki/yadm
    def update_one(self,
                   document,
                   reload=True,
                   *,
                   set=None,
                   unset=None,
                   inc=None,
                   push=None,
                   pull=None):  # TODO: extend
        """ Update one document.

        :param Document document: document instance for update
        :param bool reload: if True, reload document
        """
        update_data = build_update_query(set=set,
                                         unset=unset,
                                         inc=inc,
                                         push=push,
                                         pull=pull)

        if update_data:
            self._get_collection(document).update(
                {'_id': document.id},
                update_data,
                upsert=False,
                multi=False,
            )

        if reload:
            self.reload(document)
示例#3
0
    def update(self, *, set=None, unset=None, inc=None, push=None, pull=None):
        """ Updale documents finded in query.
        """
        update_query = build_update_query(set=set,
                                          unset=unset,
                                          inc=inc,
                                          push=push,
                                          pull=pull)

        if self._upsert:
            self._bulk_mongo.find(self._query).upsert().update(update_query)
        else:
            self._bulk_mongo.find(self._query).update(update_query)
示例#4
0
文件: database.py 项目: zzzsochi/yadm
    async def update_one(self, document, *, reload=True,
                         set=None, unset=None, inc=None,
                         push=None, pull=None,
                         **collection_params):  # TODO: extend
        update_data = build_update_query(set=set, unset=unset, inc=inc,
                                         push=push, pull=pull)

        if update_data:
            collection = self._get_collection(document, collection_params)
            result = await collection.update_one(
                {'_id': document.id},
                update_data,
                upsert=False,
            )
            document.__log__.append(UpdateOne(update_data=update_data))
        else:
            result = None

        if reload:
            await self.reload(document, **collection_params)

        return result