Documentation ¶
Index ¶
- func Annotation(annot schema.Annotation) (ast.Expr, bool, error)
- func Edge(desc *edge.Descriptor) (*ast.CallExpr, error)
- func Field(desc *field.Descriptor) (*ast.CallExpr, error)
- func Index(desc *index.Descriptor) (*ast.CallExpr, error)
- func Mutate(ctx *Context, mutations ...Mutator) error
- type Annotator
- type Context
- func (c *Context) AddType(typeName string) error
- func (c *Context) AppendEdge(typeName string, desc *edge.Descriptor) error
- func (c *Context) AppendField(typeName string, desc *field.Descriptor) error
- func (c *Context) AppendIndex(typeName string, idx ent.Index) error
- func (c *Context) AppendTypeAnnotation(typeName string, annot schema.Annotation) error
- func (c *Context) HasType(typeName string) bool
- func (c *Context) Print(path string, opts ...PrintOption) error
- func (c *Context) RemoveEdge(typeName string, edgeName string) error
- func (c *Context) RemoveField(typeName string, fieldName string) error
- func (c *Context) RemoveType(typeName string) error
- type Mutator
- type PrintOption
- type UnsupportedAnnotationError
- type UpsertSchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotation ¶
Annotation is an Annotator that searches a map of well-known ent annotation (entproto, entsql, etc.) and invokes that Annotator if found.
func Edge ¶
func Edge(desc *edge.Descriptor) (*ast.CallExpr, error)
Edge converts a *edge.Descriptor back into an *ast.CallExpr of the ent edge package that can be used to construct it.
func Field ¶
func Field(desc *field.Descriptor) (*ast.CallExpr, error)
Field converts a *field.Descriptor back into an *ast.CallExpr of the ent field package that can be used to construct it.
Types ¶
type Annotator ¶
Annotator takes a schema.Annotation and returns an AST node that can be used to build that annotation. In addition, Annotator reports whether an AST node should be created or not. If the passed schema.Annotation is not supported by the Annotator, it returns UnsupportedAnnotationError.
type Context ¶
Context represents an ent schema directory, parsed and loaded as ASTs, such that schema type declarations can be analyzed an manipulated by different programs.
func (*Context) AppendEdge ¶
func (c *Context) AppendEdge(typeName string, desc *edge.Descriptor) error
AppendEdge adds an edge to the returned values of the Edges method of type typeName.
func (*Context) AppendField ¶
func (c *Context) AppendField(typeName string, desc *field.Descriptor) error
AppendField adds a field to the returned values of the Fields method of type typeName.
func (*Context) AppendIndex ¶
AppendIndex adds an index to the returned values of the Indexes method of type typeName.
func (*Context) AppendTypeAnnotation ¶
func (c *Context) AppendTypeAnnotation(typeName string, annot schema.Annotation) error
func (*Context) Print ¶
func (c *Context) Print(path string, opts ...PrintOption) error
Print writes the updated .go files from Context into path, the directory for the "schema" package in an ent project. Print receives functional options of type PrintOption that modify its behavior.
func (*Context) RemoveEdge ¶
RemoveEdge removes an edge from the returned values of the Edges method of type typeName.
func (*Context) RemoveField ¶
RemoveField removes a field from the returned values of the Fields method of type typeName.
func (*Context) RemoveType ¶
RemoveType removes the type definition as well as any method receivers or associated comment groups from the context.
type PrintOption ¶
type PrintOption func(opt *printOpts)
PrintOption modifies the behavior of Print.
func Header ¶
func Header(c string) PrintOption
Header modifies Print to include a comment at the top of the printed .go files. If the file already contains the comment, even if it is not located at the very top of the file the comment will not be appended. Example:
ctx.Print("./schema", schemast.Header("File generated with ent-codegen-plugin.")
type UnsupportedAnnotationError ¶
type UnsupportedAnnotationError struct {
// contains filtered or unexported fields
}
func (*UnsupportedAnnotationError) Error ¶
func (e *UnsupportedAnnotationError) Error() string
type UpsertSchema ¶
type UpsertSchema struct { Name string Fields []ent.Field Edges []ent.Edge Indexes []ent.Index Annotations []schema.Annotation }
UpsertSchema implements Mutator. UpsertSchema will add to the Context the type named Name if not present and rewrite the type's Fields and Edges methods to return the desired fields and edges.
func (*UpsertSchema) Mutate ¶
func (u *UpsertSchema) Mutate(ctx *Context) error
Mutate applies the UpsertSchema mutation to the Context.