Skip to content

Commit

Permalink
Set transaction isolation level (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
azeemshahzad authored and rkarthik007 committed Aug 10, 2019
1 parent 0949f65 commit cd5302b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion golang/gorm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ go get github.com/lib/pq/hstore
Append source code location to GOPATH environment variable

```
export GOPATH=$GOPATH: /orm-examples/golang/gorm
export GOPATH=$GOPATH:/orm-examples/golang/gorm
```

Create database in YugaByte. Follow the name as specified in configuration.
```
./ysqlsh -c "CREATE DATABASE ysql_gorm"
```

Build and run using shell script:
Expand Down
2 changes: 1 addition & 1 deletion golang/gorm/src/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dbport" : 5433,
"username" : "postgres",
"password" : "",
"dbname" : "gormdemo",
"dbname" : "ysql_gorm",
"sslmode" : "disable",
"bindport" : 8080
}
5 changes: 5 additions & 0 deletions golang/gorm/src/controller/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func init() {
panic(err)
}

err = dbConn.Exec("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE").Error
if err != nil {
panic(err)
}

dbConn.Debug().AutoMigrate(&model.User{}, &model.Product{}, &model.Order{}, &model.OrderLine{})

dbConn.Model(&model.OrderLine{}).AddForeignKey("order_id", "orders(order_id)", "CASCADE", "CASCADE")
Expand Down

0 comments on commit cd5302b

Please sign in to comment.