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,

  1. type User struct {
  2. Id int64
  3. Name string
  4. UpdatedAt time.Time `xorm:"updated"`
  5. }

When methods Insert(), InsertOne(), Update() are invoked, updated field will be filled as current time or timestamp. For example:

  1. var user User
  2. engine.ID(1).Get(&user)
  3. // SELECT * FROM user WHERE id = ?
  4. engine.ID(1).Update(&user)
  5. // UPDATE user SET ..., updated_at = ? WHERE id = ?

If you will temporarilly stop filling the time, use NoAutoTime():

  1. engine.NoAutoTime().Insert(&user)

This feature is useful when you want to copy one record from one table to another.