hook

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 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 AccountFunc

type AccountFunc func(context.Context, *ent.AccountMutation) (ent.Value, error)

The AccountFunc type is an adapter to allow the use of ordinary function as Account mutator.

func (AccountFunc) Mutate

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

Mutate calls f(ctx, m).

type BlobFunc

type BlobFunc func(context.Context, *ent.BlobMutation) (ent.Value, error)

The BlobFunc type is an adapter to allow the use of ordinary function as Blob mutator.

func (BlobFunc) Mutate

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

Mutate calls f(ctx, m).

type CarFunc

type CarFunc func(context.Context, *ent.CarMutation) (ent.Value, error)

The CarFunc type is an adapter to allow the use of ordinary function as Car mutator.

func (CarFunc) Mutate

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

type DeviceFunc func(context.Context, *ent.DeviceMutation) (ent.Value, error)

The DeviceFunc type is an adapter to allow the use of ordinary function as Device mutator.

func (DeviceFunc) Mutate

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

Mutate calls f(ctx, m).

type DocFunc

type DocFunc func(context.Context, *ent.DocMutation) (ent.Value, error)

The DocFunc type is an adapter to allow the use of ordinary function as Doc mutator.

func (DocFunc) Mutate

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

Mutate calls f(ctx, m).

type GroupFunc

type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)

The GroupFunc type is an adapter to allow the use of ordinary function as Group mutator.

func (GroupFunc) Mutate

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

Mutate calls f(ctx, m).

type MixinIDFunc

type MixinIDFunc func(context.Context, *ent.MixinIDMutation) (ent.Value, error)

The MixinIDFunc type is an adapter to allow the use of ordinary function as MixinID mutator.

func (MixinIDFunc) Mutate

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

Mutate calls f(ctx, m).

type NoteFunc

type NoteFunc func(context.Context, *ent.NoteMutation) (ent.Value, error)

The NoteFunc type is an adapter to allow the use of ordinary function as Note mutator.

func (NoteFunc) Mutate

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

Mutate calls f(ctx, m).

type OtherFunc

type OtherFunc func(context.Context, *ent.OtherMutation) (ent.Value, error)

The OtherFunc type is an adapter to allow the use of ordinary function as Other mutator.

func (OtherFunc) Mutate

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

Mutate calls f(ctx, m).

type PetFunc

type PetFunc func(context.Context, *ent.PetMutation) (ent.Value, error)

The PetFunc type is an adapter to allow the use of ordinary function as Pet mutator.

func (PetFunc) Mutate

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

type TokenFunc func(context.Context, *ent.TokenMutation) (ent.Value, error)

The TokenFunc type is an adapter to allow the use of ordinary function as Token mutator.

func (TokenFunc) Mutate

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