Remove SET_IDENTITY_INSERT for transactions in MS SQL
SET_IDENTITY_INSERT should be handled by each individual developer to avoid extra queries to the database.
This commit is contained in:
		
							parent
							
								
									5409931a1b
								
							
						
					
					
						commit
						ed02d1ba03
					
				@ -12,14 +12,7 @@ import (
 | 
			
		||||
	"github.com/jinzhu/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func setIdentityInsert(scope *gorm.Scope) {
 | 
			
		||||
	if scope.Dialect().GetName() == "mssql" {
 | 
			
		||||
		scope.NewDB().Exec(fmt.Sprintf("SET IDENTITY_INSERT %v ON", scope.TableName()))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	gorm.DefaultCallback.Create().After("gorm:begin_transaction").Register("mssql:set_identity_insert", setIdentityInsert)
 | 
			
		||||
	gorm.RegisterDialect("mssql", &mssql{})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user