add new time type timestampz for datetime with time zone
This commit is contained in:
parent
afedb683c6
commit
20bfc62f13
11
base_test.go
11
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) {
|
||||
|
|
3
mysql.go
3
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
|
||||
}
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
6
table.go
6
table.go
|
@ -46,6 +46,7 @@ var (
|
|||
DateTime = "DATETIME"
|
||||
Time = "TIME"
|
||||
TimeStamp = "TIMESTAMP"
|
||||
TimeStampz = "TIMESTAMPZ"
|
||||
|
||||
Decimal = "DECIMAL"
|
||||
Numeric = "NUMERIC"
|
||||
|
@ -87,6 +88,7 @@ var (
|
|||
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("")
|
||||
|
|
Loading…
Reference in New Issue