49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
|
package schema
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"entgo.io/contrib/entgql"
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/schema"
|
||
|
"entgo.io/ent/schema/edge"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
"github.com/google/uuid"
|
||
|
)
|
||
|
|
||
|
// Profile holds the schema definition for the Profile entity.
|
||
|
type Profile struct {
|
||
|
ent.Schema
|
||
|
}
|
||
|
|
||
|
// Fields of the Profile.
|
||
|
func (Profile) Fields() []ent.Field {
|
||
|
return []ent.Field{
|
||
|
field.UUID("id", uuid.UUID{}).Default(uuid.New).Unique().Immutable(),
|
||
|
field.Time("created_at").Default(time.Now).Immutable().Annotations(entgql.OrderField("CREATED_AT")),
|
||
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now).Optional().Annotations(entgql.OrderField("UPDATED_AT")),
|
||
|
field.String("name").Optional(),
|
||
|
field.Text("address").Optional(),
|
||
|
field.String("phone").Optional(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Edges of the Profile.
|
||
|
func (Profile) Edges() []ent.Edge {
|
||
|
return []ent.Edge{
|
||
|
edge.To("posts", Post.Type).Annotations(
|
||
|
entgql.RelayConnection(),
|
||
|
entgql.OrderField("POSTS_COUNT"),
|
||
|
),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Annotations of the Profile.
|
||
|
func (Profile) Annotations() []schema.Annotation {
|
||
|
return []schema.Annotation{
|
||
|
entgql.RelayConnection(),
|
||
|
entgql.QueryField(),
|
||
|
entgql.Mutations(entgql.MutationCreate(), entgql.MutationUpdate()),
|
||
|
}
|
||
|
}
|