Ver Fonte

删除sqlresult

yjp há 9 meses atrás
pai
commit
d15122f915
3 ficheiros alterados com 5 adições e 195 exclusões
  1. 3 3
      sdk/sdk.go
  2. 0 190
      sdk/sql_result.go
  3. 2 2
      sdk/transaction.go

+ 3 - 3
sdk/sdk.go

@@ -15,9 +15,9 @@ type SDK struct {
 	grpcClient *grpc_client.Client
 }
 
-func (s *SDK) ExecuteRawSql(sql string, executeParams map[string]any) ([]SqlResult, error) {
+func (s *SDK) ExecuteRawSql(sql string, executeParams map[string]any) ([]map[string]any, error) {
 	if strutils.IsStringEmpty(sql) {
-		return make([]SqlResult, 0), nil
+		return make([]map[string]any, 0), nil
 	}
 
 	options := s.options
@@ -28,7 +28,7 @@ func (s *SDK) ExecuteRawSql(sql string, executeParams map[string]any) ([]SqlResu
 		return nil, err
 	}
 
-	results := make([]SqlResult, len(tableRows))
+	results := make([]map[string]any, len(tableRows))
 	for i, row := range tableRows {
 		results[i] = row
 	}

+ 0 - 190
sdk/sql_result.go

@@ -1,190 +0,0 @@
-package sdk
-
-import (
-	"fmt"
-	"git.sxidc.com/go-tools/utils/reflectutils"
-	"strings"
-	"time"
-)
-
-const (
-	sqlResultTimeMicroFormat = "2006-01-02T15:04:05.000000+08:00"
-	sqlResultTimeMilliFormat = "2006-01-02T15:04:05.000+08:00"
-	sqlResultTimeSecFormat   = "2006-01-02T15:04:05+08:00"
-)
-
-func ParseSqlResultTimeStr(timeStr string) (time.Time, error) {
-	layout := sqlResultTimeSecFormat
-
-	timeZoneIndex := strings.LastIndex(timeStr, "+08:")
-	if timeZoneIndex != -1 {
-		timeStr = timeStr[:timeZoneIndex]
-
-		afterSecondIndex := strings.LastIndex(timeStr, ".")
-		if afterSecondIndex != -1 {
-			if len(timeStr)-afterSecondIndex-1 == 6 {
-				layout = sqlResultTimeMicroFormat
-			} else if len(timeStr)-afterSecondIndex-1 == 3 {
-				layout = sqlResultTimeMilliFormat
-			}
-		}
-	}
-
-	return time.ParseInLocation(layout, timeStr, time.Local)
-}
-
-type SqlResult map[string]any
-
-func (result SqlResult) ColumnValueStringAsTime(columnName string) time.Time {
-	value, ok := result[columnName].(string)
-	if !ok {
-		return time.Time{}
-	}
-
-	t, err := ParseSqlResultTimeStr(value)
-	if err != nil {
-		return time.Time{}
-	}
-
-	return t
-}
-
-func (result SqlResult) ColumnValueBool(columnName string) bool {
-	value, err := reflectutils.ToBool(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return false
-	}
-
-	return value
-}
-
-func (result SqlResult) ColumnValueString(columnName string) string {
-	value, err := reflectutils.ToString(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return ""
-	}
-
-	return value
-}
-
-func (result SqlResult) ColumnValueInt(columnName string) int {
-	value, err := reflectutils.ToInt64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return int(value)
-}
-
-func (result SqlResult) ColumnValueInt8(columnName string) int8 {
-	value, err := reflectutils.ToInt64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return int8(value)
-}
-
-func (result SqlResult) ColumnValueInt16(columnName string) int16 {
-	value, err := reflectutils.ToInt64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return int16(value)
-}
-
-func (result SqlResult) ColumnValueInt32(columnName string) int32 {
-	value, err := reflectutils.ToInt64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return int32(value)
-}
-
-func (result SqlResult) ColumnValueInt64(columnName string) int64 {
-	value, err := reflectutils.ToInt64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return value
-}
-
-func (result SqlResult) ColumnValueUint(columnName string) uint {
-	value, err := reflectutils.ToUint64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return uint(value)
-}
-
-func (result SqlResult) ColumnValueUint8(columnName string) uint8 {
-	value, err := reflectutils.ToUint64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return uint8(value)
-}
-
-func (result SqlResult) ColumnValueUint16(columnName string) uint16 {
-	value, err := reflectutils.ToUint64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return uint16(value)
-}
-
-func (result SqlResult) ColumnValueUint32(columnName string) uint32 {
-	value, err := reflectutils.ToUint64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return uint32(value)
-}
-
-func (result SqlResult) ColumnValueUint64(columnName string) uint64 {
-	value, err := reflectutils.ToUint64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return value
-}
-
-func (result SqlResult) ColumnValueFloat32(columnName string) float32 {
-	value, err := reflectutils.ToFloat64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return float32(value)
-}
-
-func (result SqlResult) ColumnValueFloat64(columnName string) float64 {
-	value, err := reflectutils.ToFloat64(result[columnName])
-	if err != nil {
-		fmt.Println(err)
-		return 0
-	}
-
-	return value
-}

+ 2 - 2
sdk/transaction.go

@@ -15,7 +15,7 @@ type Transaction struct {
 	stream v1.SqlService_TransactionClient
 }
 
-func (tx *Transaction) ExecuteRawSql(sql string, values ...any) ([]SqlResult, error) {
+func (tx *Transaction) ExecuteRawSql(sql string, values ...any) ([]map[string]any, error) {
 	var retErr error
 
 	defer func() {
@@ -80,7 +80,7 @@ func (tx *Transaction) ExecuteRawSql(sql string, values ...any) ([]SqlResult, er
 		return nil, retErr
 	}
 
-	results := make([]SqlResult, len(tableRows))
+	results := make([]map[string]any, len(tableRows))
 	for i, row := range tableRows {
 		results[i] = row
 	}