Exec logs its params and calls the underlying transaction Exec method.
(ctx context.Context, query string, args, v any)
| 117 | |
| 118 | // Exec logs its params and calls the underlying transaction Exec method. |
| 119 | func (d *DebugTx) Exec(ctx context.Context, query string, args, v any) error { |
| 120 | start := time.Now() |
| 121 | err := d.Tx.Exec(ctx, query, args, v) |
| 122 | printArgs := args |
| 123 | if argsArray, ok := args.([]interface{}); ok { |
| 124 | for i, argVal := range argsArray { |
| 125 | if argValStr, ok := argVal.(string); ok && len(argValStr) > strMaxLen { |
| 126 | printArgs.([]interface{})[i] = argValStr[:strMaxLen] + "...[Truncated]..." |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | if skip, ok := ctx.Value(SkipDbLogging{}).(bool); ok && skip { |
| 131 | return err |
| 132 | } |
| 133 | d.log(ctx, fmt.Sprintf("Tx(%s).Exec: query=%v args=%v time=%v", d.id, query, args, time.Since(start))) |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | // ExecContext logs its params and calls the underlying transaction ExecContext method if it is supported. |
| 138 | func (d *DebugTx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) { |