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

Small documentation update #3677

Closed
petrjahoda opened this issue Oct 24, 2020 · 1 comment
Closed

Small documentation update #3677

petrjahoda opened this issue Oct 24, 2020 · 1 comment
Assignees
Labels
type:feature_request feature request

Comments

@petrjahoda
Copy link

petrjahoda commented Oct 24, 2020

Describe the feature

When opening connection to a database a new goroutine is created. That is OK, if only one connection (or few) is used through the program. But in case the program has to be made a way, that a new connection is made on demand, the problem arise.
With every new connection a new goroutine is created and another 8Kb of memory is consumed.

Because of that, maybe this information can be added to https://gorm.io/docs/connecting_to_the_database.html

The obvious solution for those cases is simple:

Original

dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
   handleError()
}

New:

dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
sqlDB, _ := db.DB()
defer sqlDB.Close()
if err != nil {
   handleError()
}
@jinzhu
Copy link
Member

jinzhu commented Oct 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature_request feature request
Projects
None yet
Development

No branches or pull requests

2 participants