u
This commit is contained in:
1 parent
4d60582d4f
commit
2fb19021ae
40 files changed
+2552
-348
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"allapp-go/pkg/uniqueid"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -58,3 +59,30 @@ func validateData(table string, keyField string, data map[string]any) (any, erro
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// 校验数据
|
||||
func validateInsertData(table string, keyField string, data map[string]any) (any, error) {
|
||||
if table == "" {
|
||||
return nil, fmt.Errorf("表名不能为空")
|
||||
}
|
||||
|
||||
if len(data) == 0 {
|
||||
return nil, fmt.Errorf("数据不能为空")
|
||||
}
|
||||
|
||||
if keyField == "" {
|
||||
return nil, fmt.Errorf("主键字段不能为空")
|
||||
}
|
||||
|
||||
val, _ := data[keyField]
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func ensureID(data map[string]any, keyField string) {
|
||||
v, ok := data[keyField]
|
||||
|
||||
if !ok || v == nil || v == "" {
|
||||
data[keyField] = uniqueid.NextId()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user