Using orm (GORM) for GoLang (1.11), DB is SQLite (imported from MySQL as it is) and I have a problem with datetime conversion
import (
...
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"time"
)
type Product struct {
P_id int `json:"p_id"`
Z_id int `json:"z_id"`
Name string `json:"name"`
...
Pushed int `json:"pushed"`
Cn_color int `json:"cn_color"`
Updated_at time.Time `json:"updated_at"`
}
func GetProduct() {
db, err = gorm.Open("sqlite3", "./data/godb.db")
if err != nil {
panic("Could not connect to DB")
}
defer db.Close()
var product Product
db.Where("p_id = ?", c.Param("p_id")).First(&product)
fmt.Print(product.Updated_at)
}
And i recieved
0001-01-01 00:00:00 +0000 UTC
But in DB i have
2018-02-28 14:17:56
How can I specify the type of datetime field?
I've tried:
- to add
json:"updated_at" type: "datetime"
- to change type to
*time.Time
- answers from this post - time column in sqlite using gorm
but nothing happens