-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoftdeletes.go
30 lines (23 loc) · 1.09 KB
/
softdeletes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package entx
import "context"
// SoftDeleteSkipKey is used to indicate to allow soft deleted records to be returned in
// records and to skip soft delete on mutations and proceed with a regular delete
type SoftDeleteSkipKey struct{}
// SkipSoftDelete returns a new context that skips the soft-delete interceptor/hooks.
func SkipSoftDelete(parent context.Context) context.Context {
return context.WithValue(parent, SoftDeleteSkipKey{}, true)
}
// CheckSkipSoftDelete checks if the SoftDeleteSkipKey is set in the context
func CheckSkipSoftDelete(ctx context.Context) bool {
return ctx.Value(SoftDeleteSkipKey{}) != nil
}
// SoftDeleteKey is used to indicate a soft delete mutation is in progress
type SoftDeleteKey struct{}
// IsSoftDelete returns a new context that informs the delete is a soft-delete for interceptor/hooks.
func IsSoftDelete(parent context.Context) context.Context {
return context.WithValue(parent, SoftDeleteKey{}, true)
}
// CheckIsSoftDelete checks if the softDeleteKey is set in the context
func CheckIsSoftDelete(ctx context.Context) bool {
return ctx.Value(SoftDeleteKey{}) != nil
}