diff --git a/base_test.go b/base_test.go index 17cfedf1..33790ae8 100644 --- a/base_test.go +++ b/base_test.go @@ -1632,6 +1632,7 @@ func testBool(engine *Engine, t *testing.T) { type TTime struct { Id int64 T time.Time + Tz time.Time `xorm:"timestampz"` } func testTime(engine *Engine, t *testing.T) { @@ -1660,12 +1661,20 @@ func testTime(engine *Engine, t *testing.T) { panic(err) } - tt3 := &TTime{T: time.Now()} + tt3 := &TTime{T: time.Now(), Tz: time.Now()} _, err = engine.Insert(tt3) if err != nil { t.Error(err) panic(err) } + + tt4s := make([]TTime, 0) + err = engine.Find(&tt4s) + if err != nil { + t.Error(err) + panic(err) + } + fmt.Println("=======\n", tt4s, "=======\n") } func testPrefixTableName(engine *Engine, t *testing.T) { diff --git a/mysql.go b/mysql.go index 09d70d86..20cb17b1 100644 --- a/mysql.go +++ b/mysql.go @@ -90,6 +90,9 @@ func (db *mysql) SqlType(c *Column) string { res = BigInt case Bytea: res = Blob + case TimeStampz: + res = Char + c.Length = 64 default: res = t } diff --git a/postgres.go b/postgres.go index 0349e073..464d60e5 100644 --- a/postgres.go +++ b/postgres.go @@ -72,6 +72,8 @@ func (db *postgres) SqlType(c *Column) string { return Bytea case DateTime: res = TimeStamp + case TimeStampz: + return "timestamp with time zone" case Float: res = Real case TinyText, MediumText, LongText: @@ -180,6 +182,8 @@ func (db *postgres) GetColumns(tableName string) ([]string, map[string]*Column, col.SQLType = SQLType{Varchar, 0, 0} case "timestamp without time zone": col.SQLType = SQLType{DateTime, 0, 0} + case "timestamp with time zone": + col.SQLType = SQLType{TimeStampz, 0, 0} case "double precision": col.SQLType = SQLType{Double, 0, 0} case "boolean": diff --git a/session.go b/session.go index 118061c1..5e9d1e10 100644 --- a/session.go +++ b/session.go @@ -1622,6 +1622,8 @@ func (session *Session) value2Interface(col *Column, fieldValue reflect.Value) ( return s[11:19], nil } else if col.SQLType.Name == Date { return fieldValue.Interface().(time.Time).Format("2006-01-02"), nil + } else if col.SQLType.Name == TimeStampz { + return fieldValue.Interface().(time.Time).Format(time.RFC3339Nano), nil } return fieldValue.Interface(), nil } diff --git a/sqlite3.go b/sqlite3.go index c0cb8bda..f8b27fb0 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -18,6 +18,8 @@ func (db *sqlite3) SqlType(c *Column) string { switch t := c.SQLType.Name; t { case Date, DateTime, TimeStamp, Time: return Numeric + case TimeStampz: + return Text case Char, Varchar, TinyText, Text, MediumText, LongText: return Text case Bit, TinyInt, SmallInt, MediumInt, Int, Integer, BigInt, Bool: diff --git a/table.go b/table.go index fdd62bfd..012c4030 100644 --- a/table.go +++ b/table.go @@ -42,10 +42,11 @@ var ( Binary = "BINARY" VarBinary = "VARBINARY" - Date = "DATE" - DateTime = "DATETIME" - Time = "TIME" - TimeStamp = "TIMESTAMP" + Date = "DATE" + DateTime = "DATETIME" + Time = "TIME" + TimeStamp = "TIMESTAMP" + TimeStampz = "TIMESTAMPZ" Decimal = "DECIMAL" Numeric = "NUMERIC" @@ -83,10 +84,11 @@ var ( Binary: true, VarBinary: true, - Date: true, - DateTime: true, - Time: true, - TimeStamp: true, + Date: true, + DateTime: true, + Time: true, + TimeStamp: true, + TimeStampz: true, Decimal: true, Numeric: true, @@ -122,7 +124,7 @@ func Type2SQLType(t reflect.Type) (st SQLType) { st = SQLType{Double, 0, 0} case reflect.Complex64, reflect.Complex128: st = SQLType{Varchar, 64, 0} - case reflect.Array, reflect.Slice: + case reflect.Array, reflect.Slice, reflect.Map: if t.Elem() == reflect.TypeOf(b) { st = SQLType{Blob, 0, 0} } else { @@ -162,7 +164,7 @@ func SQLType2Type(st SQLType) reflect.Type { return reflect.TypeOf([]byte{}) case Bool: return reflect.TypeOf(true) - case DateTime, Date, Time, TimeStamp: + case DateTime, Date, Time, TimeStamp, TimeStampz: return reflect.TypeOf(tm) case Decimal, Numeric: return reflect.TypeOf("")