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

debug sql

parent 168e879e
...@@ -38,6 +38,7 @@ type Pool struct { ...@@ -38,6 +38,7 @@ type Pool struct {
Balance Balance Balance Balance
PingTimout time.Duration PingTimout time.Duration
PingTry int PingTry int
Debug bool
} }
func (d *Pool) WithContext(ctx context.Context) *Pool { func (d *Pool) WithContext(ctx context.Context) *Pool {
...@@ -417,19 +418,21 @@ func (d *Pool) prepare(sql string, param map[string]any) string { ...@@ -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) { switch vv := v.(type) {
case bool: case bool:
if vv { 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: case int, uint:
if vv == 1 { 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: case string:
if vv == "1" { 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