Refact do.go
This commit is contained in:
parent
045b3b6fbc
commit
f884a94495
28
do.go
28
do.go
@ -16,22 +16,10 @@ type Do struct {
|
|||||||
db *DB
|
db *DB
|
||||||
model *Model
|
model *Model
|
||||||
tableName string
|
tableName string
|
||||||
startedTransaction bool
|
|
||||||
|
|
||||||
value interface{}
|
value interface{}
|
||||||
sql string
|
sql string
|
||||||
sqlVars []interface{}
|
sqlVars []interface{}
|
||||||
|
startedTransaction bool
|
||||||
whereClause []map[string]interface{}
|
|
||||||
orClause []map[string]interface{}
|
|
||||||
notClause []map[string]interface{}
|
|
||||||
selectStr string
|
|
||||||
orderStrs []string
|
|
||||||
offsetStr string
|
|
||||||
limitStr string
|
|
||||||
unscoped bool
|
|
||||||
updateAttrs map[string]interface{}
|
|
||||||
ignoreProtectedAttrs bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Do) table() string {
|
func (s *Do) table() string {
|
||||||
@ -63,17 +51,19 @@ func (s *Do) addToVars(value interface{}) string {
|
|||||||
return fmt.Sprintf(s.db.dialect.BinVar(), len(s.sqlVars))
|
return fmt.Sprintf(s.db.dialect.BinVar(), len(s.sqlVars))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Do) exec(sqls ...string) (err error) {
|
func (s *Do) trace(t time.Time) {
|
||||||
|
s.db.slog(s.sql, t, s.sqlVars...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Do) exec(sqls ...string) {
|
||||||
|
defer s.trace(time.Now())
|
||||||
if !s.db.hasError() {
|
if !s.db.hasError() {
|
||||||
if len(sqls) > 0 {
|
if len(sqls) > 0 {
|
||||||
s.sql = sqls[0]
|
s.sql = sqls[0]
|
||||||
}
|
}
|
||||||
|
_, err := s.db.db.Exec(s.sql, s.sqlVars...)
|
||||||
now := time.Now()
|
s.err(err)
|
||||||
_, err = s.db.db.Exec(s.sql, s.sqlVars...)
|
|
||||||
s.db.slog(s.sql, now, s.sqlVars...)
|
|
||||||
}
|
}
|
||||||
return s.err(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Do) save() *Do {
|
func (s *Do) save() *Do {
|
||||||
|
@ -13,7 +13,7 @@ func (s *DB) clone() *DB {
|
|||||||
|
|
||||||
func (s *DB) do(data interface{}) *Do {
|
func (s *DB) do(data interface{}) *Do {
|
||||||
s.data = data
|
s.data = data
|
||||||
return &Do{db: s}
|
return &Do{db: s}.setModel(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) err(err error) error {
|
func (s *DB) err(err error) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user