forked from go-gorm/gorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_private.go
50 lines (41 loc) · 967 Bytes
/
main_private.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
45
46
47
48
49
50
package gorm
import "time"
func (s *DB) clone() *DB {
db := DB{db: s.db, parent: s.parent, logMode: s.logMode, values: map[string]interface{}{}, Value: s.Value, Error: s.Error}
for key, value := range s.values {
db.values[key] = value
}
if s.search == nil {
db.search = &search{}
} else {
db.search = s.search.clone()
}
db.search.db = &db
return &db
}
func (s *DB) err(err error) error {
if err != nil {
if err != RecordNotFound {
if s.logMode == 0 {
go s.print(fileWithLineNum(), err)
} else {
s.log(err)
}
}
s.Error = err
}
return err
}
func (s *DB) print(v ...interface{}) {
s.parent.logger.(logger).Print(v...)
}
func (s *DB) log(v ...interface{}) {
if s != nil && s.logMode == 2 {
s.print(append([]interface{}{"log", fileWithLineNum()}, v...)...)
}
}
func (s *DB) slog(sql string, t time.Time, vars ...interface{}) {
if s.logMode == 2 {
s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars)
}
}