Set AutoIncrement to false with tag

This commit is contained in:
Jinzhu 2018-02-10 08:24:39 +08:00
parent 97495a5e40
commit 2c68f695c3
3 changed files with 7 additions and 8 deletions

View File

@ -39,13 +39,10 @@ func (commonDialect) Quote(key string) string {
}
func (s *commonDialect) fieldCanAutoIncrement(field *StructField) bool {
// add a new tag "NOT_AUTO_INCREMENT"
_, not := field.TagSettings["NOT_AUTO_INCREMENT"]
if not {
return false
if value, ok := field.TagSettings["AUTO_INCREMENT"]; ok {
return value != "FALSE"
}
_, ok := field.TagSettings["AUTO_INCREMENT"]
return ok || field.IsPrimaryKey
return field.IsPrimaryKey
}
func (s *commonDialect) DataTypeOf(field *StructField) string {

View File

@ -72,8 +72,10 @@ func OpenTestConnection() (db *gorm.DB, err error) {
// db.SetLogger(Logger{log.New(os.Stdout, "\r\n", 0)})
// db.SetLogger(log.New(os.Stdout, "\r\n", 0))
if os.Getenv("DEBUG") == "true" {
if debug := os.Getenv("DEBUG"); debug == "true" {
db.LogMode(true)
} else if debug == "false" {
db.LogMode(false)
}
db.DB().SetMaxIdleConns(10)

View File

@ -1,5 +1,5 @@
dialects=("postgres" "mysql" "mssql" "sqlite")
for dialect in "${dialects[@]}" ; do
GORM_DIALECT=${dialect} go test
DEBUG=false GORM_DIALECT=${dialect} go test
done