Updated
Updated
Updated could automatically add a timestamp on the record when you insert or update one record. You have to add one updated
tag on xorm
tag section. The field type could be time.Time
, type MyTime time.Time
or int
, int64
. For example,
type User struct {
Id int64
Name string
UpdatedAt time.Time `xorm:"updated"`
}
When methods Insert()
, InsertOne()
, Update()
are invoked, updated
field will be filled as current time or timestamp. For example:
var user User
engine.ID(1).Get(&user)
// SELECT * FROM user WHERE id = ?
engine.ID(1).Update(&user)
// UPDATE user SET ..., updated_at = ? WHERE id = ?
If you will temporarilly stop filling the time, use NoAutoTime()
:
engine.NoAutoTime().Insert(&user)
This feature is useful when you want to copy one record from one table to another.