Exemple #1
0
    def update(self, document=None, upsert=False, safe=True, multi=False,
        callback=None, force=False):
        """Update a document

        :Parameters:
        - `safe` (optional): safe update operation
        - `callback` : method which will be called when update is finished
        - `force`: if True will overide full document
        """
        if not document and not self.dirty_fields:
            callback(tuple())
            return

        pre_update.send(instance=self)

        if not document:
            if force:
                document = self.as_dict()
            else:
                document = {"$set": self.as_dict(self.dirty_fields)}

        client = Client(Database(), self.__collection__)
        spec = {'_id': self._id}

        response, error = yield gen.Task(client.update, spec, document,
            upsert=upsert, safe=safe, multi=multi)

        self.clean_fields()

        post_update.send(instance=self)

        if callback:
            callback((response, error))
Exemple #2
0
    def update(self, document=None, safe=True, callback=None):
        """Update a document

        :Parameters:
        - `safe` (optional): safe update operation
        - `callback` : method which will be called when update is finished
        """
        pre_update.send(instance=self)

        if not document:
            document = self.as_dict()

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)
        spec = {'_id': self._id}

        message_update = message.update(collection_name, False,
                False, spec, document, safe, {})

        response, error = yield gen.Task(database.send_message, message_update)

        post_update.send(instance=self)

        if callback:
            callback((response, error))
Exemple #3
0
    def update(self,
               document=None,
               upsert=False,
               safe=True,
               multi=False,
               callback=None,
               force=False):
        """Update a document

        :Parameters:
        - `safe` (optional): safe update operation
        - `callback` : method which will be called when update is finished
        - `force`: if True will overide full document
        """
        if not document and not self.dirty_fields:
            callback(tuple())
            return

        pre_update.send(instance=self)

        if not document:
            if force:
                document = self.as_dict()
            else:
                document = {"$set": self.as_dict(self.dirty_fields)}

        client = Client(Database(), self.__collection__)
        spec = {'_id': self._id}

        response, error = yield gen.Task(client.update,
                                         spec,
                                         document,
                                         upsert=upsert,
                                         safe=safe,
                                         multi=multi)

        self.clean_fields()

        post_update.send(instance=self)

        if callback:
            callback((response, error))
Exemple #4
0
    def update(self, document=None, upsert=False, safe=True, multi=False,
        callback=None):
        """Update a document

        :Parameters:
        - `safe` (optional): safe update operation
        - `callback` : method which will be called when update is finished
        """
        pre_update.send(instance=self)

        if not document:
            document = self.as_dict()

        client = Client(Database(), self.__collection__)
        spec = {'_id': self._id}

        response, error = yield gen.Task(client.update, spec, document,
            upsert=upsert, safe=safe, multi=multi)

        post_update.send(instance=self)

        if callback:
            callback((response, error))