hook

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 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) gen.Hook

FixedError is a hook returning a fixed error.

func If

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

If executes the given hook under condition.

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

func On

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

On executes the given hook only for the given operation.

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

func Reject

func Reject(op gen.Op) gen.Hook

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

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

func Unless

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

Unless skips the given hook only for the given operation.

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

Types

type BreedFunc

type BreedFunc func(context.Context, *gen.BreedMutation) (gen.Value, error)

The BreedFunc type is an adapter to allow the use of ordinary function as Breed mutator.

func (BreedFunc) Mutate

func (f BreedFunc) Mutate(ctx context.Context, m gen.Mutation) (gen.Value, error)

Mutate calls f(ctx, m).

type CatFunc

type CatFunc func(context.Context, *gen.CatMutation) (gen.Value, error)

The CatFunc type is an adapter to allow the use of ordinary function as Cat mutator.

func (CatFunc) Mutate

func (f CatFunc) Mutate(ctx context.Context, m gen.Mutation) (gen.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 ...gen.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

func (c Chain) Append(hooks ...gen.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() gen.Hook

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

type Condition

type Condition func(context.Context, gen.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 gen.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 FatherCatFunc

type FatherCatFunc func(context.Context, *gen.FatherCatMutation) (gen.Value, error)

The FatherCatFunc type is an adapter to allow the use of ordinary function as FatherCat mutator.

func (FatherCatFunc) Mutate

func (f FatherCatFunc) Mutate(ctx context.Context, m gen.Mutation) (gen.Value, error)

Mutate calls f(ctx, m).

type KittenFunc

type KittenFunc func(context.Context, *gen.KittenMutation) (gen.Value, error)

The KittenFunc type is an adapter to allow the use of ordinary function as Kitten mutator.

func (KittenFunc) Mutate

func (f KittenFunc) Mutate(ctx context.Context, m gen.Mutation) (gen.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