This commit is contained in:
oneao committed 2026-04-06 21:15:11 +08:00
1 parent f08db1959b
commit c6671c8a8c
68 files changed
+13904 -1131

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
package db
import (
"fmt"
"strconv"
"strings"
)
func validateData(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, ok := data[keyField]
if !ok {
return nil, fmt.Errorf("缺少主键字段: %s", keyField)
}
if val == nil {
return nil, fmt.Errorf("主键字段值不能为空")
}
return val, nil
}
// 高效 placeholder 转换
func convertPlaceholder(sql string) string {
var sb strings.Builder
sb.Grow(len(sql))
argIndex := 1
for i := 0; i < len(sql); i++ {
if sql[i] == '?' {
sb.WriteByte('$')
sb.WriteString(strconv.Itoa(argIndex))
argIndex++
} else {
sb.WriteByte(sql[i])
}
}
return sb.String()
}