Enhance db.Scan with ParamsFilter - Issue 7336 - Suggestion (#7337)

This commit is contained in:
Evyatar Yaffe
2025-01-12 12:19:28 +02:00
committed by GitHub
parent 8503287ca4
commit fed49230cb

View File

@ -80,6 +80,11 @@ var (
})
// Recorder logger records running SQL into a recorder instance
Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}
// RecorderParamsFilter defaults to no-op, allows to be run-over by a different implementation
RecorderParamsFilter = func(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
return sql, params
}
)
// New initialize logger
@ -211,3 +216,10 @@ func (l *traceRecorder) Trace(ctx context.Context, begin time.Time, fc func() (s
l.SQL, l.RowsAffected = fc()
l.Err = err
}
func (l *traceRecorder) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
if RecorderParamsFilter == nil {
return sql, params
}
return RecorderParamsFilter(ctx, sql, params...)
}