2013-11-16 07:41:31 +04:00
|
|
|
package gorm
|
|
|
|
|
2015-01-19 10:50:21 +03:00
|
|
|
import "time"
|
2013-11-16 07:41:31 +04:00
|
|
|
|
|
|
|
func (s *DB) clone() *DB {
|
2016-01-12 08:44:16 +03:00
|
|
|
db := DB{db: s.db, parent: s.parent, logger: s.logger, logMode: s.logMode, unscoped: s.unscoped, values: map[string]interface{}{}, Value: s.Value, Error: s.Error}
|
2014-08-20 13:05:02 +04:00
|
|
|
|
|
|
|
for key, value := range s.values {
|
|
|
|
db.values[key] = value
|
|
|
|
}
|
2013-11-16 10:15:33 +04:00
|
|
|
|
2013-11-16 11:01:31 +04:00
|
|
|
if s.search == nil {
|
2013-11-16 09:28:22 +04:00
|
|
|
db.search = &search{}
|
|
|
|
} else {
|
2013-11-16 11:01:31 +04:00
|
|
|
db.search = s.search.clone()
|
2013-11-16 09:28:22 +04:00
|
|
|
}
|
2013-11-16 11:01:31 +04:00
|
|
|
|
2013-11-16 10:15:33 +04:00
|
|
|
db.search.db = &db
|
|
|
|
return &db
|
2013-11-16 07:41:31 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 13:36:58 +04:00
|
|
|
func (s *DB) print(v ...interface{}) {
|
2015-08-01 06:09:17 +03:00
|
|
|
s.logger.(logger).Print(v...)
|
2013-11-16 07:41:31 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 13:36:58 +04:00
|
|
|
func (s *DB) log(v ...interface{}) {
|
2014-07-29 14:21:36 +04:00
|
|
|
if s != nil && s.logMode == 2 {
|
2014-01-04 13:36:58 +04:00
|
|
|
s.print(append([]interface{}{"log", fileWithLineNum()}, v...)...)
|
|
|
|
}
|
2013-11-16 07:41:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DB) slog(sql string, t time.Time, vars ...interface{}) {
|
2014-01-04 13:36:58 +04:00
|
|
|
if s.logMode == 2 {
|
2014-08-23 12:00:04 +04:00
|
|
|
s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars)
|
2014-01-04 13:36:58 +04:00
|
|
|
}
|
2013-11-16 07:41:31 +04:00
|
|
|
}
|