Ejemplo n.º 1
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))
Ejemplo n.º 2
0
    def save(self, safe=True, callback=None):
        """Save a document

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

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)

        message_insert = message.insert(collection_name, [self.as_dict()],
            True, safe, {})

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

        post_save.send(instance=self)

        if callback:
            callback((response, error))
Ejemplo n.º 3
0
    def remove(self, safe=True, callback=None):
        """Remove a document

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

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)

        message_delete = message.delete(collection_name, {'_id': self._id},
            safe, {})

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

        post_remove.send(instance=self)

        if callback:
            callback((response, error))