From 6542364944b0e8d40c5d043308d88f97a69b671d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 11 Apr 2018 12:57:13 +0800 Subject: [PATCH] refactor buildUpdates (#884) --- session_update.go | 6 ++---- statement.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/session_update.go b/session_update.go index aba3906ec..2115d67f7 100644 --- a/session_update.go +++ b/session_update.go @@ -176,10 +176,8 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6 } if session.statement.ColumnStr == "" { - colNames, args = buildUpdates(session.engine, session.statement.RefTable, bean, false, false, - false, false, session.statement.allUseBool, session.statement.useAllCols, - session.statement.mustColumnMap, session.statement.nullableMap, - session.statement.columnMap, session.statement.omitColumnMap, true, session.statement.unscoped) + colNames, args = session.statement.buildUpdates(bean, false, false, + false, false, true) } else { colNames, args, err = session.genUpdateColumns(bean) if err != nil { diff --git a/statement.go b/statement.go index 07f48037e..f6827b38a 100644 --- a/statement.go +++ b/statement.go @@ -223,11 +223,18 @@ func (statement *Statement) setRefBean(bean interface{}) error { } // Auto generating update columnes and values according a struct -func buildUpdates(engine *Engine, table *core.Table, bean interface{}, - includeVersion bool, includeUpdated bool, includeNil bool, - includeAutoIncr bool, allUseBool bool, useAllCols bool, - mustColumnMap map[string]bool, nullableMap map[string]bool, - columnMap columnMap, omitColumnMap columnMap, update, unscoped bool) ([]string, []interface{}) { +func (statement *Statement) buildUpdates(bean interface{}, + includeVersion, includeUpdated, includeNil, + includeAutoIncr, update bool) ([]string, []interface{}) { + engine := statement.Engine + table := statement.RefTable + allUseBool := statement.allUseBool + useAllCols := statement.useAllCols + mustColumnMap := statement.mustColumnMap + nullableMap := statement.nullableMap + columnMap := statement.columnMap + omitColumnMap := statement.omitColumnMap + unscoped := statement.unscoped var colNames = make([]string, 0) var args = make([]interface{}, 0)