hook

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT 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 CommentFunc

type CommentFunc func(context.Context, *ent.CommentMutation) (ent.Value, error)

The CommentFunc type is an adapter to allow the use of ordinary function as Comment mutator.

func (CommentFunc) Mutate

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

Mutate calls f(ctx, m).

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 EpicFunc

type EpicFunc func(context.Context, *ent.EpicMutation) (ent.Value, error)

The EpicFunc type is an adapter to allow the use of ordinary function as Epic mutator.

func (EpicFunc) Mutate

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

Mutate calls f(ctx, m).

type FeatureFunc

type FeatureFunc func(context.Context, *ent.FeatureMutation) (ent.Value, error)

The FeatureFunc type is an adapter to allow the use of ordinary function as Feature mutator.

func (FeatureFunc) Mutate

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

Mutate calls f(ctx, m).

type GoalFunc

type GoalFunc func(context.Context, *ent.GoalMutation) (ent.Value, error)

The GoalFunc type is an adapter to allow the use of ordinary function as Goal mutator.

func (GoalFunc) Mutate

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

Mutate calls f(ctx, m).

type IdeaEndorsementFunc

type IdeaEndorsementFunc func(context.Context, *ent.IdeaEndorsementMutation) (ent.Value, error)

The IdeaEndorsementFunc type is an adapter to allow the use of ordinary function as IdeaEndorsement mutator.

func (IdeaEndorsementFunc) Mutate

Mutate calls f(ctx, m).

type IdeaFunc

type IdeaFunc func(context.Context, *ent.IdeaMutation) (ent.Value, error)

The IdeaFunc type is an adapter to allow the use of ordinary function as Idea mutator.

func (IdeaFunc) Mutate

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

Mutate calls f(ctx, m).

type IdeaOrganizationFunc

type IdeaOrganizationFunc func(context.Context, *ent.IdeaOrganizationMutation) (ent.Value, error)

The IdeaOrganizationFunc type is an adapter to allow the use of ordinary function as IdeaOrganization mutator.

func (IdeaOrganizationFunc) Mutate

Mutate calls f(ctx, m).

type IdeaUserFunc

type IdeaUserFunc func(context.Context, *ent.IdeaUserMutation) (ent.Value, error)

The IdeaUserFunc type is an adapter to allow the use of ordinary function as IdeaUser mutator.

func (IdeaUserFunc) Mutate

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

Mutate calls f(ctx, m).

type InitiativeFunc

type InitiativeFunc func(context.Context, *ent.InitiativeMutation) (ent.Value, error)

The InitiativeFunc type is an adapter to allow the use of ordinary function as Initiative mutator.

func (InitiativeFunc) Mutate

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

Mutate calls f(ctx, m).

type ProductFunc

type ProductFunc func(context.Context, *ent.ProductMutation) (ent.Value, error)

The ProductFunc type is an adapter to allow the use of ordinary function as Product mutator.

func (ProductFunc) Mutate

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

Mutate calls f(ctx, m).

type RelationshipFunc

type RelationshipFunc func(context.Context, *ent.RelationshipMutation) (ent.Value, error)

The RelationshipFunc type is an adapter to allow the use of ordinary function as Relationship mutator.

func (RelationshipFunc) Mutate

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

Mutate calls f(ctx, m).

type ReleaseFunc

type ReleaseFunc func(context.Context, *ent.ReleaseMutation) (ent.Value, error)

The ReleaseFunc type is an adapter to allow the use of ordinary function as Release mutator.

func (ReleaseFunc) Mutate

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

Mutate calls f(ctx, m).

type RequirementFunc

type RequirementFunc func(context.Context, *ent.RequirementMutation) (ent.Value, error)

The RequirementFunc type is an adapter to allow the use of ordinary function as Requirement mutator.

func (RequirementFunc) Mutate

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

Mutate calls f(ctx, m).

type SavedFilterFunc

type SavedFilterFunc func(context.Context, *ent.SavedFilterMutation) (ent.Value, error)

The SavedFilterFunc type is an adapter to allow the use of ordinary function as SavedFilter mutator.

func (SavedFilterFunc) Mutate

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

Mutate calls f(ctx, m).

type SyncMetaFunc

type SyncMetaFunc func(context.Context, *ent.SyncMetaMutation) (ent.Value, error)

The SyncMetaFunc type is an adapter to allow the use of ordinary function as SyncMeta mutator.

func (SyncMetaFunc) Mutate

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

Mutate calls f(ctx, m).

type UserFunc

type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)

The UserFunc type is an adapter to allow the use of ordinary function as User mutator.

func (UserFunc) Mutate

func (f UserFunc) 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