声明模型
1 模型定义
type User struct {
ID uint // Standard field for the primary key
Name string // A regular string field
Email *string // A pointer to a string, allowing for null values
Age uint8 // An unsigned 8-bit integer
Birthday *time.Time // A pointer to time.Time, can be null
MemberNumber sql.NullString // Uses sql.NullString to handle nullable strings
ActivatedAt sql.NullTime // Uses sql.NullTime for nullable time fields
CreatedAt time.Time // Automatically managed by GORM for creation time
UpdatedAt time.Time // Automatically managed by GORM for update time
ignored string // fields that aren't exported are ignored
}2 约定
2.1 使用ID作为主键
2.2 复数表名
2.3 临时指定表名
2.4 命名策略
2.5 列名
2.6 CreatedAt
2.7 UpdatedAt
3 grom.Model
4 字段级权限控制
5 创建/更新时间追踪
6 嵌入结构体
7 字段标签
标签名
说明
8 关联标签
9 时间处理
最后更新于