From 1b4c05690094392c1cbbdf28b401018502996c77 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 10 Oct 2017 22:46:41 +0800 Subject: [PATCH] Add GORM Config --- gorm.go | 16 ++++++++++++++++ main.go | 18 ------------------ 2 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 gorm.go diff --git a/gorm.go b/gorm.go new file mode 100644 index 00000000..8ddf6e92 --- /dev/null +++ b/gorm.go @@ -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 +} diff --git a/main.go b/main.go index 16fa0b79..138e1a12 100644 --- a/main.go +++ b/main.go @@ -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()