refactor: DB-数据操作优化

This commit is contained in:
meilin.huang
2023-11-13 17:41:03 +08:00
parent 76527d95bd
commit f234c72514
6 changed files with 125 additions and 40 deletions

View File

@@ -13,7 +13,7 @@ require (
github.com/go-playground/validator/v10 v10.14.0
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-jwt/jwt/v5 v5.1.0
github.com/gorilla/websocket v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/kanzihuang/vitess/go/vt/sqlparser v0.0.0-20231018071450-ac8d9f0167e9
github.com/lib/pq v1.10.9
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230712084735-068dc2aee82d

View File

@@ -113,15 +113,14 @@ func (d *Db) ExecSql(rc *req.Ctx) {
for _, s := range sqls {
s = stringx.TrimSpaceAndBr(s)
// 多条执行,如果有查询语句,则跳过
if isMulti && strings.HasPrefix(strings.ToLower(s), "select") {
continue
// 多条执行,暂不支持查询语句
if isMulti {
biz.IsTrue(!strings.HasPrefix(strings.ToLower(s), "select"), "多条语句执行暂不不支持select语句")
}
execReq.Sql = s
execRes, err := d.DbSqlExecApp.Exec(execReq)
if err != nil {
biz.ErrIsNilAppendErr(err, fmt.Sprintf("[%s] -> 执行失败: ", s)+"%s")
}
biz.ErrIsNilAppendErr(err, fmt.Sprintf("[%s] -> 执行失败: ", s)+"%s")
if execResAll == nil {
execResAll = execRes

View File

@@ -44,6 +44,10 @@ func Debug(msg string, args ...any) {
Log(context.Background(), slog.LevelDebug, msg, args...)
}
func DebugContext(ctx context.Context, msg string, args ...any) {
Log(ctx, slog.LevelDebug, msg, args...)
}
func Debugf(format string, args ...any) {
Log(context.Background(), slog.LevelDebug, fmt.Sprintf(format, args...))
}
@@ -77,6 +81,10 @@ func Warn(msg string, args ...any) {
Log(context.Background(), slog.LevelWarn, msg, args...)
}
func WarnContext(ctx context.Context, msg string, args ...any) {
Log(ctx, slog.LevelWarn, msg, args...)
}
func Warnf(format string, args ...any) {
Log(context.Background(), slog.LevelWarn, fmt.Sprintf(format, args...))
}
@@ -89,6 +97,10 @@ func Error(msg string, args ...any) {
Log(context.Background(), slog.LevelError, msg, args...)
}
func ErrorContext(ctx context.Context, msg string, args ...any) {
Log(ctx, slog.LevelError, msg, args...)
}
func Errorf(format string, args ...any) {
Log(context.Background(), slog.LevelError, fmt.Sprintf(format, args...))
}