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,34 @@
// 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"
"github.com/google/uuid"
)
// Car holds the schema definition for the Car entity.
type Car struct {
ent.Schema
}
// Fields of the Car.
func (Car) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New),
field.String("number").
Optional(),
}
}
// Edges of the Car.
func (Car) Edges() []ent.Edge {
return []ent.Edge{
edge.To("rentals", Rental.Type),
}
}

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"
"entgo.io/ent/schema/index"
)
// Card holds the schema definition for the Card entity.
type Card struct {
ent.Schema
}
// Fields of the Card.
func (Card) Fields() []ent.Field {
return []ent.Field{
field.String("number").
Optional(),
field.Int("owner_id").
Optional(),
}
}
// Edges of the Card.
func (Card) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Ref("card").
Field("owner_id").
Unique(),
}
}
// Indexes of the Card.
func (Card) Indexes() []ent.Index {
return []ent.Index{
index.Fields("number", "owner_id"),
}
}

View File

@@ -0,0 +1,33 @@
// 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 (
"encoding/json"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Info holds the schema definition for the Info entity.
type Info struct {
ent.Schema
}
func (Info) Fields() []ent.Field {
return []ent.Field{
field.Int("id"),
field.JSON("content", json.RawMessage{}),
}
}
func (Info) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Unique().
StorageKey(edge.Column("id")),
}
}

View File

@@ -0,0 +1,37 @@
// 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"
)
// Metadata holds the schema definition for the Metadata entity.
type Metadata struct {
ent.Schema
}
func (Metadata) Fields() []ent.Field {
return []ent.Field{
field.Int("id"),
field.Int("age").
Default(0),
field.Int("parent_id").
Optional(),
}
}
func (Metadata) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("metadata").
Unique(),
edge.To("parent", Metadata.Type).
Field("parent_id").
Unique().
From("children"),
}
}

View File

@@ -0,0 +1,37 @@
// 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"
)
// Node holds the schema definition for the Node entity.
type Node struct {
ent.Schema
}
// Fields of the Node.
func (Node) Fields() []ent.Field {
return []ent.Field{
field.Int("value").
Default(0),
field.Int("prev_id").
Optional(),
}
}
// Edges of the Node.
func (Node) Edges() []ent.Edge {
return []ent.Edge{
edge.To("next", Node.Type).
Unique().
From("prev").
Field("prev_id").
Unique(),
}
}

View File

@@ -0,0 +1,34 @@
// 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 {
ent.Schema
}
// Fields of the Pet.
func (Pet) Fields() []ent.Field {
return []ent.Field{
field.Int("owner_id").
Optional(),
}
}
// Edges of the Dog.
func (Pet) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Ref("pets").
Field("owner_id").
Unique(),
}
}

View File

@@ -0,0 +1,43 @@
// 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"
"entgo.io/ent/schema/index"
)
// Post holds the schema definition for the Post entity.
type Post struct {
ent.Schema
}
// Fields of the Post.
func (Post) Fields() []ent.Field {
return []ent.Field{
field.String("text"),
field.Int("author_id").
Optional().
Nillable(),
}
}
// Edges of the Post.
func (Post) Edges() []ent.Edge {
return []ent.Edge{
edge.To("author", User.Type).
Field("author_id").
Unique(),
}
}
// Indexes of the Post.
func (Post) Indexes() []ent.Index {
return []ent.Index{
index.Fields("author_id", "text"),
}
}

View File

@@ -0,0 +1,59 @@
// 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"
"github.com/google/uuid"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Rental holds the schema definition for the Rental entity.
type Rental struct {
ent.Schema
}
// Fields of the Rental.
func (Rental) Fields() []ent.Field {
return []ent.Field{
field.Time("date").
Default(time.Now),
field.Int("user_id").
Immutable(),
field.UUID("car_id", uuid.UUID{}).
Immutable(),
}
}
// Edges of the Rental.
func (Rental) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("rentals").
Field("user_id").
Unique().
Required().
Immutable(),
edge.From("car", Car.Type).
Ref("rentals").
Field("car_id").
Unique().
Required().
Immutable(),
}
}
// Indexes of the Rental.
func (Rental) Indexes() []ent.Index {
return []ent.Index{
index.Fields("car_id", "user_id").
Unique(),
}
}

View File

@@ -0,0 +1,57 @@
// 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"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.Int("id").
SchemaType(map[string]string{
dialect.SQLite: "integer",
}).
Immutable(),
field.Int("parent_id").
Optional().
Immutable(),
field.Int("spouse_id").
Optional(),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("pets", Pet.Type),
edge.To("children", User.Type).
From("parent").
Field("parent_id").
Immutable().
Comment("The parent edge and its field are immutable").
Unique(),
edge.To("spouse", User.Type).
Field("spouse_id").
Unique(),
edge.To("card", Card.Type).
Unique(),
edge.To("metadata", Metadata.Type).
Unique().
StorageKey(edge.Column("id")),
edge.From("info", Info.Type).
Ref("user"),
edge.To("rentals", Rental.Type),
}
}