mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
ent/doc: add indexes doc and example
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1380 Reviewed By: alexsn Differential Revision: D17075317 fbshipit-source-id: 021cb0bde3849af5a5d842b715a7b7dbd861c54f
This commit is contained in:
committed by
Facebook Github Bot
parent
373769dfaf
commit
e00a7d96a4
30
examples/edgeindex/ent/schema/city.go
Normal file
30
examples/edgeindex/ent/schema/city.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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 (
|
||||
"github.com/facebookincubator/ent"
|
||||
"github.com/facebookincubator/ent/schema/edge"
|
||||
"github.com/facebookincubator/ent/schema/field"
|
||||
)
|
||||
|
||||
// City holds the schema definition for the City entity.
|
||||
type City struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the City.
|
||||
func (City) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the City.
|
||||
func (City) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("streets", Street.Type),
|
||||
}
|
||||
}
|
||||
42
examples/edgeindex/ent/schema/street.go
Normal file
42
examples/edgeindex/ent/schema/street.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 (
|
||||
"github.com/facebookincubator/ent"
|
||||
"github.com/facebookincubator/ent/schema/edge"
|
||||
"github.com/facebookincubator/ent/schema/field"
|
||||
"github.com/facebookincubator/ent/schema/index"
|
||||
)
|
||||
|
||||
// Street holds the schema definition for the Street entity.
|
||||
type Street struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Street.
|
||||
func (Street) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Street.
|
||||
func (Street) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("city", City.Type).
|
||||
Ref("streets").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Street.
|
||||
func (Street) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("name").
|
||||
Edges("city").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user