id: schema-config

title: Config

自定义表名

可以像下面的例子一样,使用 Table 选项自定义表名。

  1. package schema
  2. import (
  3. "github.com/facebookincubator/ent"
  4. "github.com/facebookincubator/ent/schema/field"
  5. )
  6. type User struct {
  7. ent.Schema
  8. }
  9. func (User) Config() ent.Config {
  10. return ent.Config{
  11. Table: "Users",
  12. }
  13. }
  14. func (User) Fields() []ent.Field {
  15. return []ent.Field{
  16. field.Int("age"),
  17. field.String("name"),
  18. }
  19. }