diff --git a/.idea/hotime.iml b/.idea/hotime.iml index c2f07d0..86d29cd 100644 --- a/.idea/hotime.iml +++ b/.idea/hotime.iml @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/.idea/libraries/GOPATH__hotime_.xml b/.idea/libraries/GOPATH__hotime_.xml index 55a4127..05b5382 100644 --- a/.idea/libraries/GOPATH__hotime_.xml +++ b/.idea/libraries/GOPATH__hotime_.xml @@ -1,14 +1,14 @@ - - + + - - + + diff --git a/.idea/misc.xml b/.idea/misc.xml index ce2eb0a..d4559d4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,13 +1,6 @@ - - - + + + - - - - - - - + + + + + + + + - - - - - - - - - - - - - - + - @@ -55,7 +46,17 @@ - + + + + + + + + + + + @@ -65,17 +66,27 @@ - + - + + + + + + + + + + + - - + + @@ -85,7 +96,17 @@ - + + + + + + + + + + + @@ -95,7 +116,7 @@ - + @@ -105,29 +126,7 @@ - - - - - - - - - - - - - - - - - - - - - - - + @@ -170,17 +169,17 @@ @@ -195,11 +194,21 @@ - + + + + + + + + + + @@ -216,7 +225,6 @@ - @@ -224,24 +232,6 @@ - - - - - - - @@ -269,6 +259,7 @@ + @@ -312,10 +303,6 @@ - - - - @@ -340,25 +327,9 @@ - - - - - - - - - - - - - - - - @@ -370,10 +341,6 @@ - - - - project @@ -384,25 +351,12 @@ - + - - project - - - true - - - - DIRECTORY - - false - - @@ -416,23 +370,23 @@ - C:\Users\彭\AppData\Roaming\Subversion + C:\Users\92597\AppData\Roaming\Subversion 125 @@ -463,6 +417,7 @@ + 1500458878821 @@ -594,7 +549,7 @@ - @@ -606,15 +561,15 @@ - + - + - + @@ -653,14 +608,14 @@ - + - + @@ -668,38 +623,36 @@ - + - + - - - - + + - + - + @@ -707,7 +660,7 @@ - + @@ -715,38 +668,36 @@ - + - + - - - - + + - + - + @@ -754,14 +705,14 @@ - + - + @@ -769,38 +720,36 @@ - + - - - - + + - + - + - + @@ -808,7 +757,7 @@ - + @@ -816,31 +765,29 @@ - + - + - - - - + + - + @@ -851,14 +798,14 @@ - + - + @@ -866,7 +813,7 @@ - + @@ -874,87 +821,50 @@ - - - - + + - - + - - - - - - - - - - - - - - - - - - - - + - - - - + - - + - - - - - - - - - - - - + - + @@ -964,7 +874,7 @@ - + @@ -972,18 +882,15 @@ - - - - - + + - + @@ -991,7 +898,7 @@ - + @@ -999,7 +906,7 @@ - + @@ -1007,10 +914,9 @@ - + - @@ -1018,7 +924,7 @@ - + @@ -1026,15 +932,39 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db.go b/db.go index ad2db16..f8e4445 100644 --- a/db.go +++ b/db.go @@ -30,24 +30,22 @@ func (this *HoTimeDB) SetConnect(connect func(err ...*Error) *sql.DB, err ...*Er } //事务,如果action返回true则执行成功;false则回滚 -func (this *HoTimeDB) Action(action func() bool) bool { +func (this *HoTimeDB) Action(action func(db HoTimeDB) bool) bool { tx, err := this.DB.Begin() if err != nil { this.LastErr.SetError(err) return false } - this.Tx = tx - result := action() + db:=HoTimeDB{DB:this.DB,Tx:tx,Cached:this.Cached} + + result := action(db) if !result { - this.Tx.Rollback() - this.Tx = nil + db.Tx.Rollback() return result } - - this.Tx.Commit() - this.Tx = nil + db.Tx.Commit() return result } diff --git a/example/main.go b/example/main.go index 9344ca6..521ca87 100644 --- a/example/main.go +++ b/example/main.go @@ -50,9 +50,9 @@ func main() { "index": hotime.Ctr{ "test": func(this *hotime.Context) { fmt.Println(this.Db.GetTag()) - x:=this.Db.Action(func() bool { + x:=this.Db.Action(func(db hotime.HoTimeDB) bool { - this.Db.Insert("user",hotime.Map{"unickname":"dasdas"}) + db.Insert("user",hotime.Map{"unickname":"dasdas"}) return false })