hook

package
v1.65.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 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 ArchiveFunc

type ArchiveFunc func(context.Context, *ent.ArchiveMutation) (ent.Value, error)

The ArchiveFunc type is an adapter to allow the use of ordinary function as Archive mutator.

func (ArchiveFunc) Mutate

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

Mutate calls f(ctx, m).

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 CommitRowFunc

type CommitRowFunc func(context.Context, *ent.CommitRowMutation) (ent.Value, error)

The CommitRowFunc type is an adapter to allow the use of ordinary function as CommitRow mutator.

func (CommitRowFunc) Mutate

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

type DamagedPathFunc func(context.Context, *ent.DamagedPathMutation) (ent.Value, error)

The DamagedPathFunc type is an adapter to allow the use of ordinary function as DamagedPath mutator.

func (DamagedPathFunc) Mutate

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

Mutate calls f(ctx, m).

type DeletedRefFunc

type DeletedRefFunc func(context.Context, *ent.DeletedRefMutation) (ent.Value, error)

The DeletedRefFunc type is an adapter to allow the use of ordinary function as DeletedRef mutator.

func (DeletedRefFunc) Mutate

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

Mutate calls f(ctx, m).

type FileFunc

type FileFunc func(context.Context, *ent.FileMutation) (ent.Value, error)

The FileFunc type is an adapter to allow the use of ordinary function as File mutator.

func (FileFunc) Mutate

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

Mutate calls f(ctx, m).

type ObjectFunc

type ObjectFunc func(context.Context, *ent.ObjectMutation) (ent.Value, error)

The ObjectFunc type is an adapter to allow the use of ordinary function as Object mutator.

func (ObjectFunc) Mutate

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

Mutate calls f(ctx, m).

type PinFunc

type PinFunc func(context.Context, *ent.PinMutation) (ent.Value, error)

The PinFunc type is an adapter to allow the use of ordinary function as Pin mutator.

func (PinFunc) Mutate

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

Mutate calls f(ctx, m).

type ReindexFunc

type ReindexFunc func(context.Context, *ent.ReindexMutation) (ent.Value, error)

The ReindexFunc type is an adapter to allow the use of ordinary function as Reindex mutator.

func (ReindexFunc) Mutate

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

Mutate calls f(ctx, m).

type SessionFunc

type SessionFunc func(context.Context, *ent.SessionMutation) (ent.Value, error)

The SessionFunc type is an adapter to allow the use of ordinary function as Session mutator.

func (SessionFunc) Mutate

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

Mutate calls f(ctx, m).

type SetFunc

type SetFunc func(context.Context, *ent.SetMutation) (ent.Value, error)

The SetFunc type is an adapter to allow the use of ordinary function as Set mutator.

func (SetFunc) Mutate

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

Mutate calls f(ctx, m).

type SetRefFunc

type SetRefFunc func(context.Context, *ent.SetRefMutation) (ent.Value, error)

The SetRefFunc type is an adapter to allow the use of ordinary function as SetRef mutator.

func (SetRefFunc) Mutate

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

Mutate calls f(ctx, m).

type SettingsFunc

type SettingsFunc func(context.Context, *ent.SettingsMutation) (ent.Value, error)

The SettingsFunc type is an adapter to allow the use of ordinary function as Settings mutator.

func (SettingsFunc) Mutate

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

Mutate calls f(ctx, m).

type TreeFunc

type TreeFunc func(context.Context, *ent.TreeMutation) (ent.Value, error)

The TreeFunc type is an adapter to allow the use of ordinary function as Tree mutator.

func (TreeFunc) Mutate

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

Mutate calls f(ctx, m).

type WalkedArchiveFunc

type WalkedArchiveFunc func(context.Context, *ent.WalkedArchiveMutation) (ent.Value, error)

The WalkedArchiveFunc type is an adapter to allow the use of ordinary function as WalkedArchive mutator.

func (WalkedArchiveFunc) Mutate

Mutate calls f(ctx, m).

Jump to

Keyboard shortcuts

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