schemast

package
v0.0.0-...-960bda7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotation

func Annotation(annot schema.Annotation) (ast.Expr, bool, error)

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.

func Index

func Index(desc *index.Descriptor) (*ast.CallExpr, error)

Index converts an *index.Descriptor back into an *ast.CallExpr of the ent Index package that can be used to construct it.

func Mutate

func Mutate(ctx *Context, mutations ...Mutator) error

Mutate applies a sequence of mutations to a Context

Types

type Annotator

type Annotator func(schema.Annotation) (ast.Expr, bool, error)

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

type Context struct {
	SchemaPackage *packages.Package
	// contains filtered or unexported fields
}

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 Load

func Load(path string) (*Context, error)

Load loads a *schemast.Context from a path.

func (*Context) AddType

func (c *Context) AddType(typeName string) error

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

func (c *Context) AppendIndex(typeName string, idx ent.Index) error

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) HasType

func (c *Context) HasType(typeName string) bool

HasType reports whether typeName is already defined in the Context.

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

func (c *Context) RemoveEdge(typeName string, edgeName string) error

RemoveEdge removes an edge from the returned values of the Edges method of type typeName.

func (*Context) RemoveField

func (c *Context) RemoveField(typeName string, fieldName string) error

RemoveField removes a field from the returned values of the Fields method of type typeName.

func (*Context) RemoveType

func (c *Context) RemoveType(typeName string) error

RemoveType removes the type definition as well as any method receivers or associated comment groups from the context.

type Mutator

type Mutator interface {
	Mutate(ctx *Context) error
}

Mutator changes a Context.

type PrintOption

type PrintOption func(opt *printOpts)

PrintOption modifies the behavior of Print.

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL