mysql.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. from ZlwlAlgosCommon.utils.ProUtils import *
  2. from ZlwlAlgosCommon.service.iotp.IotpAlgoService import IotpAlgoService
  3. cur_env = 'dev' # 设置运行环境
  4. app_path = "/home/wangliming/project/zlwl-algos" # 设置相对路径
  5. app_name = "schedule" # 应用名, 建议与topic的后缀相同
  6. sysUtils = SysUtils(cur_env, app_path)
  7. mysqlUtils = MysqlUtils()
  8. mysql_params = sysUtils.get_cf_param('mysql-algo')
  9. mysql_engine, mysql_Session= mysqlUtils.get_mysql_engine(mysql_params)
  10. mysql_conn = mysql_engine.connect()
  11. # with mysql_Session() as session:
  12. # session.add(Test2(id=12, field1=10))
  13. # session.commit()
  14. # 删除
  15. # with mysql_Session() as session:
  16. # session.execute(delete(Test2).where(or_((Test2.id == 10), (Test2.id == 12))))
  17. # session.commit()
  18. # 修改
  19. # with mysql_Session() as session:
  20. # session.execute(update(Test2).where(and_((Test2.id == 12), (Test2.field1 == 10))).values(id=15))
  21. # session.commit()
  22. # # upsert
  23. # insert_data = insert(Test2).valuess()
  24. # with mysql_Session() as session:
  25. # session.execute(update(Test2).where(and_((Test2.id == 12), (Test2.field1 == 10))).values(id=15))
  26. # session.commit()