todo.go 633 B

12345678910111213141516171819202122232425262728293031
  1. package schema
  2. import (
  3. "time"
  4. "entgo.io/ent"
  5. "entgo.io/ent/schema/edge"
  6. "entgo.io/ent/schema/field"
  7. )
  8. // Todo holds the schema definition for the Todo entity.
  9. type Todo struct {
  10. ent.Schema
  11. }
  12. // Fields of the Todo.
  13. func (Todo) Fields() []ent.Field {
  14. return []ent.Field{
  15. field.Text("text").NotEmpty(),
  16. field.Time("created_at").Default(time.Now).Immutable(),
  17. field.Enum("status").Values("in_progress", "completed").Default("in_progress"),
  18. field.Int("priority").Default(0),
  19. }
  20. }
  21. // Edges of the Todo.
  22. func (Todo) Edges() []ent.Edge {
  23. return []ent.Edge{
  24. edge.To("parent", Todo.Type).Unique().From("children"),
  25. }
  26. }