postgresql - 如何在 go 的 gorm 模型中访问每个字段需要映射到的 postgres 类型?
问题描述
假设我有一个模型
type MyModel struct {
FirstField *CustomType `gorm:"primaryKey"`
SecondField string `gorm:"type:varchar(42)"`
}
type CustomType struct {
*big.Int
}
func (CustomType) GormDataType() string {
return "numeric"
}
有什么方法可以通过 db.DB 对象找出 FirstField 的 postgres 类型应该是数字,SecondField 的 varchar(42) 类型应该是数字吗?
我注意到表单中的每个字段都有一个在 schema/field.go ParseField 中解析的 DataType。它在哪里被调用,它是否存储在数据库中的某个地方?我注意到我需要一个模式来自己调用 ParseField,但 db 模式似乎为零。我错过了什么吗?谢谢!
解决方案
推荐阅读
- node.js - NodeJS:服务必须使用`new`操作符构建
- input - 角度 5,保持输入值并将其添加到 JS 对象
- javascript - VBS 点击按钮 by href
- javascript - 更改侧边栏的颜色
- azure-language-understanding - 使用意图映射 LUIS 话语
- google-bigquery - Java - 一次插入一行到谷歌大查询?
- docker - 如何使用 docker-compose 将环境变量设置到 docker 容器中
- php - yii2 从日期时间选择时间
- reactjs - Immutable.js 不呈现列表数据
- python - 从python dict中的用户输入获取键值