首页 > 其他分享 >gorm tips

gorm tips

时间:2022-08-15 00:00:34浏览次数:65  
标签:column 列名 id beast Time tips gorm

约定的列明

type User struct {
  ID        uint      // 列名是 `id`
  Name      string    // 列名是 `name`
  Birthday  time.Time // 列名是 `birthday`
  CreatedAt time.Time // 列名是 `created_at`
}

约定的是驼峰命名会转化为下划线命名。

type Animal struct {
  AnimalID int64     `gorm:"column:beast_id"`         // 将列名设为 `beast_id`
  Birthday time.Time `gorm:"column:day_of_the_beast"` // 将列名设为 `day_of_the_beast`
  Age      int64     `gorm:"column:age_of_the_beast"` // 将列名设为 `age_of_the_beast`
}

可以使用标签修改对用的名字。不然可能导致查出来的数据转换不到对应结构体中。

标签:column,列名,id,beast,Time,tips,gorm
From: https://www.cnblogs.com/wangshushuo/p/16586753.html

相关文章