Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (d SqliteDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool)
return "integer"
case "NullableBytes":
return "blob"
case "Time":
return "datetime"
}

if maxsize < 1 {
Expand Down Expand Up @@ -170,6 +172,8 @@ func (d PostgresDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr boo
return "smallint"
case "NullableBytes":
return "bytea"
case "Time", "NullTime":
return "timestamp with time zone"
}

if maxsize < 1 {
Expand Down Expand Up @@ -264,6 +268,8 @@ func (m MySQLDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool)
return "tinyint"
case "NullableBytes":
return "mediumblob"
case "Time":
return "datetime"
}

if maxsize < 1 {
Expand Down
25 changes: 25 additions & 0 deletions gorp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,30 @@ func TestWithStringPk(t *testing.T) {
}
}

type WithTime struct {
Id int64
Time time.Time
}

func TestWithTime(t *testing.T) {
dbmap := initDbMap()
defer dbmap.DropTables()

t1, err := time.Parse("2006-01-02 15:04:05 -0700 MST",
"2013-08-09 21:30:43 +0800 CST")
if err != nil {
panic(err)
}
w1 := WithTime{1, t1}
_insert(dbmap, &w1)

obj := _get(dbmap, WithTime{}, w1.Id)
w2 := obj.(*WithTime)
if w1.Time.UnixNano() != w2.Time.UnixNano() {
t.Errorf("%v != %v", w1, w2)
}
}

func TestInvoicePersonView(t *testing.T) {
dbmap := initDbMap()
defer dbmap.DropTables()
Expand Down Expand Up @@ -1017,6 +1041,7 @@ func initDbMap() *DbMap {
dbmap.AddTableWithName(WithIgnoredColumn{}, "ignored_column_test").SetKeys(true, "Id")
dbmap.AddTableWithName(TypeConversionExample{}, "type_conv_test").SetKeys(true, "Id")
dbmap.AddTableWithName(WithEmbeddedStruct{}, "embedded_struct_test").SetKeys(true, "Id")
dbmap.AddTableWithName(WithTime{}, "time_test").SetKeys(true, "Id")
dbmap.TypeConverter = testTypeConverter{}
err := dbmap.CreateTables()
if err != nil {
Expand Down