Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save manakuro/7c7f0bf9c9e330e8bdb671c96124d4ae to your computer and use it in GitHub Desktop.
// Fields of the Todo.
func (Todo) Fields() []ent.Field {
return []ent.Field{
field.Int("user_id").Optional(),
field.String("name").Default(""),
field.Enum("status").
NamedValues(
"InProgress", "IN_PROGRESS",
"Completed", "COMPLETED",
).
Default("IN_PROGRESS"),
field.Int("priority").Default(0),
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