Merge pull request #1122 from jeffbmartinez/gh-pages-add-close

Add db.Close() examples to documentation
This commit is contained in:
Jinzhu 2016-07-20 08:36:16 +09:00 committed by GitHub
commit ba70f12ea6
2 changed files with 4 additions and 0 deletions

View File

@ -52,6 +52,7 @@ func main() {
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect database")
} }
defer db.Close()
// Migrate the schema // Migrate the schema
db.AutoMigrate(&Product{}) db.AutoMigrate(&Product{})

View File

@ -31,6 +31,7 @@ import (
func main() { func main() {
db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local") db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
defer db.Close()
} }
``` ```
@ -44,6 +45,7 @@ import (
func main() { func main() {
db, err := gorm.Open("postgres", "host=myhost user=gorm dbname=gorm sslmode=disable password=mypassword") db, err := gorm.Open("postgres", "host=myhost user=gorm dbname=gorm sslmode=disable password=mypassword")
defer db.Close()
} }
``` ```
@ -57,6 +59,7 @@ import (
func main() { func main() {
db, err := gorm.Open("sqlite3", "/tmp/gorm.db") db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
defer db.Close()
} }
``` ```