这是我的代码:
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"time"
"fmt"
)
func (Rank) TableName() string {
return "Score_rank"
}
// Overriding Column Name
type Rank struct {
Id int64 `gorm:"column:id"`
DateCreation time.Time `gorm:"column:dateCreation`
Score time.Time `gorm:"column:score"`
Rank time.Time `gorm:"column:rank"`
ReceiverId int64 `gorm:"column:receiver_id"`
}
func main() {
db, err := gorm.Open("postgres", "host=127.0.0.1 port=5432 user=toto dbname=repsys password=akaburrules")
defer db.Close()
if err != nil {
panic("failed to connect database")
}
defer db.Close()
var rank Rank
//db.First(&rank)
db.First(&rank)
fmt.Println(rank)
fmt.Println(rank.ReceiverId)
fmt.Println(rank.DateCreation)
}
输出为:
{3 0001-01-01 00:00:00 +0000 UTC 2018-06-23 13:34:35 +0200 CEST 2018-06-23 13:34:36 +0200 CEST 3}
3
0001-01-01 00:00:00 +0000 UTC
但是问题是rank.DateCreation为假:
我不明白为什么我要使用date0001创建的0001-01-01 00:00:00 +0000 UTC。似乎也是空白值
值应为: 2018-06-23 13:34:11 + 02
这是我的数据库的pg admin视图 pg admin view of my db
编辑:
这是我的数据库的创建脚本:
"dateCreation" timestamp with time zone,
score timestamp with time zone,
rank timestamp with time zone,
问题可能是:
带有时区的“ dateCreation”时间戳
,引号。
那么如何用引号将该字段映射?
感谢和问候