Skip to content

Commit

Permalink
refactor buildUpdates (go-xorm#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 11, 2018
1 parent fd4a80b commit 6542364
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 2 additions & 4 deletions session_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 12 additions & 5 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6542364

Please sign in to comment.