hook

package
v0.0.0-...-c3b95e6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 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) db.Hook

FixedError is a hook returning a fixed error.

func If

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

If executes the given hook under condition.

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

func On

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

On executes the given hook only for the given operation.

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

func Reject

func Reject(op db.Op) db.Hook

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

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

func Unless

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

Unless skips the given hook only for the given operation.

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

Types

type AuthCodeFunc

type AuthCodeFunc func(context.Context, *db.AuthCodeMutation) (db.Value, error)

The AuthCodeFunc type is an adapter to allow the use of ordinary function as AuthCode mutator.

func (AuthCodeFunc) Mutate

func (f AuthCodeFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type AuthRequestFunc

type AuthRequestFunc func(context.Context, *db.AuthRequestMutation) (db.Value, error)

The AuthRequestFunc type is an adapter to allow the use of ordinary function as AuthRequest mutator.

func (AuthRequestFunc) Mutate

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

NewChain creates a new chain of hooks.

func (Chain) Append

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

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

type Condition

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

type ConnectorFunc func(context.Context, *db.ConnectorMutation) (db.Value, error)

The ConnectorFunc type is an adapter to allow the use of ordinary function as Connector mutator.

func (ConnectorFunc) Mutate

func (f ConnectorFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type DeviceRequestFunc

type DeviceRequestFunc func(context.Context, *db.DeviceRequestMutation) (db.Value, error)

The DeviceRequestFunc type is an adapter to allow the use of ordinary function as DeviceRequest mutator.

func (DeviceRequestFunc) Mutate

func (f DeviceRequestFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type DeviceTokenFunc

type DeviceTokenFunc func(context.Context, *db.DeviceTokenMutation) (db.Value, error)

The DeviceTokenFunc type is an adapter to allow the use of ordinary function as DeviceToken mutator.

func (DeviceTokenFunc) Mutate

func (f DeviceTokenFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type KeysFunc

type KeysFunc func(context.Context, *db.KeysMutation) (db.Value, error)

The KeysFunc type is an adapter to allow the use of ordinary function as Keys mutator.

func (KeysFunc) Mutate

func (f KeysFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type OAuth2ClientFunc

type OAuth2ClientFunc func(context.Context, *db.OAuth2ClientMutation) (db.Value, error)

The OAuth2ClientFunc type is an adapter to allow the use of ordinary function as OAuth2Client mutator.

func (OAuth2ClientFunc) Mutate

func (f OAuth2ClientFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type OfflineSessionFunc

type OfflineSessionFunc func(context.Context, *db.OfflineSessionMutation) (db.Value, error)

The OfflineSessionFunc type is an adapter to allow the use of ordinary function as OfflineSession mutator.

func (OfflineSessionFunc) Mutate

func (f OfflineSessionFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type PasswordFunc

type PasswordFunc func(context.Context, *db.PasswordMutation) (db.Value, error)

The PasswordFunc type is an adapter to allow the use of ordinary function as Password mutator.

func (PasswordFunc) Mutate

func (f PasswordFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type RefreshTokenFunc

type RefreshTokenFunc func(context.Context, *db.RefreshTokenMutation) (db.Value, error)

The RefreshTokenFunc type is an adapter to allow the use of ordinary function as RefreshToken mutator.

func (RefreshTokenFunc) Mutate

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