From 0b616c0525eb2f9bc310dc6ff23f854fa12bb394 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 13 Feb 2018 15:06:14 +0800 Subject: [PATCH] Update GORM Config --- config.go | 31 ------------------------------- gorm.go | 39 ++++++++++++++++++++++++++++++++++++--- main.go | 19 ------------------- 3 files changed, 36 insertions(+), 53 deletions(-) delete mode 100644 config.go diff --git a/config.go b/config.go deleted file mode 100644 index dba6ad94..00000000 --- a/config.go +++ /dev/null @@ -1,31 +0,0 @@ -package gorm - -import "github.com/jinzhu/gorm/logger" - -// Config GORM config -type Config struct { - // MaxIdleConnections sets the maximum number of connections in the idle connection pool - MaxIdleConnections int - // MaxOpenConnections sets the maximum number of open connections to the database - MaxOpenConnections int - - // 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 logger.Interface - LogMode logger.LogLevel - - // Dialect DB Dialect - Dialect Dialect - - // Callbacks defined GORM callbacks - Callbacks *Callback - - // db fresh db connection - globalDbConnection SQLCommon -} diff --git a/gorm.go b/gorm.go index b040a891..d51e679b 100644 --- a/gorm.go +++ b/gorm.go @@ -1,13 +1,46 @@ package gorm +import "github.com/jinzhu/gorm/logger" + +// Config GORM config +type Config struct { + // MaxIdleConnections sets the maximum number of connections in the idle connection pool + MaxIdleConnections int + // MaxOpenConnections sets the maximum number of open connections to the database + MaxOpenConnections int + + // 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 + + // Dialect DB Dialect + Dialect Dialect + + // Callbacks defined GORM callbacks + Callbacks *Callback + + // Logger + Logger logger.Interface + LogMode logger.LogLevel + + // db fresh db connection + globalDB SQLCommon +} + // DB contains information for current db connection type DB struct { - // Current operation - Value interface{} // Value current operation data - db SQLCommon + // current instance + Value interface{} + tx SQLCommon search *search values map[string]interface{} + // Global config + config *Config + // Result result fields Error error RowsAffected int64 diff --git a/main.go b/main.go index a38d0afb..0f853d1c 100644 --- a/main.go +++ b/main.go @@ -9,25 +9,6 @@ import ( "time" ) -// DB contains information for current db connection -type DB struct { - Value interface{} - Error error - RowsAffected int64 - - // single db - db SQLCommon - blockGlobalUpdate bool - search *search - values map[string]interface{} - - // global db - parent *DB - callbacks *Callback - dialect Dialect - singularTable bool -} - // Open initialize a new db connection, need to import driver first, e.g: // // import _ "github.com/go-sql-driver/mysql"