I\'ve got a class:
class Tag(Base, TimestampMixin): \"\"\"Tags\"\"\" __tablename__ = \'tags\' __table_args__ = {\'mysql_engine\' : \'InnoDB\', \'
You can try this
def get_or_increase_tag(tag_name): tag = session.query(Tag).filter_by(tag=tag_name).first() if not tag: tag = Tag(tag_name) else: tag.cnt += 1 return tag
You can check the link https://stackoverflow.com/search?q=Insert+on+duplicate+update+sqlalchemy