Add db.Close() examples to documentation
This commit is contained in:
		
							parent
							
								
									711e791bb5
								
							
						
					
					
						commit
						915f2c5061
					
				@ -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{})
 | 
				
			||||||
 | 
				
			|||||||
@ -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()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user