Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set transaction isolation level #50

Merged
merged 1 commit into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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