1 Star 0 Fork 0

DaMeng/Ent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
friendship.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
DaMeng 提交于 2024-10-24 16:04 . :tada:fork ent
// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package schema
import (
"time"
"gitee.com/damengde/ent"
"gitee.com/damengde/ent/schema/edge"
"gitee.com/damengde/ent/schema/field"
"gitee.com/damengde/ent/schema/index"
)
// An example for an ent/schema that mixed in an ent/mixin to define default table schema (in the database).
// Friendship holds the edge schema definition of the Friendship relationship.
type Friendship struct {
ent.Schema
}
// Mixin defines the schemas that mixed into this schema.
func (Friendship) Mixin() []ent.Mixin {
return []ent.Mixin{
Mixin{},
}
}
// Fields of the Friendship.
func (Friendship) Fields() []ent.Field {
return []ent.Field{
field.Int("weight").
Default(1),
field.Time("created_at").
Default(time.Now),
field.Int("user_id").
Immutable(),
field.Int("friend_id").
Immutable(),
}
}
// Edges of the Friendship.
func (Friendship) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Unique().
Required().
Immutable().
Field("user_id"),
edge.To("friend", User.Type).
Unique().
Required().
Immutable().
Field("friend_id"),
}
}
// Indexes of the Friendship.
func (Friendship) Indexes() []ent.Index {
return []ent.Index{
index.Fields("created_at"),
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/damengde/ent.git
git@gitee.com:damengde/ent.git
damengde
ent
Ent
90870c5ba095

搜索帮助

0d507c66 1850385 C8b1a773 1850385