[英]why after I created a new table using go-pg, and found that the name of the new table changed?
为什么我使用 go-pg 创建了一个新表后,发现新表的名称发生了变化? 例如,结构名称是“story”,它在 pg 中变成了“stories”。
type Newtb struct {
Id int64
Name string
Emails []string
}
func createTest(db *pg.DB) error {
err := db.Model((*Newtb)(nil)).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
})
if err != nil {
log.Fatal(err)
return err
}
return nil
}
我的结构名称是“Newtb”,它在 postgreSQL 中变成了“newtbs”。 有人可以向我解释为什么在表名中添加了“s”吗?
表名和别名通过下划线自动从结构名派生而来。 表名也是复数形式,例如 struct Genre 获取表名流派和别名流派。 您可以使用 tableName 字段覆盖默认表名和别名:
type Genre struct {
tableName struct{} `pg:"genres,alias:g"`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.