Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created December 10, 2021 04:25
Show Gist options
  • Select an option

  • Save manakuro/f1665622edba65f92f647e8f40f17f81 to your computer and use it in GitHub Desktop.

Select an option

Save manakuro/f1665622edba65f92f647e8f40f17f81 to your computer and use it in GitHub Desktop.
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").
NotEmpty().
MaxLen(255),
field.Int("age").
Positive(),
field.Time("created_at").
Default(time.Now).
SchemaType(map[string]string{
dialect.MySQL: "datetime DEFAULT CURRENT_TIMESTAMP",
}).
Immutable(),
field.Time("updated_at").
Default(time.Now).
SchemaType(map[string]string{
dialect.MySQL: "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
}).
Immutable(),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment