From bc4c9cfa3b9a88b74d6555f56386f1797b493b59 Mon Sep 17 00:00:00 2001 From: generalworksinc Date: Thu, 1 Jul 2021 00:42:01 +0900 Subject: [PATCH] adapt Timestamp/DateTime milisecond for MySQL/Postgres --- dialects/time.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dialects/time.go b/dialects/time.go index 5aee0c10..64f6206d 100644 --- a/dialects/time.go +++ b/dialects/time.go @@ -18,8 +18,13 @@ func FormatTime(dialect Dialect, sqlTypeName string, t time.Time) (v interface{} v = s[11:19] case schemas.Date: v = t.Format("2006-01-02") - case schemas.DateTime, schemas.TimeStamp, schemas.Varchar: // !DarthPestilane! format time when sqlTypeName is schemas.Varchar. - if dialect.URI().DBType == schemas.ORACLE { + case schemas.Varchar: // !DarthPestilane! format time when sqlTypeName is schemas.Varchar. + v = t.Format("2006-01-02 15:04:05") + case schemas.TimeStamp, schemas.DateTime: + dbType := dialect.URI().DBType + if dbType == schemas.POSTGRES || dbType == schemas.MYSQL { + v = t.Format("2006-01-02 15:04:05.999999") + } else if dialect.URI().DBType == schemas.ORACLE { v = t } else { v = t.Format("2006-01-02 15:04:05")