diff --git a/dialect/mysql.go b/dialect/mysql.go index 151c1076..a1c0a26e 100644 --- a/dialect/mysql.go +++ b/dialect/mysql.go @@ -19,7 +19,7 @@ func (s *mysql) SupportLastInsertId() bool { func (d *mysql) SqlTag(column interface{}, size int) string { switch column.(type) { case time.Time: - return "timestamp" + return "datetime" case bool, sql.NullBool: return "boolean" case int, int8, int16, int32, uint, uint8, uint16, uint32: diff --git a/gorm_test.go b/gorm_test.go index e6e638af..ab257f6f 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -8,6 +8,7 @@ import ( _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" + "os" "reflect" "strconv" "testing" @@ -84,13 +85,20 @@ var ( func init() { var err error - - db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable") - // CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm'; - // CREATE DATABASE 'gorm'; - // GRANT ALL ON gorm.* TO 'gorm'@'localhost'; - // db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True") - // db, err = Open("sqlite3", "/tmp/gorm.db") + switch os.Getenv("GORM_DIALECT") { + case "mysql": + // CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm'; + // CREATE DATABASE 'gorm'; + // GRANT ALL ON gorm.* TO 'gorm'@'localhost'; + fmt.Println("testing mysql...") + db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True") + case "sqlite": + fmt.Println("testing sqlite3...") + db, err = Open("sqlite3", "/tmp/gorm.db") + default: + fmt.Println("testing postgres...") + db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable") + } // db.SetLogger(log.New(os.Stdout, "\r\n", 0)) // db.LogMode(true) diff --git a/test_all.sh b/test_all.sh new file mode 100755 index 00000000..6c5593b3 --- /dev/null +++ b/test_all.sh @@ -0,0 +1,5 @@ +dialects=("postgres" "mysql" "sqlite") + +for dialect in "${dialects[@]}" ; do + GORM_DIALECT=${dialect} go test +done