Add GORM Config

This commit is contained in:
Jinzhu 2017-10-10 22:46:41 +08:00
parent 0a51f6cdc5
commit 1b4c056900
2 changed files with 16 additions and 18 deletions

16
gorm.go Normal file
View File

@ -0,0 +1,16 @@
package gorm
import "github.com/jinzhu/gorm/logger"
// Config GORM config
type Config struct {
// SingularTable use singular table name, by default, GORM will pluralize your struct's name as table name
// Refer https://github.com/jinzhu/inflection for inflection rules
SingularTable bool
// BlockGlobalUpdate generates an error on update/delete without where clause, this is to prevent eventual error with empty objects updates/deletions
BlockGlobalUpdate bool
Logger logger.Interface
LogMode logger.LogMode
}

18
main.go
View File

@ -143,24 +143,6 @@ func (s *DB) LogMode(enable bool) *DB {
return s
}
// BlockGlobalUpdate if true, generates an error on update/delete without where clause.
// This is to prevent eventual error with empty objects updates/deletions
func (s *DB) BlockGlobalUpdate(enable bool) *DB {
s.blockGlobalUpdate = enable
return s
}
// HasBlockGlobalUpdate return state of block
func (s *DB) HasBlockGlobalUpdate() bool {
return s.blockGlobalUpdate
}
// SingularTable use singular table by default
func (s *DB) SingularTable(enable bool) {
modelStructsMap = newModelStructsMap()
s.parent.singularTable = enable
}
// NewScope create a scope for current operation
func (s *DB) NewScope(value interface{}) *Scope {
dbClone := s.clone()