Skip to content

事务

要在事务中执行一系列操作,一般流程如下:

ts
this.db.Begin();
// 执行一系列数据库操作
let ref = new User("", 0, 0);
this.db.Table("User").Where('id', 1).First(ref);
if(this.db.GetError()) {
    this.db.Rollback(); // 发生异常时回滚
} else {
    ref.Name = "ZhangSan";
    this.db.Save(ref);
    if(this.db.GetError()) {
        this.db.Rollback(); // 发生异常时回滚
    } else {
        this.db.Commit();  // 没有发生异常时提交
    }
}