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:
John Mick 2017-03-07 11:10:14 +01:00 committed by Jinzhu
parent 572d0a0ab1
commit 66982a7047
1 changed files with 0 additions and 7 deletions

View File

@ -11,14 +11,7 @@ import (
"github.com/jinzhu/gorm" "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() { func init() {
gorm.DefaultCallback.Create().After("gorm:begin_transaction").Register("mssql:set_identity_insert", setIdentityInsert)
gorm.RegisterDialect("mssql", &mssql{}) gorm.RegisterDialect("mssql", &mssql{})
} }