def update(self, text): with transaction.manager: try: d = self.session.query(Description).filter_by(text=text).one() except NoResultFound: d = Description() d.text = text self.session.add(d) d = self.session.merge(d) return d
def new(self, text): with transaction.manager: d = Description() d.text = text self.session.add(d) return self.session.merge(d)