37 lines
697 B
Go
37 lines
697 B
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
type Comments struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Comments) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("id").Unique().Immutable(),
|
|
field.Int64("post_id"),
|
|
field.Int64("author_id"),
|
|
field.String("content"),
|
|
field.Int("like_count").Optional().Default(0),
|
|
field.Time("created_at").Default(time.Now).Immutable(),
|
|
field.Time("deleted_at").Optional().Nillable(),
|
|
}
|
|
}
|
|
|
|
func (Comments) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("post_id", "created_at"),
|
|
index.Fields("author_id", "created_at"),
|
|
}
|
|
}
|
|
|
|
func (Comments) Edges() []ent.Edge {
|
|
return nil
|
|
}
|