[英]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.