|
@@ -292,43 +292,26 @@ func DeleteEntity(executor Executor, tableName string, e any) error {
|
|
|
|
|
|
|
|
|
func UpdateEntity(executor Executor, tableName string, e any) error {
|
|
|
- _, err := UpdateEntityWithRowsAffected(executor, tableName, e)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-func UpdateEntityWithRowsAffected(executor Executor, tableName string, e any) (int64, error) {
|
|
|
if executor == nil {
|
|
|
- return 0, errors.New("没有传递执行器")
|
|
|
+ return errors.New("没有传递执行器")
|
|
|
}
|
|
|
|
|
|
if strutils.IsStringEmpty(tableName) {
|
|
|
- return 0, errors.New("没有传递表名")
|
|
|
+ return errors.New("没有传递表名")
|
|
|
}
|
|
|
|
|
|
if e == nil {
|
|
|
- return 0, nil
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
entityType := reflect.TypeOf(e)
|
|
|
if !reflectutils.IsTypeStructOrStructPointer(entityType) {
|
|
|
- return 0, errors.New("实体参数不是结构或结构指针")
|
|
|
+ return errors.New("实体参数不是结构或结构指针")
|
|
|
}
|
|
|
|
|
|
fields, err := sql_mapping.DefaultUsage(e)
|
|
|
if err != nil {
|
|
|
- return 0, err
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
now := time.Now().Local()
|
|
@@ -375,19 +358,19 @@ func UpdateEntityWithRowsAffected(executor Executor, tableName string, e any) (i
|
|
|
|
|
|
executeParamsMap, err := executeParams.Map()
|
|
|
if err != nil {
|
|
|
- return 0, err
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
args := make([]any, 0)
|
|
|
args = append(args, executeParams.TableRow.Values()...)
|
|
|
args = append(args, executeParams.Conditions.Args()...)
|
|
|
|
|
|
- _, rowsAffected, err := executor.ExecuteRawSqlTemplateWithRowsAffected(sql.UpdateTpl, executeParamsMap, args...)
|
|
|
+ _, _, err = executor.ExecuteRawSqlTemplateWithRowsAffected(sql.UpdateTpl, executeParamsMap, args...)
|
|
|
if err != nil {
|
|
|
- return 0, err
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
- return rowsAffected, nil
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
|