Hi,

I have been looking at the group archive and googling around a bit,
but it seems like if I want to do insert to table if row doesn't
exist, otherwise update a field in the row is not really possible.  I
end up doing something like below.

    def _add_index(self, src_id, tar_id):

        row = self.session.query(Index).filter(Index.src_id==src_id).\
                filter(Index.tar_id==tar_id).first()

        if row:
            row.new += 1
            row.total += 1
        else:
            row = Index(src_id, tar_id, 1, 1, 0)

        self.session.add(row)
        self.session.commit()

        return

This doesn't look very efficient, is there a better way to do this?  I
have been looking at merge(), but that looks like it is for merging
uncommitted transactions in the session before committing to the db.
Is this correct?

TIA,
Mason

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to