You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update with serializer:unixtime does not insert timestamps properly
Description
Here's my code, the database mysql:8.0.0 field is the timestamp type. If I don't specify serializer:unixtime, I can't plug in. There is no problem with Create after using it. But you can't call the update, here's the SQL that you get after the code runs
package main
import (
"fmt""gorm.io/driver/mysql""gorm.io/gorm"
)
typeBaseModelstruct {
Updatedint64`gorm:"autoUpdateTime;serializer:unixtime"`// Use unix MILLI seconds as updating timeCreatedint64`gorm:"autoCreateTime;serializer:unixtime"`// Use unix seconds as creating time
}
funcmain() {
dsn:="root:123456@tcp(127.0.0.1:3306)/?charset=utf8mb4&parseTime=True&loc=Local"db, err:=gorm.Open(mysql.Open(dsn), &gorm.Config{})
iferr!=nil {
panic(err)
}
createSql:=db.ToSQL(func(tx*gorm.DB) *gorm.DB {
returntx.Create(&BaseModel{})
})
fmt.Println("createSql", createSql)
updateSql:=db.ToSQL(func(tx*gorm.DB) *gorm.DB {
returntx.Updates(&BaseModel{})
})
fmt.Println("updateSql", updateSql)
}
Here are the results
createSql INSERT INTO `base_models` (`updated`,`created`) VALUES ('2024-04-29 16:03:24','2024-04-29 16:03:24')
2024/04/30 00:03:24 E:/demo/main.go:26 WHERE conditions required
updateSql UPDATE `base_models` SET `updated`=1714406604
The text was updated successfully, but these errors were encountered:
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
type BaseModel struct {
Updated int64 `gorm:"autoUpdateTime;serializer:unixtime"`
Created int64 `gorm:"autoCreateTime;serializer:unixtime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Update with serializer:unixtime does not insert timestamps properly
Description
Here's my code, the database mysql:8.0.0 field is the timestamp type. If I don't specify serializer:unixtime, I can't plug in. There is no problem with Create after using it. But you can't call the update, here's the SQL that you get after the code runs
Here are the results
The text was updated successfully, but these errors were encountered: