|
@@ -12,14 +12,10 @@ import (
|
|
const slowThreshold = time.Millisecond * 500
|
|
const slowThreshold = time.Millisecond * 500
|
|
|
|
|
|
func exec(conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
|
|
func exec(conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
|
|
- stmt, err := format(q, args...)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
startTime := timex.Now()
|
|
startTime := timex.Now()
|
|
result, err := conn.Exec(q, args...)
|
|
result, err := conn.Exec(q, args...)
|
|
duration := timex.Since(startTime)
|
|
duration := timex.Since(startTime)
|
|
|
|
+ stmt := formatForPrint(q, args)
|
|
if duration > slowThreshold {
|
|
if duration > slowThreshold {
|
|
logx.WithDuration(duration).Slowf("[SQL] exec: slowcall - %s", stmt)
|
|
logx.WithDuration(duration).Slowf("[SQL] exec: slowcall - %s", stmt)
|
|
} else {
|
|
} else {
|
|
@@ -33,10 +29,10 @@ func exec(conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func execStmt(conn stmtConn, args ...interface{}) (sql.Result, error) {
|
|
func execStmt(conn stmtConn, args ...interface{}) (sql.Result, error) {
|
|
- stmt := fmt.Sprint(args...)
|
|
|
|
startTime := timex.Now()
|
|
startTime := timex.Now()
|
|
result, err := conn.Exec(args...)
|
|
result, err := conn.Exec(args...)
|
|
duration := timex.Since(startTime)
|
|
duration := timex.Since(startTime)
|
|
|
|
+ stmt := fmt.Sprint(args...)
|
|
if duration > slowThreshold {
|
|
if duration > slowThreshold {
|
|
logx.WithDuration(duration).Slowf("[SQL] execStmt: slowcall - %s", stmt)
|
|
logx.WithDuration(duration).Slowf("[SQL] execStmt: slowcall - %s", stmt)
|
|
} else {
|
|
} else {
|
|
@@ -50,14 +46,10 @@ func execStmt(conn stmtConn, args ...interface{}) (sql.Result, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func query(conn sessionConn, scanner func(*sql.Rows) error, q string, args ...interface{}) error {
|
|
func query(conn sessionConn, scanner func(*sql.Rows) error, q string, args ...interface{}) error {
|
|
- stmt, err := format(q, args...)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
startTime := timex.Now()
|
|
startTime := timex.Now()
|
|
rows, err := conn.Query(q, args...)
|
|
rows, err := conn.Query(q, args...)
|
|
duration := timex.Since(startTime)
|
|
duration := timex.Since(startTime)
|
|
|
|
+ stmt := fmt.Sprint(args...)
|
|
if duration > slowThreshold {
|
|
if duration > slowThreshold {
|
|
logx.WithDuration(duration).Slowf("[SQL] query: slowcall - %s", stmt)
|
|
logx.WithDuration(duration).Slowf("[SQL] query: slowcall - %s", stmt)
|
|
} else {
|
|
} else {
|