github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/boil/hooks.go (about)

     1  package boil
     2  
     3  import "context"
     4  
     5  // SkipHooks modifies a context to prevent hooks from running for any query
     6  // it encounters.
     7  func SkipHooks(ctx context.Context) context.Context {
     8  	return context.WithValue(ctx, ctxSkipHooks, true)
     9  }
    10  
    11  // HooksAreSkipped returns true if the context skips hooks
    12  func HooksAreSkipped(ctx context.Context) bool {
    13  	skip := ctx.Value(ctxSkipHooks)
    14  	return skip != nil && skip.(bool)
    15  }
    16  
    17  // SkipTimestamps modifies a context to prevent hooks from running for any query
    18  // it encounters.
    19  func SkipTimestamps(ctx context.Context) context.Context {
    20  	return context.WithValue(ctx, ctxSkipTimestamps, true)
    21  }
    22  
    23  // TimestampsAreSkipped returns true if the context skips hooks
    24  func TimestampsAreSkipped(ctx context.Context) bool {
    25  	skip := ctx.Value(ctxSkipTimestamps)
    26  	return skip != nil && skip.(bool)
    27  }
    28  
    29  // HookPoint is the point in time at which we hook
    30  type HookPoint int
    31  
    32  // the hook point constants
    33  const (
    34  	BeforeInsertHook HookPoint = iota + 1
    35  	BeforeUpdateHook
    36  	BeforeDeleteHook
    37  	BeforeUpsertHook
    38  	AfterInsertHook
    39  	AfterSelectHook
    40  	AfterUpdateHook
    41  	AfterDeleteHook
    42  	AfterUpsertHook
    43  )