diff --git a/golang/gorm/README.md b/golang/gorm/README.md index 87acfdc..b460c9f 100644 --- a/golang/gorm/README.md +++ b/golang/gorm/README.md @@ -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: diff --git a/golang/gorm/src/config/config.json b/golang/gorm/src/config/config.json index efe3531..2b491a1 100644 --- a/golang/gorm/src/config/config.json +++ b/golang/gorm/src/config/config.json @@ -4,7 +4,7 @@ "dbport" : 5433, "username" : "postgres", "password" : "", - "dbname" : "gormdemo", + "dbname" : "ysql_gorm", "sslmode" : "disable", "bindport" : 8080 } diff --git a/golang/gorm/src/controller/base.go b/golang/gorm/src/controller/base.go index f4c73c3..7b71cda 100644 --- a/golang/gorm/src/controller/base.go +++ b/golang/gorm/src/controller/base.go @@ -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")