hook

package
v0.0.0-...-7acab80 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixedError

func FixedError(err error) ent.Hook

FixedError is a hook returning a fixed error.

func If

func If(hk ent.Hook, cond Condition) ent.Hook

If executes the given hook under condition.

hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))

func On

func On(hk ent.Hook, op ent.Op) ent.Hook

On executes the given hook only for the given operation.

hook.On(Log, ent.Delete|ent.Create)

func Reject

func Reject(op ent.Op) ent.Hook

Reject returns a hook that rejects all operations that match op.

func (T) Hooks() []ent.Hook {
	return []ent.Hook{
		Reject(ent.Delete|ent.Update),
	}
}

func Unless

func Unless(hk ent.Hook, op ent.Op) ent.Hook

Unless skips the given hook only for the given operation.

hook.Unless(Log, ent.Update|ent.UpdateOne)

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain acts as a list of hooks and is effectively immutable. Once created, it will always hold the same set of hooks in the same order.

func NewChain

func NewChain(hooks ...ent.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

func (c Chain) Append(hooks ...ent.Hook) Chain

Append extends a chain, adding the specified hook as the last ones in the mutation flow.

func (Chain) Extend

func (c Chain) Extend(chain Chain) Chain

Extend extends a chain, adding the specified chain as the last ones in the mutation flow.

func (Chain) Hook

func (c Chain) Hook() ent.Hook

Hook chains the list of hooks and returns the final hook.

type Condition

type Condition func(context.Context, ent.Mutation) bool

Condition is a hook condition function.

func And

func And(first, second Condition, rest ...Condition) Condition

And groups conditions with the AND operator.

func HasAddedFields

func HasAddedFields(field string, fields ...string) Condition

HasAddedFields is a condition validating `.AddedField` on fields.

func HasClearedFields

func HasClearedFields(field string, fields ...string) Condition

HasClearedFields is a condition validating `.FieldCleared` on fields.

func HasFields

func HasFields(field string, fields ...string) Condition

HasFields is a condition validating `.Field` on fields.

func HasOp

func HasOp(op ent.Op) Condition

HasOp is a condition testing mutation operation.

func Not

func Not(cond Condition) Condition

Not negates a given condition.

func Or

func Or(first, second Condition, rest ...Condition) Condition

Or groups conditions with the OR operator.

type DocumentFunc

type DocumentFunc func(context.Context, *ent.DocumentMutation) (ent.Value, error)

The DocumentFunc type is an adapter to allow the use of ordinary function as Document mutator.

func (DocumentFunc) Mutate

func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type DocumentTypeFunc

type DocumentTypeFunc func(context.Context, *ent.DocumentTypeMutation) (ent.Value, error)

The DocumentTypeFunc type is an adapter to allow the use of ordinary function as DocumentType mutator.

func (DocumentTypeFunc) Mutate

func (f DocumentTypeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type EdgeTypeFunc

type EdgeTypeFunc func(context.Context, *ent.EdgeTypeMutation) (ent.Value, error)

The EdgeTypeFunc type is an adapter to allow the use of ordinary function as EdgeType mutator.

func (EdgeTypeFunc) Mutate

func (f EdgeTypeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type ExternalReferenceFunc

type ExternalReferenceFunc func(context.Context, *ent.ExternalReferenceMutation) (ent.Value, error)

The ExternalReferenceFunc type is an adapter to allow the use of ordinary function as ExternalReference mutator.

func (ExternalReferenceFunc) Mutate

Mutate calls f(ctx, m).

type HashesEntryFunc

type HashesEntryFunc func(context.Context, *ent.HashesEntryMutation) (ent.Value, error)

The HashesEntryFunc type is an adapter to allow the use of ordinary function as HashesEntry mutator.

func (HashesEntryFunc) Mutate

func (f HashesEntryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type IdentifiersEntryFunc

type IdentifiersEntryFunc func(context.Context, *ent.IdentifiersEntryMutation) (ent.Value, error)

The IdentifiersEntryFunc type is an adapter to allow the use of ordinary function as IdentifiersEntry mutator.

func (IdentifiersEntryFunc) Mutate

Mutate calls f(ctx, m).

type MetadataFunc

type MetadataFunc func(context.Context, *ent.MetadataMutation) (ent.Value, error)

The MetadataFunc type is an adapter to allow the use of ordinary function as Metadata mutator.

func (MetadataFunc) Mutate

func (f MetadataFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type NodeFunc

type NodeFunc func(context.Context, *ent.NodeMutation) (ent.Value, error)

The NodeFunc type is an adapter to allow the use of ordinary function as Node mutator.

func (NodeFunc) Mutate

func (f NodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type NodeListFunc

type NodeListFunc func(context.Context, *ent.NodeListMutation) (ent.Value, error)

The NodeListFunc type is an adapter to allow the use of ordinary function as NodeList mutator.

func (NodeListFunc) Mutate

func (f NodeListFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type PersonFunc

type PersonFunc func(context.Context, *ent.PersonMutation) (ent.Value, error)

The PersonFunc type is an adapter to allow the use of ordinary function as Person mutator.

func (PersonFunc) Mutate

func (f PersonFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type PurposeFunc

type PurposeFunc func(context.Context, *ent.PurposeMutation) (ent.Value, error)

The PurposeFunc type is an adapter to allow the use of ordinary function as Purpose mutator.

func (PurposeFunc) Mutate

func (f PurposeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type ToolFunc

type ToolFunc func(context.Context, *ent.ToolMutation) (ent.Value, error)

The ToolFunc type is an adapter to allow the use of ordinary function as Tool mutator.

func (ToolFunc) Mutate

func (f ToolFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

Jump to

Keyboard shortcuts

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