48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package schema
|
|
|
|
import (
|
|
"likedream-goframe/internal/ent/schema/mix"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// SysAgent holds the schema definition for the SysAgent entity.
|
|
type SysAgent struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the SysAgent.
|
|
func (SysAgent) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("level"),
|
|
field.String("rate").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
|
dialect.MySQL: "decimal(10,2)",
|
|
dialect.Postgres: "numeric(10,2)",
|
|
}),
|
|
}
|
|
}
|
|
|
|
// Edges of the SysAgent.
|
|
func (SysAgent) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("users", SysUser.Type).Ref("agent").Unique().Annotations(entsql.OnDelete(entsql.Cascade)),
|
|
}
|
|
}
|
|
|
|
func (SysAgent) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{Table: "sys_agent"},
|
|
}
|
|
}
|
|
func (SysAgent) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mix.MixinTime{},
|
|
}
|
|
}
|