snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
40
entc/integration/customid/ent/schema/account.go
Normal file
40
entc/integration/customid/ent/schema/account.go
Normal 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"
|
||||
"entgo.io/ent/entc/integration/customid/sid"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Account holds the schema definition for the Account entity.
|
||||
type Account struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Account.
|
||||
func (Account) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Other("id", sid.ID("")).
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "bigint",
|
||||
dialect.Postgres: "bigint",
|
||||
dialect.SQLite: "integer",
|
||||
}).
|
||||
Default(sid.New).
|
||||
Immutable(),
|
||||
field.String("email").NotEmpty(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Account.
|
||||
func (Account) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("token", Token.Type),
|
||||
}
|
||||
}
|
||||
86
entc/integration/customid/ent/schema/blob.go
Normal file
86
entc/integration/customid/ent/schema/blob.go
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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/schema"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Blob holds the schema definition for the Blob entity.
|
||||
type Blob struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Blob.
|
||||
func (Blob) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Annotations(entsql.Annotation{
|
||||
Default: "uuid_generate_v4()",
|
||||
}).
|
||||
Unique(),
|
||||
field.UUID("uuid", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique(),
|
||||
field.Int("count").
|
||||
Default(0),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Blob.
|
||||
func (Blob) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("parent", Blob.Type).
|
||||
Unique(),
|
||||
edge.To("links", Blob.Type).
|
||||
Through("blob_links", BlobLink.Type),
|
||||
}
|
||||
}
|
||||
|
||||
// BlobLink holds the edge schema definition for blob links.
|
||||
type BlobLink struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the BlobLink.
|
||||
func (BlobLink) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
field.ID("blob_id", "link_id"),
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the BlobLink.
|
||||
func (BlobLink) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Default(time.Now),
|
||||
field.UUID("blob_id", uuid.UUID{}),
|
||||
field.UUID("link_id", uuid.UUID{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the BlobLink.
|
||||
func (BlobLink) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("blob", Blob.Type).
|
||||
Field("blob_id").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.To("link", Blob.Type).
|
||||
Field("link_id").
|
||||
Required().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
58
entc/integration/customid/ent/schema/car.go
Normal file
58
entc/integration/customid/ent/schema/car.go
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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/mixin"
|
||||
)
|
||||
|
||||
type IDMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (IDMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Float("before_id").
|
||||
Optional().
|
||||
Positive(),
|
||||
field.Int("id").
|
||||
Positive().
|
||||
Immutable(),
|
||||
field.Float("after_id").
|
||||
Optional().
|
||||
Negative(),
|
||||
}
|
||||
}
|
||||
|
||||
// Car holds the schema definition for the Car entity.
|
||||
type Car struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Mixin of the Car.
|
||||
func (Car) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
IDMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Car.
|
||||
func (Car) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("model"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Car.
|
||||
func (Car) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", Pet.Type).
|
||||
Ref("cars").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
74
entc/integration/customid/ent/schema/doc.go
Normal file
74
entc/integration/customid/ent/schema/doc.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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 (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"ariga.io/atlas/sql/postgres"
|
||||
)
|
||||
|
||||
// Doc holds the schema definition for the Doc entity.
|
||||
type Doc struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Doc.
|
||||
func (Doc) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("id").
|
||||
GoType(DocID("")).
|
||||
MaxLen(36).
|
||||
NotEmpty().
|
||||
Unique().
|
||||
Immutable().
|
||||
DefaultFunc(func() DocID {
|
||||
return DocID(uuid.NewString())
|
||||
}).
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: postgres.TypeUUID,
|
||||
}),
|
||||
field.String("text").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Doc.
|
||||
func (Doc) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("children", Doc.Type).
|
||||
From("parent").
|
||||
Unique(),
|
||||
edge.To("related", Doc.Type),
|
||||
}
|
||||
}
|
||||
|
||||
type DocID string
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (s *DocID) Scan(value any) (err error) {
|
||||
switch v := value.(type) {
|
||||
case nil:
|
||||
case []byte:
|
||||
*s = DocID(v)
|
||||
case string:
|
||||
*s = DocID(v)
|
||||
default:
|
||||
err = fmt.Errorf("unexpected type %T", v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (s DocID) Value() (driver.Value, error) {
|
||||
return string(s), nil
|
||||
}
|
||||
31
entc/integration/customid/ent/schema/group.go
Normal file
31
entc/integration/customid/ent/schema/group.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// 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.Int("id").
|
||||
StructTag(`json:"oid,omitempty"`),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Group.
|
||||
func (Group) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("users", User.Type),
|
||||
}
|
||||
}
|
||||
37
entc/integration/customid/ent/schema/intsid.go
Normal file
37
entc/integration/customid/ent/schema/intsid.go
Normal 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/entc/integration/customid/sid"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// IntSID holds the schema definition for the IntSID entity.
|
||||
type IntSID struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the IntSid.
|
||||
func (IntSID) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").
|
||||
GoType(sid.New()).
|
||||
Unique().
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the IntSid.
|
||||
func (IntSID) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("parent", IntSID.Type).
|
||||
Unique(),
|
||||
edge.From("children", IntSID.Type).
|
||||
Ref("parent"),
|
||||
}
|
||||
}
|
||||
35
entc/integration/customid/ent/schema/link.go
Normal file
35
entc/integration/customid/ent/schema/link.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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"
|
||||
uuidc "entgo.io/ent/entc/integration/customid/uuidcompatible"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type LinkInformation struct {
|
||||
Name string
|
||||
Link string
|
||||
}
|
||||
|
||||
// Link holds the schema definition for the Link entity.
|
||||
type Link struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the IntSid.
|
||||
func (Link) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuidc.UUIDC{}).Default(uuidc.NewUUIDC),
|
||||
field.JSON("link_information", map[string]LinkInformation{}).
|
||||
Default(map[string]LinkInformation{
|
||||
"ent": {
|
||||
Name: "ent",
|
||||
Link: "https://entgo.io/",
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
55
entc/integration/customid/ent/schema/mixinid.go
Normal file
55
entc/integration/customid/ent/schema/mixinid.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// BaseMixin holds the schema definition for the BaseMixin entity.
|
||||
type BaseMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
// Fields of the Mixin.
|
||||
func (BaseMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).Default(uuid.New),
|
||||
field.String("some_field"),
|
||||
}
|
||||
}
|
||||
|
||||
// MixinID holds the schema definition for the MixinID entity.
|
||||
type MixinID struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the MixinID.
|
||||
func (MixinID) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("mixin_field"),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the MixinID
|
||||
func (MixinID) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("id"),
|
||||
index.Fields("id", "some_field"),
|
||||
index.Fields("id", "mixin_field"),
|
||||
index.Fields("id", "mixin_field", "some_field"),
|
||||
}
|
||||
}
|
||||
|
||||
// Mixin of MixinID
|
||||
func (MixinID) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
BaseMixin{},
|
||||
}
|
||||
}
|
||||
45
entc/integration/customid/ent/schema/note.go
Normal file
45
entc/integration/customid/ent/schema/note.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
type NoteID string
|
||||
|
||||
// Note holds the schema definition for the Note entity.
|
||||
type Note struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Note.
|
||||
func (Note) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("id").
|
||||
GoType(NoteID("")).
|
||||
MaxLen(36).
|
||||
NotEmpty().
|
||||
Unique().
|
||||
Immutable().
|
||||
DefaultFunc(func() NoteID {
|
||||
return NoteID(uuid.NewString())
|
||||
}),
|
||||
field.String("text").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Note.
|
||||
func (Note) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("children", Note.Type).
|
||||
From("parent").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
31
entc/integration/customid/ent/schema/other.go
Normal file
31
entc/integration/customid/ent/schema/other.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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/entc/integration/customid/sid"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Other holds the schema definition for the Other entity.
|
||||
type Other struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Other.
|
||||
func (Other) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Other("id", sid.ID("")).
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "bigint",
|
||||
dialect.Postgres: "bigint",
|
||||
dialect.SQLite: "integer",
|
||||
}).
|
||||
Default(sid.New).
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
42
entc/integration/customid/ent/schema/pet.go
Normal file
42
entc/integration/customid/ent/schema/pet.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// 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.String("id").
|
||||
MaxLen(36).
|
||||
NotEmpty().
|
||||
Unique().
|
||||
Immutable().
|
||||
DefaultFunc(uuid.NewString),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Pet.
|
||||
func (Pet) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("pets").
|
||||
Unique(),
|
||||
edge.To("cars", Car.Type),
|
||||
edge.To("friends", Pet.Type),
|
||||
edge.To("best_friend", Pet.Type).
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
23
entc/integration/customid/ent/schema/revision.go
Normal file
23
entc/integration/customid/ent/schema/revision.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Revision holds the schema definition for the Revision entity.
|
||||
type Revision struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Revision.
|
||||
func (Revision) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("id"),
|
||||
}
|
||||
}
|
||||
92
entc/integration/customid/ent/schema/session.go
Normal file
92
entc/integration/customid/ent/schema/session.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// 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 (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Session holds the schema definition for the Session entity.
|
||||
type Session struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Session.
|
||||
func (Session) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Bytes("id").
|
||||
MaxLen(64).
|
||||
GoType(ID{}).
|
||||
DefaultFunc(NewID),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Session.
|
||||
func (Session) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("device", Device.Type).
|
||||
Ref("sessions").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
// Device holds the schema definition for the Device entity.
|
||||
type Device struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Device.
|
||||
func (Device) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Bytes("id").
|
||||
MaxLen(64).
|
||||
GoType(ID{}).
|
||||
DefaultFunc(NewID),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Device.
|
||||
func (Device) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("active_session", Session.Type).
|
||||
Unique(),
|
||||
edge.To("sessions", Session.Type),
|
||||
}
|
||||
}
|
||||
|
||||
type ID [64]byte
|
||||
|
||||
func NewID() ID {
|
||||
var id [64]byte
|
||||
copy(id[:], uuid.NewString()+uuid.NewString()+uuid.NewString()+uuid.NewString())
|
||||
return id
|
||||
}
|
||||
|
||||
func (i ID) String() string {
|
||||
return string(i[:])
|
||||
}
|
||||
|
||||
func (i *ID) Scan(v any) error {
|
||||
switch v := v.(type) {
|
||||
case []byte:
|
||||
copy(i[:], v)
|
||||
case string:
|
||||
copy(i[:], v)
|
||||
default:
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i ID) Value() (driver.Value, error) {
|
||||
return string(i[:]), nil
|
||||
}
|
||||
40
entc/integration/customid/ent/schema/token.go
Normal file
40
entc/integration/customid/ent/schema/token.go
Normal 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"
|
||||
"entgo.io/ent/entc/integration/customid/sid"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Token holds the schema definition for the Token entity.
|
||||
type Token struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Token.
|
||||
func (Token) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Other("id", sid.ID("")).
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "bigint",
|
||||
dialect.Postgres: "bigint",
|
||||
dialect.SQLite: "integer",
|
||||
}).
|
||||
Default(sid.New).
|
||||
Immutable(),
|
||||
field.String("body").NotEmpty(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Token.
|
||||
func (Token) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("account", Account.Type).Ref("token").Required().Unique(),
|
||||
}
|
||||
}
|
||||
36
entc/integration/customid/ent/schema/user.go
Normal file
36
entc/integration/customid/ent/schema/user.go
Normal 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"
|
||||
)
|
||||
|
||||
// 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").
|
||||
StorageKey("oid"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("groups", Group.Type).
|
||||
Ref("users"),
|
||||
edge.To("children", User.Type).
|
||||
From("parent").
|
||||
Unique(),
|
||||
edge.To("pets", Pet.Type),
|
||||
}
|
||||
}
|
||||
43
entc/integration/customid/ent/schema/valuescan.go
Normal file
43
entc/integration/customid/ent/schema/valuescan.go
Normal 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 (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ValueScan holds the schema definition for the ValueScan entity.
|
||||
type ValueScan struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// ValueScanID is a custom ID type that relies on an external ValueScanner.
|
||||
type ValueScanID struct {
|
||||
V int
|
||||
}
|
||||
|
||||
// Fields of the ValueScan.
|
||||
func (ValueScan) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").
|
||||
GoType(ValueScanID{}).
|
||||
ValueScanner(field.ValueScannerFunc[ValueScanID, *sql.NullInt64]{
|
||||
V: func(id ValueScanID) (driver.Value, error) {
|
||||
return int64(id.V), nil
|
||||
},
|
||||
S: func(id *sql.NullInt64) (ValueScanID, error) {
|
||||
if !id.Valid {
|
||||
return ValueScanID{}, nil
|
||||
}
|
||||
return ValueScanID{V: int(id.Int64)}, nil
|
||||
},
|
||||
}),
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user