|
@@ -354,6 +354,36 @@ func (m *Mysql) UpdateByTx(tx *sql.Tx, tableName string, query, update map[strin
|
|
return m.UpdateOrDeleteBySqlByTx(tx, q, values...) >= 0
|
|
return m.UpdateOrDeleteBySqlByTx(tx, q, values...) >= 0
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//批量更新
|
|
|
|
+func (m *Mysql) UpdateBath(tableName string, fields []string, array [][]interface{}) {
|
|
|
|
+ ws := []string{}
|
|
|
|
+ args := []interface{}{}
|
|
|
|
+ ids := []interface{}{}
|
|
|
|
+ casethen := []string{}
|
|
|
|
+ for n := 0; n < len(array[0]); n++ {
|
|
|
|
+ for _, v := range array {
|
|
|
|
+ if n == 0 {
|
|
|
|
+ ws = append(ws, "?")
|
|
|
|
+ ids = append(ids, v[0])
|
|
|
|
+ casethen = append(casethen, "when ? then ?")
|
|
|
|
+ } else {
|
|
|
|
+ args = append(args, v[0], v[n])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ct := strings.Join(casethen, " ")
|
|
|
|
+ sql_appends := []string{}
|
|
|
|
+ for k, v := range fields {
|
|
|
|
+ if k == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ sql_appends = append(sql_appends, fmt.Sprintf(`%s=case %s %s end`, v, fields[0], ct))
|
|
|
|
+ }
|
|
|
|
+ args = append(args, ids...)
|
|
|
|
+ sql := fmt.Sprintf(`update %s set %s where %s in (%s)`, tableName, strings.Join(sql_appends, ","), fields[0], strings.Join(ws, ","))
|
|
|
|
+ m.UpdateOrDeleteBySql(sql, args...)
|
|
|
|
+}
|
|
|
|
+
|
|
//删除
|
|
//删除
|
|
func (m *Mysql) Delete(tableName string, query map[string]interface{}) bool {
|
|
func (m *Mysql) Delete(tableName string, query map[string]interface{}) bool {
|
|
return m.DeleteByTx(nil, tableName, query)
|
|
return m.DeleteByTx(nil, tableName, query)
|