forked from mirror/gorm
Print affected rows (#1541)
* fix better * add the rows number that the sql result affected or returned
This commit is contained in:
parent
2a1463811e
commit
10e217e2bc
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
@ -87,6 +88,7 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = append(messages, sql)
|
messages = append(messages, sql)
|
||||||
|
messages = append(messages, fmt.Sprintf(" \n\033[36;31m[%v]\033[0m ", strconv.FormatInt(values[5].(int64), 10)+" rows affected or returned "))
|
||||||
} else {
|
} else {
|
||||||
messages = append(messages, "\033[31;1m")
|
messages = append(messages, "\033[31;1m")
|
||||||
messages = append(messages, values[2:]...)
|
messages = append(messages, values[2:]...)
|
||||||
|
|
8
main.go
8
main.go
|
@ -702,7 +702,7 @@ func (s *DB) GetErrors() []error {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
func (s *DB) clone() *DB {
|
func (s *DB) clone() *DB {
|
||||||
db := DB{
|
db := &DB{
|
||||||
db: s.db,
|
db: s.db,
|
||||||
parent: s.parent,
|
parent: s.parent,
|
||||||
logger: s.logger,
|
logger: s.logger,
|
||||||
|
@ -723,8 +723,8 @@ func (s *DB) clone() *DB {
|
||||||
db.search = s.search.clone()
|
db.search = s.search.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
db.search.db = &db
|
db.search.db = db
|
||||||
return &db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) print(v ...interface{}) {
|
func (s *DB) print(v ...interface{}) {
|
||||||
|
@ -739,6 +739,6 @@ func (s *DB) log(v ...interface{}) {
|
||||||
|
|
||||||
func (s *DB) slog(sql string, t time.Time, vars ...interface{}) {
|
func (s *DB) slog(sql string, t time.Time, vars ...interface{}) {
|
||||||
if s.logMode == 2 {
|
if s.logMode == 2 {
|
||||||
s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars)
|
s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars, s.RowsAffected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue