-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathent.go
163 lines (149 loc) · 3.79 KB
/
ent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// 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 ent is the interface between end-user schemas and entc (ent codegen).
package ent
import (
"github.com/facebookincubator/ent/schema/edge"
"github.com/facebookincubator/ent/schema/field"
"github.com/facebookincubator/ent/schema/index"
)
type (
// The Interface type describes the requirements for an exported type defined in the schema package.
// It functions as the interface between the user's schema types and codegen loader.
// Users should use the Schema type for embedding as follows:
//
// type T struct {
// ent.Schema
// }
//
Interface interface {
// Type is a dummy method, that is used in edge declaration.
//
// The Type method should be used as follows:
//
// type S struct { ent.Schema }
//
// type T struct { ent.Schema }
//
// func (T) Edges() []ent.Edge {
// return []ent.Edge{
// edge.To("S", S.Type),
// }
// }
//
Type()
// Fields returns the fields of the schema.
Fields() []Field
// Edges returns the edges of the schema.
Edges() []Edge
// Indexes returns the indexes of the schema.
Indexes() []Index
// Config returns an optional config for the schema.
Config() Config
// Mixin returns an optional list of Mixin to extends
// the schema.
Mixin() []Mixin
}
// A Field interface returns a field descriptor for vertex fields/properties.
// The usage for the interface is as follows:
//
// func (T) Fields() []ent.Field {
// return []ent.Field{
// field.Int("int"),
// }
// }
//
Field interface {
Descriptor() *field.Descriptor
}
// A Edge interface returns an edge descriptor for vertex edges.
// The usage for the interface is as follows:
//
// func (T) Edges() []ent.Edge {
// return []ent.Edge{
// edge.To("S", S.Type),
// }
// }
//
Edge interface {
Descriptor() *edge.Descriptor
}
// A Index interface returns an index descriptor for vertex indexes.
// The usage for the interface is as follows:
//
// func (T) Indexes() []ent.Index {
// return []ent.Index{
// index.Fields("f1", "f2").
// Unique(),
// }
// }
//
Index interface {
Descriptor() *index.Descriptor
}
// A Config structure is used to configure an entity schema.
// The usage of this structure is as follows:
//
// func (T) Config() ent.Config {
// return ent.Config{
// Table: "Name",
// }
// }
//
Config struct {
// A Table is an optional table name defined for the schema.
Table string
}
// The Mixin type describes a set of methods that can extend
// other methods in the schema without calling them directly.
//
// type TimeMixin struct {}
//
// func (TimeMixin) Fields() []ent.Field {
// return []ent.Field{
// field.Time("created_at").
// Immutable().
// Default(time.Now),
// field.Time("updated_at").
// Default(time.Now).
// UpdateDefault(time.Now),
// }
// }
//
// type T struct {
// ent.Schema
// }
//
// func(T) Mixin() []ent.Mixin {
// return []ent.Mixin{
// TimeMixin{},
// }
// }
//
Mixin interface {
// Fields returns a slice of fields to be added
// to the schema fields.
Fields() []Field
}
// Schema is the default implementation for the schema Interface.
// It can be embedded in end-user schemas as follows:
//
// type T struct {
// ent.Schema
// }
//
Schema struct {
Interface
}
)
// Fields of the schema.
func (Schema) Fields() []Field { return nil }
// Edges of the schema.
func (Schema) Edges() []Edge { return nil }
// Indexes of the schema.
func (Schema) Indexes() []Index { return nil }
// Config of the schema.
func (Schema) Config() Config { return Config{} }
// Mixin of the schema.
func (Schema) Mixin() []Mixin { return nil }