Add db.Close() examples to documentation

This commit is contained in:
jeff martinez 2016-07-18 14:03:08 -07:00
parent 711e791bb5
commit 915f2c5061
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()
} }
``` ```