Update GORM Config

This commit is contained in:
Jinzhu 2018-02-13 15:06:14 +08:00
parent a699c1e560
commit 0b616c0525
3 changed files with 36 additions and 53 deletions

View File

@ -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
}

39
gorm.go
View File

@ -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

19
main.go
View File

@ -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"