diff --git a/dialect.go b/dialect.go index 1e8c971d..e997b413 100644 --- a/dialect.go +++ b/dialect.go @@ -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 { @@ -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 { @@ -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 { diff --git a/gorp_test.go b/gorp_test.go index 89ad2bac..37305384 100644 --- a/gorp_test.go +++ b/gorp_test.go @@ -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() @@ -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 {