Documentation ¶
Index ¶
- func Generate(cfg Config) (err error)
- type Annotation
- func Input(opts ...InputOption) (a Annotation)
- func SkipClearingOptionalField() Annotation
- func SkipIO() (a Annotation)
- func SkipInput(opts ...InputOption) (a Annotation)
- func SkipOutput() (a Annotation)
- func SkipStoringField() Annotation
- func ValidateContext(fns ...func(context.Context) context.Context) (a Annotation)
- type Config
- type Hook
- type InputOption
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Annotation ¶
type Annotation = annotation.Annotation
Annotation alias the Annotation from entx/annotation package.
func Input ¶
func Input(opts ...InputOption) (a Annotation)
Input generates the immutable field or edge into *Input struct if no options are provided, otherwise, it applies the given options.
func SkipClearingOptionalField ¶
func SkipClearingOptionalField() Annotation
SkipClearingOptionalField skips generating cleaning if the mutable field is optional at updating.
If an optional mutable field annotates with SkipInput(WithUpdate()), it skips generating clearer as well.
By default, all optional fields will be cleared if the given update value is zero, to keep the previous value, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Optional(). Annotations( entx.SkipClearingOptionalField()), } }
To skip generating clearer for all optional mutable fields, you can declare to the struct annotation.
func SkipIO ¶
func SkipIO() (a Annotation)
SkipIO skips generating the field or edge into *Input and *Output struct.
func SkipInput ¶
func SkipInput(opts ...InputOption) (a Annotation)
SkipInput skips generating the field or reversible edge into *Input struct if no options are provided, otherwise, it applies the given options.
func SkipOutput ¶
func SkipOutput() (a Annotation)
SkipOutput skips generating the field or edge into *Output struct.
func SkipStoringField ¶
func SkipStoringField() Annotation
SkipStoringField treats the field as additional field, which is not stored in the database.
By default, all fields will be stored in the database, to keep the field in the struct only, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Annotations( entx.SkipStoringField()), } }
func ValidateContext ¶
func ValidateContext(fns ...func(context.Context) context.Context) (a Annotation)
ValidateContext indicates to call the given functions before validating *Input struct.
type Config ¶
type Config struct { // ProjectDir is the root path of the Go project. ProjectDir string // Project gains from the go.mod file of ProjectDir if blank. Project string // Package holds the Go package parent path for the API schema, // defaults to "<project>/dao", // which means the schema is placing under "<project>/dao/schema". Package string // Header allows users to provide an optional header signature for // the generated files. // format: '// Code generated by "walrus", DO NOT EDIT.'. Header string // Templates specifies a list of alternative templates to execute or // to override the default. If nil, the default template is used. // // Note that, additional templates are executed on the Graph object and // the execution output is stored in a file derived by the template name. Templates []*Template // Hooks holds an optional list of Hooks to apply on the graph before/after the code-generation. Hooks []Hook }
type InputOption ¶
type InputOption struct { SkipInput func(*Annotation) Input func(*Annotation) }
InputOption defines the stereotype for generate *Input struct.
func WithCreate ¶
func WithCreate() InputOption
WithCreate is an option works with SkipInput and Input.
By default, all fields will generate into its *CreateInput struct, to skip one field, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Annotations( entx.SkipInput(entx.WithCreate())), } }
By default, all reversible edges will generate into its *CreateInput struct as a prerequisite condition, to skip one reversible edge, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.From("groups", Group.Type). Ref("users"). Through("groupUserRelationships", GroupUserRelationship.Type), Annotations( entx.SkipInput(entx.WithCreate())), } }
By default, all reversible edges will generate into its *CreateInput struct as a prerequisite condition, to generate as an additional field, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.From("template", TemplateVersion.Type). Ref("services"). Annotations( entx.Input(entx.WithCreate())), } }
By default, all irreversible edges will not generate into its *CreateInput struct as an additional fields, to skip one irreversible edge, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.To("spouse", User.Type). Unique(). Field("spouseID"). Annotations( entx.SkipInput(entx.WithCreate())), } }
func WithQuery ¶
func WithQuery() InputOption
WithQuery is an option works with SkipInput and Input.
By default, all non-indexing fields don't be generated into *QueryInput struct to generate one non-indexing field, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Annotations( entx.Input(entx.WithQuery())), } }
By default, all fields of the longest index will generate into its *QueryInput struct, to skip one index, for example:
func (Todo) Indexes() []ent.Index { return []ent.Index{ index.Fields("name"). Annotations( entx.SkipInput(entx.WithQuery())), } }
By default, all reversible edges will generate into its *QueryInput struct as a prerequisite condition, to skip one reversible edge, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.From("owner", User.Type). Required(). Ref("pets"). Field("ownerID"). Annotations( entx.SkipInput(entx.WithQuery())), } }
func WithUpdate ¶
func WithUpdate() InputOption
WithUpdate is an option works with SkipInput and Input.
By default, all immutable fields don't be generated into *UpdateInput struct, to generate one immutable field, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Immutable(). Annotations( entx.Input(entx.WithUpdate())), } }
By default, all mutable fields will generate into its *UpdateInput struct, to skip one field, for example:
func (Todo) Fields() []ent.Field { return []ent.Field{ field.String("health"). Annotations( entx.SkipInput(entx.WithUpdate())), } }
By default, all reversible edges will generate into its *UpdateInput struct as a prerequisite condition, to skip one reversible edge, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.From("owner", User.Type). Required(). Ref("pets"). Field("ownerID"). Annotations( entx.SkipInput(entx.WithUpdate())), } }
By default, all reversible edges will generate into its *CreateInput struct as a prerequisite condition, to generate as an additional field, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.From("template", TemplateVersion.Type). Ref("services"). Annotations( entx.Input(entx.WithUpdate())), } }
By default, all mutable irreversible edges will not generate into its *UpdateInput struct as an additional fields, to generate one mutable irreversible edge, for example:
func (Todo) Edges() []ent.Edge { return []ent.Edge{ edge.To("spouse", User.Type). Unique(). Field("spouseID"). Annotations( entx.SkipInput(entx.WithUpdate())), } }