sqlalchemy更新和插入操作


    def save_app_info(self):
        try:
            # update app_info
            print(self.dicts)
            data = db_session.query(App_Info).filter_by(app_id=self.app_id,mall_name=self.mall_name).first()
            if data:   
                {setattr(data, k, v) for k,v in dicts.items()}
                print(data)
            else:
                # insert app_info
                db_session.execute(App_Info.__table__.insert(), self.dicts)
            db_session.commit()
        except:
            db_session.rollback()
            other.error("save app_data is error,here are details:{}".format(traceback.format_exc()))
        finally:
            db_session.close()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM