hook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 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) 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 APIKeyFunc

type APIKeyFunc func(context.Context, *ent.APIKeyMutation) (ent.Value, error)

The APIKeyFunc type is an adapter to allow the use of ordinary function as APIKey mutator.

func (APIKeyFunc) Mutate

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

Mutate calls f(ctx, m).

type AgentFunc added in v0.2.0

type AgentFunc func(context.Context, *ent.AgentMutation) (ent.Value, error)

The AgentFunc type is an adapter to allow the use of ordinary function as Agent mutator.

func (AgentFunc) Mutate added in v0.2.0

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

Mutate calls f(ctx, m).

type ApplicationFunc added in v0.2.0

type ApplicationFunc func(context.Context, *ent.ApplicationMutation) (ent.Value, error)

The ApplicationFunc type is an adapter to allow the use of ordinary function as Application mutator.

func (ApplicationFunc) Mutate added in v0.2.0

func (f ApplicationFunc) 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 CredentialFunc added in v0.2.0

type CredentialFunc func(context.Context, *ent.CredentialMutation) (ent.Value, error)

The CredentialFunc type is an adapter to allow the use of ordinary function as Credential mutator.

func (CredentialFunc) Mutate added in v0.2.0

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

Mutate calls f(ctx, m).

type HumanFunc added in v0.2.0

type HumanFunc func(context.Context, *ent.HumanMutation) (ent.Value, error)

The HumanFunc type is an adapter to allow the use of ordinary function as Human mutator.

func (HumanFunc) Mutate added in v0.2.0

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

Mutate calls f(ctx, m).

type InviteFunc added in v0.2.0

type InviteFunc func(context.Context, *ent.InviteMutation) (ent.Value, error)

The InviteFunc type is an adapter to allow the use of ordinary function as Invite mutator.

func (InviteFunc) Mutate added in v0.2.0

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

Mutate calls f(ctx, m).

type MembershipFunc

type MembershipFunc func(context.Context, *ent.MembershipMutation) (ent.Value, error)

The MembershipFunc type is an adapter to allow the use of ordinary function as Membership mutator.

func (MembershipFunc) Mutate

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

Mutate calls f(ctx, m).

type OAuthAccountFunc

type OAuthAccountFunc func(context.Context, *ent.OAuthAccountMutation) (ent.Value, error)

The OAuthAccountFunc type is an adapter to allow the use of ordinary function as OAuthAccount mutator.

func (OAuthAccountFunc) Mutate

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

Mutate calls f(ctx, m).

type OAuthAppFunc

type OAuthAppFunc func(context.Context, *ent.OAuthAppMutation) (ent.Value, error)

The OAuthAppFunc type is an adapter to allow the use of ordinary function as OAuthApp mutator.

func (OAuthAppFunc) Mutate

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

Mutate calls f(ctx, m).

type OAuthAppSecretFunc

type OAuthAppSecretFunc func(context.Context, *ent.OAuthAppSecretMutation) (ent.Value, error)

The OAuthAppSecretFunc type is an adapter to allow the use of ordinary function as OAuthAppSecret mutator.

func (OAuthAppSecretFunc) Mutate

Mutate calls f(ctx, m).

type OAuthAuthCodeFunc

type OAuthAuthCodeFunc func(context.Context, *ent.OAuthAuthCodeMutation) (ent.Value, error)

The OAuthAuthCodeFunc type is an adapter to allow the use of ordinary function as OAuthAuthCode mutator.

func (OAuthAuthCodeFunc) Mutate

Mutate calls f(ctx, m).

type OAuthConsentFunc

type OAuthConsentFunc func(context.Context, *ent.OAuthConsentMutation) (ent.Value, error)

The OAuthConsentFunc type is an adapter to allow the use of ordinary function as OAuthConsent mutator.

func (OAuthConsentFunc) Mutate

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

Mutate calls f(ctx, m).

type OAuthTokenFunc

type OAuthTokenFunc func(context.Context, *ent.OAuthTokenMutation) (ent.Value, error)

The OAuthTokenFunc type is an adapter to allow the use of ordinary function as OAuthToken mutator.

func (OAuthTokenFunc) Mutate

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

Mutate calls f(ctx, m).

type OrganizationFunc

type OrganizationFunc func(context.Context, *ent.OrganizationMutation) (ent.Value, error)

The OrganizationFunc type is an adapter to allow the use of ordinary function as Organization mutator.

func (OrganizationFunc) Mutate

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

Mutate calls f(ctx, m).

type PrincipalFunc added in v0.2.0

type PrincipalFunc func(context.Context, *ent.PrincipalMutation) (ent.Value, error)

The PrincipalFunc type is an adapter to allow the use of ordinary function as Principal mutator.

func (PrincipalFunc) Mutate added in v0.2.0

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

Mutate calls f(ctx, m).

type PrincipalMembershipFunc added in v0.2.0

type PrincipalMembershipFunc func(context.Context, *ent.PrincipalMembershipMutation) (ent.Value, error)

The PrincipalMembershipFunc type is an adapter to allow the use of ordinary function as PrincipalMembership mutator.

func (PrincipalMembershipFunc) Mutate added in v0.2.0

Mutate calls f(ctx, m).

type PrincipalTokenFunc added in v0.2.0

type PrincipalTokenFunc func(context.Context, *ent.PrincipalTokenMutation) (ent.Value, error)

The PrincipalTokenFunc type is an adapter to allow the use of ordinary function as PrincipalToken mutator.

func (PrincipalTokenFunc) Mutate added in v0.2.0

Mutate calls f(ctx, m).

type RefreshTokenFunc

type RefreshTokenFunc func(context.Context, *ent.RefreshTokenMutation) (ent.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 ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type ServiceAccountFunc

type ServiceAccountFunc func(context.Context, *ent.ServiceAccountMutation) (ent.Value, error)

The ServiceAccountFunc type is an adapter to allow the use of ordinary function as ServiceAccount mutator.

func (ServiceAccountFunc) Mutate

Mutate calls f(ctx, m).

type ServiceAccountKeyPairFunc

type ServiceAccountKeyPairFunc func(context.Context, *ent.ServiceAccountKeyPairMutation) (ent.Value, error)

The ServiceAccountKeyPairFunc type is an adapter to allow the use of ordinary function as ServiceAccountKeyPair mutator.

func (ServiceAccountKeyPairFunc) Mutate

Mutate calls f(ctx, m).

type ServicePrincipalFunc added in v0.2.0

type ServicePrincipalFunc func(context.Context, *ent.ServicePrincipalMutation) (ent.Value, error)

The ServicePrincipalFunc type is an adapter to allow the use of ordinary function as ServicePrincipal mutator.

func (ServicePrincipalFunc) Mutate added in v0.2.0

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