forked from volatiletech/sqlboiler
/
hooks.go
43 lines (36 loc) · 1.08 KB
/
hooks.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
31
32
33
34
35
36
37
38
39
40
41
42
43
package boil
import "context"
// SkipHooks modifies a context to prevent hooks from running for any query
// it encounters.
func SkipHooks(ctx context.Context) context.Context {
return context.WithValue(ctx, ctxSkipHooks, true)
}
// HooksAreSkipped returns true if the context skips hooks
func HooksAreSkipped(ctx context.Context) bool {
skip := ctx.Value(ctxSkipHooks)
return skip != nil && skip.(bool)
}
// SkipTimestamps modifies a context to prevent hooks from running for any query
// it encounters.
func SkipTimestamps(ctx context.Context) context.Context {
return context.WithValue(ctx, ctxSkipTimestamps, true)
}
// TimestampsAreSkipped returns true if the context skips hooks
func TimestampsAreSkipped(ctx context.Context) bool {
skip := ctx.Value(ctxSkipTimestamps)
return skip != nil && skip.(bool)
}
// HookPoint is the point in time at which we hook
type HookPoint int
// the hook point constants
const (
BeforeInsertHook HookPoint = iota + 1
BeforeUpdateHook
BeforeDeleteHook
BeforeUpsertHook
AfterInsertHook
AfterSelectHook
AfterUpdateHook
AfterDeleteHook
AfterUpsertHook
)