多表事务


  1. session := torm.GetDbInstance("default", "writer").GetSession()
  2. defer session.Close()
  3. session.Begin()
  4. dao := NewDbtestDao(session)
  5. param := torm.CastToParamIn([]int{1})
  6. data, err := dao.Get(param)
  7. row := data[0]
  8. row.Param1 = 100
  9. row.Param2 = "update1"
  10. dao.Update(&row)
  11. daoAnother := NewDbtestAnotherDao(session)
  12. param = torm.CastToParamIn([]int{2})
  13. data, err = daoAnother.Get(param)
  14. row = data[0]
  15. daoAnother.Delete(&row)
  16. e := session.Commit()
  17. if e != nil {
  18. session.Rollback()
  19. }
  • 多表事务,需在同一实例上