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