Skip to content

Commit

Permalink
fix(mysqldialect): remove duplicate AppendTime
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Oct 5, 2021
1 parent 182e4ee commit 8d42090
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dialect/mysqldialect/append.go
Expand Up @@ -32,7 +32,7 @@ func appendTimeValue(fmter schema.Formatter, b []byte, v reflect.Value) []byte {

func appendTime(b []byte, tm time.Time) []byte {
b = append(b, '\'')
b = tm.UTC().AppendFormat(b, "2006-01-02 15:04:05.999999")
b = tm.AppendFormat(b, "2006-01-02 15:04:05.999999")
b = append(b, '\'')
return b
}
Expand Down
5 changes: 1 addition & 4 deletions dialect/mysqldialect/dialect.go
Expand Up @@ -85,10 +85,7 @@ func (d *Dialect) IdentQuote() byte {
}

func (d *Dialect) AppendTime(b []byte, tm time.Time) []byte {
b = append(b, '\'')
b = tm.AppendFormat(b, "2006-01-02 15:04:05.999999-07:00")
b = append(b, '\'')
return b
return appendTime(b, tm)
}

func (d *Dialect) Append(fmter schema.Formatter, b []byte, v interface{}) []byte {
Expand Down
9 changes: 8 additions & 1 deletion internal/dbtest/query_test.go
Expand Up @@ -547,7 +547,7 @@ func TestQuery(t *testing.T) {
},
func(db *bun.DB) schema.QueryAppender {
type Model struct {
ID int `bun:",allowzero"`
ID int64 `bun:",allowzero"`
}
return db.NewInsert().Model(new(Model))
},
Expand All @@ -557,6 +557,13 @@ func TestQuery(t *testing.T) {
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(&Model{ID: 42}).OmitZero().WherePK()
},
func(db *bun.DB) schema.QueryAppender {
type Model struct {
ID int64
Time time.Time
}
return db.NewInsert().Model(&Model{ID: 123, Time: time.Unix(0, 0)})
},
}

timeRE := regexp.MustCompile(`'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+(\+\d{2}:\d{2})?'`)
Expand Down
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-mysql5-61
@@ -1 +1 @@
VALUES ROW(NULL), ROW('1970-01-01 00:00:00+00:00')
VALUES ROW(NULL), ROW('1970-01-01 00:00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-mysql5-88
@@ -1 +1 @@
UPDATE `models` AS `model` SET WHERE (`model`.`id` = 42)
INSERT INTO `models` (`id`, `time`) VALUES (123, '1970-01-01 00:00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-mysql8-61
@@ -1 +1 @@
VALUES ROW(NULL), ROW('1970-01-01 00:00:00+00:00')
VALUES ROW(NULL), ROW('1970-01-01 00:00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-mysql8-88
@@ -1 +1 @@
UPDATE `models` AS `model` SET WHERE (`model`.`id` = 42)
INSERT INTO `models` (`id`, `time`) VALUES (123, '1970-01-01 00:00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-pg-88
@@ -1 +1 @@
UPDATE "models" AS "model" SET WHERE ("model"."id" = 42)
INSERT INTO "models" ("id", "time") VALUES (123, '1970-01-01 00:00:00+00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-pgx-88
@@ -1 +1 @@
UPDATE "models" AS "model" SET WHERE ("model"."id" = 42)
INSERT INTO "models" ("id", "time") VALUES (123, '1970-01-01 00:00:00+00:00')
2 changes: 1 addition & 1 deletion internal/dbtest/testdata/snapshots/TestQuery-sqlite-88
@@ -1 +1 @@
UPDATE "models" AS "model" SET WHERE ("model"."id" = 42)
INSERT INTO "models" ("id", "time") VALUES (123, '1970-01-01 00:00:00+00:00')

0 comments on commit 8d42090

Please sign in to comment.