Commit dc8c5cd4 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

debug sql

parent 168e879e
......@@ -38,6 +38,7 @@ type Pool struct {
Balance Balance
PingTimout time.Duration
PingTry int
Debug bool
}
func (d *Pool) WithContext(ctx context.Context) *Pool {
......@@ -417,19 +418,21 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
}
}
if v, ok := param["_debug"]; ok {
if d.Debug {
d.logger.Printf("--SQL\n%v\n--SQL;\n--ARG\n%+v\n--ARG;", sql, param)
} else if v, ok := param["_debug"]; ok {
switch vv := v.(type) {
case bool:
if vv {
d.logger.Printf(sql)
d.logger.Printf("--SQL\n%v\n--SQL;\n--ARG\n%+v\n--ARG;", sql, param)
}
case int, uint:
if vv == 1 {
d.logger.Printf(sql)
d.logger.Printf("--SQL\n%v\n--SQL;\n--ARG\n%+v\n--ARG;", sql, param)
}
case string:
if vv == "1" {
d.logger.Printf(sql)
d.logger.Printf("--SQL\n%v\n--SQL;\n--ARG\n%+v\n--ARG;", sql, param)
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment