method Update(...) 's first params now support map and map's ptr
This commit is contained in:
parent
29fe0b6f80
commit
365812143b
|
@ -162,7 +162,7 @@ func update(engine *Engine, t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
condi := Condi{"username": "zzz", "height": 0.0, "departname": ""}
|
condi := Condi{"username": "zzz", "height": 0.0, "departname": ""}
|
||||||
_, err = engine.Table(&user).Id(1).Update(condi)
|
_, err = engine.Table(&user).Id(1).Update(&condi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -1410,7 +1410,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
table = session.Engine.AutoMap(bean)
|
table = session.Engine.AutoMap(bean)
|
||||||
session.Statement.RefTable = table
|
session.Statement.RefTable = table
|
||||||
colNames, args = BuildConditions(session.Engine, table, bean)
|
colNames, args = BuildConditions(session.Engine, table, bean)
|
||||||
if table.Updated != "" {
|
if session.Statement.UseAutoTime && table.Updated != "" {
|
||||||
colNames = append(colNames, session.Engine.Quote(table.Updated)+" = ?")
|
colNames = append(colNames, session.Engine.Quote(table.Updated)+" = ?")
|
||||||
args = append(args, time.Now())
|
args = append(args, time.Now())
|
||||||
}
|
}
|
||||||
|
@ -1421,13 +1421,13 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
table = session.Statement.RefTable
|
table = session.Statement.RefTable
|
||||||
colNames = make([]string, 0)
|
colNames = make([]string, 0)
|
||||||
args = make([]interface{}, 0)
|
args = make([]interface{}, 0)
|
||||||
bValue := reflect.ValueOf(bean)
|
bValue := reflect.Indirect(reflect.ValueOf(bean))
|
||||||
|
|
||||||
for _, v := range bValue.MapKeys() {
|
for _, v := range bValue.MapKeys() {
|
||||||
colNames = append(colNames, session.Engine.Quote(v.String())+" = ?")
|
colNames = append(colNames, session.Engine.Quote(v.String())+" = ?")
|
||||||
args = append(args, bValue.MapIndex(v).Interface())
|
args = append(args, bValue.MapIndex(v).Interface())
|
||||||
}
|
}
|
||||||
if table.Updated != "" {
|
if session.Statement.UseAutoTime && table.Updated != "" {
|
||||||
colNames = append(colNames, session.Engine.Quote(table.Updated)+" = ?")
|
colNames = append(colNames, session.Engine.Quote(table.Updated)+" = ?")
|
||||||
args = append(args, time.Now())
|
args = append(args, time.Now())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue