why after I created a new table using go-pg, and found that the name of the new table changed? for example,the struct name is "story" and it became "stories" in pg.
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
}
My struct name is "Newtb" and it turned "newtbs" in postgreSQL. Can someone explain to me why an 's' was added to the table name?
Table name and alias are automatically derived from the struct name by underscoring it. Table name is also pluralized, for example struct Genre gets table name genres and alias genre. You can override the default table name and alias using tableName field:
type Genre struct {
tableName struct{} `pg:"genres,alias:g"`
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.