snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 22:12:36 +05:00
commit 4b3ad0b611
2680 changed files with 719472 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
)
// base holds the default configuration for most schemas in this package.
type base struct {
ent.Schema
}
// Annotations of the base schema.
func (base) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Schema("db1"),
}
}

View File

@@ -0,0 +1,65 @@
// 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"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Friendship holds the edge schema definition of the Friendship relationship.
type Friendship struct {
ent.Schema
}
// 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"),
}
}
// Annotations of the Friendship.
func (Friendship) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Schema("db2"),
}
}

View File

@@ -0,0 +1,40 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Group holds the schema definition for the Group entity.
type Group struct {
ent.Schema
}
// Fields of the Group.
func (Group) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("unknown"),
}
}
// Edges of the Group.
func (Group) Edges() []ent.Edge {
return []ent.Edge{
edge.To("users", User.Type),
}
}
// Annotations of the Group.
func (Group) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Schema("db2"),
}
}

View File

@@ -0,0 +1,44 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Parent holds the schema definition for the Parent entity.
type Parent struct {
base
}
// Fields of the Parent.
func (Parent) Fields() []ent.Field {
return []ent.Field{
field.Bool("by_adoption").
Default(false),
field.Int("user_id").
Immutable(),
field.Int("parent_id").
Immutable(),
}
}
// Edges of the Parent.
func (Parent) Edges() []ent.Edge {
return []ent.Edge{
edge.To("child", User.Type).
Unique().
Required().
Immutable().
Field("user_id"),
edge.To("parent", User.Type).
Unique().
Required().
Immutable().
Field("parent_id"),
}
}

View File

@@ -0,0 +1,36 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Pet holds the schema definition for the Pet entity.
type Pet struct {
base
}
// Fields of the Pet.
func (Pet) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("unknown"),
field.Int("owner_id").
Optional(),
}
}
// Edges of the Pet.
func (Pet) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Ref("pets").
Field("owner_id").
Unique(),
}
}

View File

@@ -0,0 +1,60 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// User holds the schema definition for the User entity.
type User struct {
base
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("unknown"),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("pets", Pet.Type),
edge.From("groups", Group.Type).
Ref("users"),
edge.To("friends", User.Type).
Through("friendships", Friendship.Type),
edge.To("children", User.Type).
Through("parent_hood", Parent.Type).
From("parents"),
}
}
// CleanUser represents a user without its PII field.
type CleanUser struct {
ent.View
}
// Annotations of the CleanUser.
func (CleanUser) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.View("SELECT id, name FROM users"),
entsql.Schema("db1"),
}
}
// Fields of the CleanUser.
func (CleanUser) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
}
}