hook

package
v0.0.0-...-c20d9b3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 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) 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 AIEmployeeFunc

type AIEmployeeFunc func(context.Context, *db.AIEmployeeMutation) (db.Value, error)

The AIEmployeeFunc type is an adapter to allow the use of ordinary function as AIEmployee mutator.

func (AIEmployeeFunc) Mutate

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

Mutate calls f(ctx, m).

type AITaskFunc

type AITaskFunc func(context.Context, *db.AITaskMutation) (db.Value, error)

The AITaskFunc type is an adapter to allow the use of ordinary function as AITask mutator.

func (AITaskFunc) Mutate

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

Mutate calls f(ctx, m).

type AdminFunc

type AdminFunc func(context.Context, *db.AdminMutation) (db.Value, error)

The AdminFunc type is an adapter to allow the use of ordinary function as Admin mutator.

func (AdminFunc) Mutate

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

Mutate calls f(ctx, m).

type AdminLoginHistoryFunc

type AdminLoginHistoryFunc func(context.Context, *db.AdminLoginHistoryMutation) (db.Value, error)

The AdminLoginHistoryFunc type is an adapter to allow the use of ordinary function as AdminLoginHistory mutator.

func (AdminLoginHistoryFunc) Mutate

Mutate calls f(ctx, m).

type AdminRoleFunc

type AdminRoleFunc func(context.Context, *db.AdminRoleMutation) (db.Value, error)

The AdminRoleFunc type is an adapter to allow the use of ordinary function as AdminRole mutator.

func (AdminRoleFunc) Mutate

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

Mutate calls f(ctx, m).

type ApiKeyFunc

type ApiKeyFunc func(context.Context, *db.ApiKeyMutation) (db.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 db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type BillingPlanFunc

type BillingPlanFunc func(context.Context, *db.BillingPlanMutation) (db.Value, error)

The BillingPlanFunc type is an adapter to allow the use of ordinary function as BillingPlan mutator.

func (BillingPlanFunc) Mutate

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

Mutate calls f(ctx, m).

type BillingQuotaFunc

type BillingQuotaFunc func(context.Context, *db.BillingQuotaMutation) (db.Value, error)

The BillingQuotaFunc type is an adapter to allow the use of ordinary function as BillingQuota mutator.

func (BillingQuotaFunc) Mutate

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

Mutate calls f(ctx, m).

type BillingRecordFunc

type BillingRecordFunc func(context.Context, *db.BillingRecordMutation) (db.Value, error)

The BillingRecordFunc type is an adapter to allow the use of ordinary function as BillingRecord mutator.

func (BillingRecordFunc) Mutate

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

Mutate calls f(ctx, m).

type BillingUsageFunc

type BillingUsageFunc func(context.Context, *db.BillingUsageMutation) (db.Value, error)

The BillingUsageFunc type is an adapter to allow the use of ordinary function as BillingUsage mutator.

func (BillingUsageFunc) Mutate

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

type CodeSnippetFunc func(context.Context, *db.CodeSnippetMutation) (db.Value, error)

The CodeSnippetFunc type is an adapter to allow the use of ordinary function as CodeSnippet mutator.

func (CodeSnippetFunc) Mutate

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

Mutate calls f(ctx, m).

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 ExtensionFunc

type ExtensionFunc func(context.Context, *db.ExtensionMutation) (db.Value, error)

The ExtensionFunc type is an adapter to allow the use of ordinary function as Extension mutator.

func (ExtensionFunc) Mutate

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

Mutate calls f(ctx, m).

type InviteCodeFunc

type InviteCodeFunc func(context.Context, *db.InviteCodeMutation) (db.Value, error)

The InviteCodeFunc type is an adapter to allow the use of ordinary function as InviteCode mutator.

func (InviteCodeFunc) Mutate

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

Mutate calls f(ctx, m).

type LicenseFunc

type LicenseFunc func(context.Context, *db.LicenseMutation) (db.Value, error)

The LicenseFunc type is an adapter to allow the use of ordinary function as License mutator.

func (LicenseFunc) Mutate

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

Mutate calls f(ctx, m).

type ModelFunc

type ModelFunc func(context.Context, *db.ModelMutation) (db.Value, error)

The ModelFunc type is an adapter to allow the use of ordinary function as Model mutator.

func (ModelFunc) Mutate

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

Mutate calls f(ctx, m).

type ModelProviderFunc

type ModelProviderFunc func(context.Context, *db.ModelProviderMutation) (db.Value, error)

The ModelProviderFunc type is an adapter to allow the use of ordinary function as ModelProvider mutator.

func (ModelProviderFunc) Mutate

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

Mutate calls f(ctx, m).

type ModelProviderModelFunc

type ModelProviderModelFunc func(context.Context, *db.ModelProviderModelMutation) (db.Value, error)

The ModelProviderModelFunc type is an adapter to allow the use of ordinary function as ModelProviderModel mutator.

func (ModelProviderModelFunc) Mutate

Mutate calls f(ctx, m).

type RoleFunc

type RoleFunc func(context.Context, *db.RoleMutation) (db.Value, error)

The RoleFunc type is an adapter to allow the use of ordinary function as Role mutator.

func (RoleFunc) Mutate

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

Mutate calls f(ctx, m).

type SecurityScanningFunc

type SecurityScanningFunc func(context.Context, *db.SecurityScanningMutation) (db.Value, error)

The SecurityScanningFunc type is an adapter to allow the use of ordinary function as SecurityScanning mutator.

func (SecurityScanningFunc) Mutate

Mutate calls f(ctx, m).

type SecurityScanningResultFunc

type SecurityScanningResultFunc func(context.Context, *db.SecurityScanningResultMutation) (db.Value, error)

The SecurityScanningResultFunc type is an adapter to allow the use of ordinary function as SecurityScanningResult mutator.

func (SecurityScanningResultFunc) Mutate

Mutate calls f(ctx, m).

type SettingFunc

type SettingFunc func(context.Context, *db.SettingMutation) (db.Value, error)

The SettingFunc type is an adapter to allow the use of ordinary function as Setting mutator.

func (SettingFunc) Mutate

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

Mutate calls f(ctx, m).

type TaskFunc

type TaskFunc func(context.Context, *db.TaskMutation) (db.Value, error)

The TaskFunc type is an adapter to allow the use of ordinary function as Task mutator.

func (TaskFunc) Mutate

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

Mutate calls f(ctx, m).

type TaskRecordFunc

type TaskRecordFunc func(context.Context, *db.TaskRecordMutation) (db.Value, error)

The TaskRecordFunc type is an adapter to allow the use of ordinary function as TaskRecord mutator.

func (TaskRecordFunc) Mutate

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

Mutate calls f(ctx, m).

type UserFunc

type UserFunc func(context.Context, *db.UserMutation) (db.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 db.Mutation) (db.Value, error)

Mutate calls f(ctx, m).

type UserGroupAdminFunc

type UserGroupAdminFunc func(context.Context, *db.UserGroupAdminMutation) (db.Value, error)

The UserGroupAdminFunc type is an adapter to allow the use of ordinary function as UserGroupAdmin mutator.

func (UserGroupAdminFunc) Mutate

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

Mutate calls f(ctx, m).

type UserGroupFunc

type UserGroupFunc func(context.Context, *db.UserGroupMutation) (db.Value, error)

The UserGroupFunc type is an adapter to allow the use of ordinary function as UserGroup mutator.

func (UserGroupFunc) Mutate

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

Mutate calls f(ctx, m).

type UserGroupUserFunc

type UserGroupUserFunc func(context.Context, *db.UserGroupUserMutation) (db.Value, error)

The UserGroupUserFunc type is an adapter to allow the use of ordinary function as UserGroupUser mutator.

func (UserGroupUserFunc) Mutate

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

Mutate calls f(ctx, m).

type UserIdentityFunc

type UserIdentityFunc func(context.Context, *db.UserIdentityMutation) (db.Value, error)

The UserIdentityFunc type is an adapter to allow the use of ordinary function as UserIdentity mutator.

func (UserIdentityFunc) Mutate

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

Mutate calls f(ctx, m).

type UserLoginHistoryFunc

type UserLoginHistoryFunc func(context.Context, *db.UserLoginHistoryMutation) (db.Value, error)

The UserLoginHistoryFunc type is an adapter to allow the use of ordinary function as UserLoginHistory mutator.

func (UserLoginHistoryFunc) Mutate

Mutate calls f(ctx, m).

type WorkspaceFileFunc

type WorkspaceFileFunc func(context.Context, *db.WorkspaceFileMutation) (db.Value, error)

The WorkspaceFileFunc type is an adapter to allow the use of ordinary function as WorkspaceFile mutator.

func (WorkspaceFileFunc) Mutate

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

Mutate calls f(ctx, m).

type WorkspaceFunc

type WorkspaceFunc func(context.Context, *db.WorkspaceMutation) (db.Value, error)

The WorkspaceFunc type is an adapter to allow the use of ordinary function as Workspace mutator.

func (WorkspaceFunc) Mutate

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