hook

package
v5.0.0-beta.22 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: AGPL-3.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 AccessTokenFunc

type AccessTokenFunc func(context.Context, *ent.AccessTokenMutation) (ent.Value, error)

The AccessTokenFunc type is an adapter to allow the use of ordinary function as AccessToken mutator.

func (AccessTokenFunc) Mutate

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

Mutate calls f(ctx, m).

type CacheLockFunc

type CacheLockFunc func(context.Context, *ent.CacheLockMutation) (ent.Value, error)

The CacheLockFunc type is an adapter to allow the use of ordinary function as CacheLock mutator.

func (CacheLockFunc) Mutate

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

type ChangelogFunc func(context.Context, *ent.ChangelogMutation) (ent.Value, error)

The ChangelogFunc type is an adapter to allow the use of ordinary function as Changelog mutator.

func (ChangelogFunc) Mutate

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

type DBCacheFunc func(context.Context, *ent.DBCacheMutation) (ent.Value, error)

The DBCacheFunc type is an adapter to allow the use of ordinary function as DBCache mutator.

func (DBCacheFunc) Mutate

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

Mutate calls f(ctx, m).

type EventFunc

type EventFunc func(context.Context, *ent.EventMutation) (ent.Value, error)

The EventFunc type is an adapter to allow the use of ordinary function as Event mutator.

func (EventFunc) Mutate

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

Mutate calls f(ctx, m).

type FavoriteFunc

type FavoriteFunc func(context.Context, *ent.FavoriteMutation) (ent.Value, error)

The FavoriteFunc type is an adapter to allow the use of ordinary function as Favorite mutator.

func (FavoriteFunc) Mutate

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

type MemberFunc func(context.Context, *ent.MemberMutation) (ent.Value, error)

The MemberFunc type is an adapter to allow the use of ordinary function as Member mutator.

func (MemberFunc) Mutate

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

Mutate calls f(ctx, m).

type NamespaceFunc

type NamespaceFunc func(context.Context, *ent.NamespaceMutation) (ent.Value, error)

The NamespaceFunc type is an adapter to allow the use of ordinary function as Namespace mutator.

func (NamespaceFunc) Mutate

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

Mutate calls f(ctx, m).

type ProjectFunc

type ProjectFunc func(context.Context, *ent.ProjectMutation) (ent.Value, error)

The ProjectFunc type is an adapter to allow the use of ordinary function as Project mutator.

func (ProjectFunc) Mutate

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

Mutate calls f(ctx, m).

type RepoFunc

type RepoFunc func(context.Context, *ent.RepoMutation) (ent.Value, error)

The RepoFunc type is an adapter to allow the use of ordinary function as Repo mutator.

func (RepoFunc) Mutate

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