-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraceDetailDatabase.go
44 lines (39 loc) · 1.56 KB
/
traceDetailDatabase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package linkTrace
import (
"fmt"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/fs/trace"
"strings"
)
type TraceDetailDatabase struct {
trace.BaseTraceDetail
DbName string // 数据库名
TableName string // 表名
Sql string // SQL
ConnectionString string // 连接字符串
RowsAffected int64 // 影响行数
}
func (receiver *TraceDetailDatabase) GetTraceDetail() *trace.BaseTraceDetail {
return &receiver.BaseTraceDetail
}
func (receiver *TraceDetailDatabase) ToString() string {
if receiver.Sql != "" {
sql := receiver.Sql
if len(sql) > 1000 {
sql = sql[:1000] + "......"
}
sql = flog.ReplaceBlues(sql, "SELECT ", "UPDATE ", "DELETE ", "INSERT INTO ", " FROM ", " WHERE ", " LIMIT ", " SET ", " ORDER BY ", " VALUES ", " and ", " or ", "`")
sql = strings.ReplaceAll(sql, receiver.TableName, flog.Green(receiver.TableName))
return fmt.Sprintf("[%s]耗时:%s,[影响%d行]%s", flog.Yellow(receiver.CallType.ToString()), flog.Red(receiver.UseTs.String()), receiver.RowsAffected, sql)
} else if receiver.ConnectionString != "" {
return fmt.Sprintf("[%s]耗时:%s, 连接数据库:%s", flog.Yellow(receiver.CallType.ToString()), flog.Red(receiver.UseTs.String()), receiver.ConnectionString)
}
return ""
}
func (receiver *TraceDetailDatabase) SetSql(connectionString string, DbName string, tableName string, sql string, rowsAffected int64) {
receiver.ConnectionString = connectionString
receiver.DbName = DbName
receiver.TableName = tableName
receiver.Sql = sql
receiver.RowsAffected = rowsAffected
}