|
|
@@ -62,6 +62,9 @@ func main() {
|
|
|
className := strutils.SimpleUUID()
|
|
|
studentNum := rand.Int31n(100)
|
|
|
|
|
|
+ newClassName := strutils.SimpleUUID()
|
|
|
+ newStudentNum := rand.Int31n(100)
|
|
|
+
|
|
|
err := sdk.InitInstance(token, baseUrl, namespace, &sdk.DataSourceOption{
|
|
|
Name: dataSource,
|
|
|
Type: sdk.DataSourceTypeDatabase,
|
|
|
@@ -113,6 +116,18 @@ func main() {
|
|
|
panic(err)
|
|
|
}
|
|
|
|
|
|
+ tx := sdk.GetInstance().GetDBOperations().BeginTransaction()
|
|
|
+
|
|
|
+ _, err = tx.
|
|
|
+ Raw("UPDATE test.classes SET name = ?, student_num = ? WHERE id = ?", newClassName, newStudentNum, classID).
|
|
|
+ Rows(0, 0)
|
|
|
+ if err != nil {
|
|
|
+ tx.RollbackTransaction()
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ tx.CommitTransaction()
|
|
|
+
|
|
|
tableRow, err := sdk.GetInstance().GetDBOperations().NewSession().
|
|
|
Table("test.classes").
|
|
|
Where("id = ?", classID).
|
|
|
@@ -121,7 +136,7 @@ func main() {
|
|
|
panic(err)
|
|
|
}
|
|
|
|
|
|
- if tableRow["id"] != classID || tableRow["name"] != className || tableRow["student_num"] != studentNum {
|
|
|
+ if tableRow["id"] != classID || tableRow["name"] != newClassName || tableRow["student_num"] != newStudentNum {
|
|
|
panic("数据查询错误")
|
|
|
}
|
|
|
|