-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtx_test.go
47 lines (46 loc) · 915 Bytes
/
tx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package f_test
import (
f "github.com/og/gofree"
grand "github.com/og/x/rand"
"testing"
)
func TestTx(t *testing.T) {
db := f.NewDatabase(f.DataSourceName{
DriverName: "mysql",
User: "root",
Password: "somepass",
Host: "localhost",
Port: "3306",
DB: "test_gofree",
})
tx := db.Tx() ; defer func() { tx.End( recover()) }()
{
user := User{}
has := false
db.TxOneID(tx, &user, &has, "1")
user.Name = grand.StringLetter(4)
db.TxUpdate(tx, &user)
{
readUser := User{}
has := false
db.OneID(&readUser, &has, "1")
}
}
{
user := User{
ID :"10",
}
has := false
_, err := db.Core.Exec(`delete from ` + user.TableName() + " where id= ?", "10")
if err != nil {
panic(err)
}
db.Create(&user)
db.TxOneID(tx, &user, &has, "10")
user.Name = grand.StringLetter(1)
db.TxUpdate(tx, &user)
}
// if (some) {
// tx.Rollback()
// }
}