yjp 9 месяцев назад
Родитель
Сommit
09948d15f4

+ 1 - 1
client/execute_sql_log.go

@@ -8,7 +8,7 @@ import (
 )
 )
 
 
 const (
 const (
-	getExecuteSqlLogsUrl = "/ds/api/v1/exec/sql/log/query"
+	getExecuteSqlLogsUrl = "/ds/api/v1/sql/exec/log/query"
 )
 )
 
 
 func (c *Client) GetExecuteSqlLogs(token string, baseUrl string, namespace string, dataSource string,
 func (c *Client) GetExecuteSqlLogs(token string, baseUrl string, namespace string, dataSource string,

+ 9 - 25
client/infos.go

@@ -5,37 +5,21 @@ type TokenInfo struct {
 }
 }
 
 
 type NamespaceInfo struct {
 type NamespaceInfo struct {
-	ID          string `json:"id"`
+	Name string `json:"name"`
-	Name        string `json:"name"`
-	Creator     string `json:"creator"`
-	CreatedTime string `json:"createdTime"`
 }
 }
 
 
 type DataSourceInfo struct {
 type DataSourceInfo struct {
-	Namespace   string `json:"namespace"`
+	Namespace string `json:"namespace"`
-	Name        string `json:"name"`
+	Name      string `json:"name"`
-	Type        string `json:"type"`
+	Type      string `json:"type"`
-	Spec        string `json:"spec"`
+	Spec      string `json:"spec"`
-	Creator     string `json:"creator"`
-	CreatedTime string `json:"createdTime"`
 }
 }
 
 
 type DataContainerInfo struct {
 type DataContainerInfo struct {
-	Namespace   string `json:"namespace"`
+	Namespace  string `json:"namespace"`
-	DataSource  string `json:"dataSource"`
+	DataSource string `json:"dataSource"`
-	Name        string `json:"name"`
+	Name       string `json:"name"`
-	Spec        string `json:"spec"`
+	Spec       string `json:"spec"`
-	Creator     string `json:"creator"`
-	CreatedTime string `json:"createdTime"`
-}
-
-type SqlInfo struct {
-	Namespace   string `json:"namespace"`
-	DataSource  string `json:"dataSource"`
-	Name        string `json:"name"`
-	Spec        string `json:"spec"`
-	Creator     string `json:"creator"`
-	CreatedTime string `json:"createdTime"`
 }
 }
 
 
 type ExecuteSqlLogInfo struct {
 type ExecuteSqlLogInfo struct {

+ 57 - 0
client/raw_sql.go

@@ -0,0 +1,57 @@
+package client
+
+import (
+	"fmt"
+	"git.sxidc.com/go-tools/api_binding/http_binding/response"
+	"git.sxidc.com/go-tools/utils/reflectutils"
+	"github.com/pkg/errors"
+	"net/url"
+	"reflect"
+)
+
+const (
+	executeRawSqlUrl = "/ds/api/v1/sql/rawSql/execute"
+)
+
+func (c *Client) ExecuteRawSql(token string, baseUrl string,
+	namespace string, dataSource string, sql string, values ...any) ([]map[string]any, error) {
+	fullUrl, err := url.JoinPath(baseUrl, executeRawSqlUrl)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := new(struct {
+		response.MsgResponse
+		Results []map[string]any `json:"results"`
+	})
+
+	rawSqlValues := make([]map[string]any, 0)
+	for _, value := range values {
+		typedValueReflectValue := reflect.ValueOf(value)
+		if !typedValueReflectValue.IsValid() {
+			return nil, errors.New("无效值")
+		}
+
+		typedValueReflectValueElem := reflectutils.PointerValueElem(typedValueReflectValue)
+		values = append(values, map[string]any{
+			"kind":  typedValueReflectValueElem.Kind(),
+			"value": typedValueReflectValueElem.Interface(),
+		})
+	}
+
+	err = c.post(token, fullUrl, map[string]any{
+		"namespace":  namespace,
+		"dataSource": dataSource,
+		"sql":        sql,
+		"values":     rawSqlValues,
+	}, resp)
+	if err != nil {
+		return nil, err
+	}
+
+	if !resp.Success {
+		return nil, fmt.Errorf(resp.Msg)
+	}
+
+	return resp.Results, nil
+}

+ 0 - 187
client/sql.go

@@ -1,187 +0,0 @@
-package client
-
-import (
-	"encoding/json"
-	"fmt"
-	"git.sxidc.com/go-tools/api_binding/http_binding/response"
-	"net/url"
-	"strconv"
-)
-
-const (
-	executeRawSqlUrl = "/ds/api/v1/sql/rawSql/execute"
-	parseSqlSpecUrl  = "/ds/api/v1/sql/spec/parse"
-	createSqlUrl     = "/ds/api/v1/sql/create"
-	deleteSqlUrl     = "/ds/api/v1/sql/delete"
-	getSqlsUrl       = "/ds/api/v1/sql/query"
-	executeSqlUrl    = "/ds/api/v1/sql/execute"
-)
-
-func (c *Client) ExecuteRawSql(token string, baseUrl string,
-	namespace string, dataSource string, sql string, executeParams map[string]any) ([]map[string]any, error) {
-	fullUrl, err := url.JoinPath(baseUrl, executeRawSqlUrl)
-	if err != nil {
-		return nil, err
-	}
-
-	resp := new(struct {
-		response.MsgResponse
-		Results []map[string]any `json:"results"`
-	})
-
-	err = c.post(token, fullUrl, map[string]any{
-		"namespace":     namespace,
-		"dataSource":    dataSource,
-		"sql":           sql,
-		"executeParams": executeParams,
-	}, resp)
-	if err != nil {
-		return nil, err
-	}
-
-	if !resp.Success {
-		return nil, fmt.Errorf(resp.Msg)
-	}
-
-	return resp.Results, nil
-}
-
-func (c *Client) ParseSqlSpec(token string, baseUrl string, spec map[string]any, executeParams map[string]any) (string, error) {
-	fullUrl, err := url.JoinPath(baseUrl, parseSqlSpecUrl)
-	if err != nil {
-		return "", err
-	}
-
-	resp := new(struct {
-		response.MsgResponse
-		Parsed string `json:"parsed"`
-	})
-
-	specJsonBytes, err := json.Marshal(spec)
-	if err != nil {
-		return "", err
-	}
-
-	err = c.post(token, fullUrl, map[string]any{
-		"sql":           string(specJsonBytes),
-		"executeParams": executeParams,
-	}, resp)
-	if err != nil {
-		return "", err
-	}
-
-	if !resp.Success {
-		return "", fmt.Errorf(resp.Msg)
-	}
-
-	return resp.Parsed, nil
-}
-
-func (c *Client) CreateSql(token string, baseUrl string, namespace string, dataSource string, name string, spec map[string]any) error {
-	fullUrl, err := url.JoinPath(baseUrl, createSqlUrl)
-	if err != nil {
-		return err
-	}
-
-	resp := new(response.MsgResponse)
-
-	specJsonBytes, err := json.Marshal(spec)
-	if err != nil {
-		return err
-	}
-
-	err = c.post(token, fullUrl, map[string]any{
-		"namespace":  namespace,
-		"dataSource": dataSource,
-		"name":       name,
-		"sql":        string(specJsonBytes),
-	}, resp)
-	if err != nil {
-		return err
-	}
-
-	if !resp.Success {
-		return fmt.Errorf(resp.Msg)
-	}
-
-	return nil
-}
-
-func (c *Client) DeleteSql(token string, baseUrl string, namespace string, dataSource string, name string) error {
-	fullUrl, err := url.JoinPath(baseUrl, deleteSqlUrl)
-	if err != nil {
-		return err
-	}
-
-	resp := new(response.MsgResponse)
-
-	err = c.post(token, fullUrl, map[string]any{
-		"namespace":  namespace,
-		"dataSource": dataSource,
-		"name":       name,
-	}, resp)
-	if err != nil {
-		return err
-	}
-
-	if !resp.Success {
-		return fmt.Errorf(resp.Msg)
-	}
-
-	return nil
-}
-
-func (c *Client) GetSqls(token string, baseUrl string, namespace string, dataSource string, name string, pageNo int, pageSize int) ([]SqlInfo, error) {
-	fullUrl, err := url.JoinPath(baseUrl, getSqlsUrl)
-	if err != nil {
-		return nil, err
-	}
-
-	resp := new(response.InfosResponse[SqlInfo])
-
-	err = c.get(token, fullUrl, map[string]string{
-		"namespace":  namespace,
-		"dataSource": dataSource,
-		"name":       name,
-		"pageNo":     strconv.Itoa(pageNo),
-		"pageSize":   strconv.Itoa(pageSize),
-	}, resp)
-	if err != nil {
-		return nil, err
-	}
-
-	if !resp.Success {
-		return nil, fmt.Errorf(resp.Msg)
-	}
-
-	return resp.Infos, nil
-}
-
-func (c *Client) ExecuteSql(token string, baseUrl string,
-	namespace string, dataSource string, name string, executeParams map[string]any) ([]map[string]any, error) {
-	fullUrl, err := url.JoinPath(baseUrl, executeSqlUrl)
-	if err != nil {
-		return nil, err
-	}
-
-	resp := new(struct {
-		response.MsgResponse
-		Results []map[string]any `json:"results"`
-	})
-
-	err = c.post(token, fullUrl, map[string]any{
-		"namespace":     namespace,
-		"dataSource":    dataSource,
-		"name":          name,
-		"executeParams": executeParams,
-	}, resp)
-	if err != nil {
-		return nil, err
-	}
-
-	if !resp.Success {
-		return nil, fmt.Errorf(resp.Msg)
-	}
-
-	return resp.Results, nil
-}

+ 0 - 55
demo/common.go

@@ -1,55 +0,0 @@
-package main
-
-import "time"
-
-const (
-	token      = "IpTTwAQweh/BP51fz5CzWKQFaXHvZe6ewvk6yOcAOkU="
-	address    = "localhost"
-	httpPort   = "10000"
-	grpcPort   = "10001"
-	namespace  = "ns-sdk-demo"
-	dataSource = "ds-sdk-demo"
-	deleteSql  = "delete-sdk-demo"
-	tableName  = "test.classes"
-)
-
-type IDField struct {
-	ID string
-}
-
-type TimeFields struct {
-	CreatedTime     *time.Time
-	LastUpdatedTime time.Time
-}
-
-type IgnoreStruct struct {
-	Field *string `sqlmapping:"-" sqlresult:"-"` // 这里如果结构字段上忽略了,结构中的字段可以不加忽略
-}
-
-type Class struct {
-	IDField
-	Name          string `sqlmapping:"updateClear;aes:@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L;"`
-	StudentNum    int    `sqlmapping:"column:student_num;notUpdate;updateClear;"`
-	GraduatedTime *time.Time
-	StudentIDs    []string `sqlmapping:"column:student_ids;joinWith:'\n'"`
-	TimeFields
-	Ignored       string           `sqlmapping:"-"`
-	*IgnoreStruct `sqlmapping:"-"` // 会忽略结构下的所有字段
-}
-
-type GraduatedTimeInfoStruct struct {
-	Time *string `sqlresult:"column:graduated_time;parseTime:2006-01-02 15:04:05"`
-}
-
-type ClassInfo struct {
-	IDField
-	Name          string `sqlresult:"aes:@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L;"`
-	StudentNum    int
-	GraduatedTime *time.Time
-	StudentIDs    []string `sqlresult:"column:student_ids;splitWith:'\n'"`
-	TimeFields
-	Ignored           string          `sqlresult:"-"`
-	*IgnoreStruct     `sqlresult:"-"` // 会忽略结构下的所有字段
-	GraduatedTimeTest *string         `sqlresult:"column:graduated_time;parseTime:2006-01-02 15:04:05"`
-	*GraduatedTimeInfoStruct
-}

+ 0 - 108
demo/sql_entity.go

@@ -1,108 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"git.sxidc.com/service-supports/ds-sdk/sql"
-	"git.sxidc.com/service-supports/ds-sdk/sql/sql_tpl"
-	"time"
-)
-
-func main() {
-	err := sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		panic(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	now := time.Now()
-	graduatedTime := now.AddDate(3, 0, 0)
-	classID := strutils.SimpleUUID()
-	studentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID(), strutils.SimpleUUID()}
-
-	class := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          "001",
-		StudentNum:    10,
-		GraduatedTime: &graduatedTime,
-		StudentIDs:    studentIDs,
-	}
-
-	newClass := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          "",
-		StudentNum:    30,
-		GraduatedTime: &graduatedTime,
-		StudentIDs:    studentIDs,
-	}
-
-	err = sql.InsertEntity(sdk.GetInstance(), tableName, class)
-	if err != nil {
-		panic(err)
-	}
-
-	result, err := sql.QueryOne(sdk.GetInstance(), &sql_tpl.QueryOneExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().Equal("id", classID),
-	})
-	if err != nil {
-		panic(err)
-	}
-
-	classInfoPtr, err := sql.ParseSqlResult[*Class](result)
-	if err != nil {
-		panic(err)
-	}
-
-	fmt.Println("Class Info:")
-	fmt.Printf("%#+v\n", classInfoPtr)
-
-	classInfos, err := sql.ParseSqlResult[[]*Class](result)
-	if err != nil {
-		panic(err)
-	}
-
-	fmt.Println("Class Info:")
-	fmt.Printf("%#+v\n", classInfos[0])
-
-	err = sql.UpdateEntity(sdk.GetInstance(), tableName, newClass)
-	if err != nil {
-		panic(err)
-	}
-
-	result, err = sql.QueryOne(sdk.GetInstance(), &sql_tpl.QueryOneExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().Equal("id", classID),
-	})
-	if err != nil {
-		panic(err)
-	}
-
-	classInfo, err := sql.ParseSqlResult[Class](result)
-	if err != nil {
-		panic(err)
-	}
-
-	fmt.Println("Class Info:")
-	fmt.Printf("%#+v\n", classInfo)
-
-	err = sql.DeleteEntity(sdk.GetInstance(), tableName, &Class{IDField: IDField{ID: classID}})
-	if err != nil {
-		panic(err)
-	}
-
-	_, err = sql.QueryOne(sdk.GetInstance(), &sql_tpl.QueryOneExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().Equal("id", classID),
-	})
-	if err != nil && !sdk.IsErrorDBRecordNotExist(err) {
-		panic(err)
-	}
-}

+ 0 - 65
demo/sql_entity_tx.go

@@ -1,65 +0,0 @@
-package main
-
-import (
-	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"git.sxidc.com/service-supports/ds-sdk/sql"
-	"time"
-)
-
-func main() {
-	err := sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		panic(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	now := time.Now()
-	graduatedTime := now.AddDate(3, 0, 0)
-	classID := strutils.SimpleUUID()
-	studentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID(), strutils.SimpleUUID()}
-
-	class := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          "001",
-		StudentNum:    10,
-		GraduatedTime: &graduatedTime,
-		StudentIDs:    studentIDs,
-	}
-
-	newClass := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          "",
-		StudentNum:    30,
-		GraduatedTime: &graduatedTime,
-		StudentIDs:    studentIDs,
-	}
-
-	err = sdk.GetInstance().Transaction(func(tx *sdk.Transaction) error {
-		err = sql.InsertEntity(tx, tableName, class)
-		if err != nil {
-			panic(err)
-		}
-
-		err = sql.UpdateEntity(tx, tableName, newClass)
-		if err != nil {
-			panic(err)
-		}
-
-		err = sql.DeleteEntity(tx, tableName, &Class{IDField: IDField{ID: classID}})
-		if err != nil {
-			panic(err)
-		}
-
-		return nil
-	})
-	if err != nil {
-		panic(err)
-	}
-}

+ 0 - 40
demo/sql_mapping.go

@@ -1,40 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"git.sxidc.com/service-supports/ds-sdk/sql"
-)
-
-func main() {
-	sqlMapping, err := sql.ParseSqlMappingTag(&Class{})
-	if err != nil {
-		panic(err)
-	}
-
-	printSqlMapping(sqlMapping)
-}
-
-func printSqlMapping(sqlMapping *sql.Mapping) {
-	for fieldName, mappingElement := range sqlMapping.MappingElement {
-		fmt.Println("---------------------------------------")
-		fmt.Println("Field Name: " + fieldName)
-
-		switch element := mappingElement.(type) {
-		case *sql.Mapping:
-			fmt.Println("Type: Struct")
-			printSqlMapping(element)
-		case *sql.MappingColumn:
-			fmt.Println("Type: Field")
-			fmt.Printf("Name: \"%s\"\n", element.Name)
-			fmt.Printf("IsKey: %v\n", element.IsKey)
-			fmt.Printf("CanUpdate: %v\n", element.CanUpdate)
-			fmt.Printf("CanUpdateClear: %v\n", element.CanUpdateClear)
-			fmt.Printf("AESKey: \"%s\"\n", element.AESKey)
-			fmt.Printf("JoinWith: \"%s\"\n", element.JoinWith)
-		default:
-			fmt.Println("类型错误")
-		}
-
-		fmt.Println("---------------------------------------")
-	}
-}

+ 0 - 39
demo/sql_result.go

@@ -1,39 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"git.sxidc.com/service-supports/ds-sdk/sql"
-)
-
-func main() {
-	// 必须使用结构指针或者[]指针,要接收返回值
-	sqlResult, err := sql.ParseSqlResultTag(&ClassInfo{})
-	if err != nil {
-		panic(err)
-	}
-
-	printSqlResult(sqlResult)
-}
-
-func printSqlResult(sqlResult *sql.Result) {
-	for fieldName, resultElement := range sqlResult.ResultElement {
-		fmt.Println("---------------------------------------")
-		fmt.Println("Field Name: " + fieldName)
-
-		switch element := resultElement.(type) {
-		case *sql.Result:
-			fmt.Println("Type: Struct")
-			printSqlResult(element)
-		case *sql.ResultColumn:
-			fmt.Println("Type: Field")
-			fmt.Printf("Name: \"%s\"\n", element.Name)
-			fmt.Printf("ParseTime: \"%s\"\n", element.ParseTime)
-			fmt.Printf("AESKey: \"%s\"\n", element.AESKey)
-			fmt.Printf("SplitWith: \"%s\"\n", element.SplitWith)
-		default:
-			fmt.Println("类型错误")
-		}
-
-		fmt.Println("---------------------------------------")
-	}
-}

+ 3 - 3
go.mod

@@ -4,11 +4,12 @@ go 1.22.0
 
 
 require (
 require (
 	git.sxidc.com/go-tools/api_binding v1.3.23
 	git.sxidc.com/go-tools/api_binding v1.3.23
-	git.sxidc.com/go-tools/utils v1.5.6
+	git.sxidc.com/go-tools/utils v1.5.23
 	github.com/fatih/structs v1.1.0
 	github.com/fatih/structs v1.1.0
 	github.com/golang/protobuf v1.5.4
 	github.com/golang/protobuf v1.5.4
 	github.com/iancoleman/strcase v0.3.0
 	github.com/iancoleman/strcase v0.3.0
 	github.com/mwitkow/go-proto-validators v0.3.2
 	github.com/mwitkow/go-proto-validators v0.3.2
+	github.com/pkg/errors v0.9.1
 	google.golang.org/grpc v1.63.2
 	google.golang.org/grpc v1.63.2
 	google.golang.org/protobuf v1.33.0
 	google.golang.org/protobuf v1.33.0
 )
 )
@@ -37,9 +38,8 @@ require (
 	github.com/mattn/go-isatty v0.0.19 // indirect
 	github.com/mattn/go-isatty v0.0.19 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
-	github.com/olahol/melody v1.1.1 // indirect
+	github.com/olahol/melody v1.2.1 // indirect
 	github.com/pelletier/go-toml/v2 v2.1.0 // indirect
 	github.com/pelletier/go-toml/v2 v2.1.0 // indirect
-	github.com/pkg/errors v0.9.1 // indirect
 	github.com/rogpeppe/go-internal v1.12.0 // indirect
 	github.com/rogpeppe/go-internal v1.12.0 // indirect
 	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

+ 4 - 4
go.sum

@@ -1,7 +1,7 @@
 git.sxidc.com/go-tools/api_binding v1.3.23 h1:vgCdYq09aiw7Vs9JeOR0OZLOjezbHugQ/3ABeakvD4g=
 git.sxidc.com/go-tools/api_binding v1.3.23 h1:vgCdYq09aiw7Vs9JeOR0OZLOjezbHugQ/3ABeakvD4g=
 git.sxidc.com/go-tools/api_binding v1.3.23/go.mod h1:SmUnRrMtODonLzWmWCGQN9uAB2TjH8g5yEKFnp4rEgU=
 git.sxidc.com/go-tools/api_binding v1.3.23/go.mod h1:SmUnRrMtODonLzWmWCGQN9uAB2TjH8g5yEKFnp4rEgU=
-git.sxidc.com/go-tools/utils v1.5.6 h1:Hf8QgpagqMCNJg4FuZcKCfs7myqeQBW6hM02SUl3vro=
+git.sxidc.com/go-tools/utils v1.5.23 h1:Kbcj+EafFVssRa6i1jnILi+LddLWMDtyvRzuV26C6fU=
-git.sxidc.com/go-tools/utils v1.5.6/go.mod h1:d8cjo9Wz5Vm/79pg3H43woycgZ74brPO0RysPDOBh2k=
+git.sxidc.com/go-tools/utils v1.5.23/go.mod h1:uTDb6QK5JZzK5+Fzsfeng7TwmnRDZiTY6JLYxIX94Qw=
 git.sxidc.com/service-supports/fserr v0.3.2 h1:5/FCr8o2jd1kNsp5tH/ADjB9fr091JZXMMZ15ZvNZzs=
 git.sxidc.com/service-supports/fserr v0.3.2 h1:5/FCr8o2jd1kNsp5tH/ADjB9fr091JZXMMZ15ZvNZzs=
 git.sxidc.com/service-supports/fserr v0.3.2/go.mod h1:W54RoA71mfex+zARuH/iMnQPMnBXQ23qXXOkwUh2sVQ=
 git.sxidc.com/service-supports/fserr v0.3.2/go.mod h1:W54RoA71mfex+zARuH/iMnQPMnBXQ23qXXOkwUh2sVQ=
 git.sxidc.com/service-supports/fslog v0.5.9 h1:q2XIK2o/fk/qmByy4x5kKLC+k7kolT5LrXHcWRSffXQ=
 git.sxidc.com/service-supports/fslog v0.5.9 h1:q2XIK2o/fk/qmByy4x5kKLC+k7kolT5LrXHcWRSffXQ=
@@ -83,8 +83,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 github.com/mwitkow/go-proto-validators v0.3.2 h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=
 github.com/mwitkow/go-proto-validators v0.3.2 h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=
 github.com/mwitkow/go-proto-validators v0.3.2/go.mod h1:ej0Qp0qMgHN/KtDyUt+Q1/tA7a5VarXUOUxD+oeD30w=
 github.com/mwitkow/go-proto-validators v0.3.2/go.mod h1:ej0Qp0qMgHN/KtDyUt+Q1/tA7a5VarXUOUxD+oeD30w=
-github.com/olahol/melody v1.1.1 h1:amgBhR7pDY0rA0JHWprgLF0LnVztognAwEQgf/WYLVM=
+github.com/olahol/melody v1.2.1 h1:xdwRkzHxf+B0w4TKbGpUSSkV516ZucQZJIWLztOWICQ=
-github.com/olahol/melody v1.1.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=
+github.com/olahol/melody v1.2.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=
 github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
 github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
 github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
 github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

+ 42 - 212
grpc_client/v1/request/sql.pb.go

@@ -122,116 +122,6 @@ func (*TransactionEndRequest) Descriptor() ([]byte, []int) {
 	return file_v1_request_sql_proto_rawDescGZIP(), []int{1}
 	return file_v1_request_sql_proto_rawDescGZIP(), []int{1}
 }
 }
 
 
-type ExecuteRawSqlRequest struct {
-	state         protoimpl.MessageState
-	sizeCache     protoimpl.SizeCache
-	unknownFields protoimpl.UnknownFields
-
-	SQL           string `protobuf:"bytes,1,opt,name=SQL,proto3" json:"SQL,omitempty"`
-	ExecuteParams string `protobuf:"bytes,2,opt,name=ExecuteParams,proto3" json:"ExecuteParams,omitempty"`
-}
-
-func (x *ExecuteRawSqlRequest) Reset() {
-	*x = ExecuteRawSqlRequest{}
-	if protoimpl.UnsafeEnabled {
-		mi := &file_v1_request_sql_proto_msgTypes[2]
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		ms.StoreMessageInfo(mi)
-	}
-}
-
-func (x *ExecuteRawSqlRequest) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ExecuteRawSqlRequest) ProtoMessage() {}
-
-func (x *ExecuteRawSqlRequest) ProtoReflect() protoreflect.Message {
-	mi := &file_v1_request_sql_proto_msgTypes[2]
-	if protoimpl.UnsafeEnabled && x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-// Deprecated: Use ExecuteRawSqlRequest.ProtoReflect.Descriptor instead.
-func (*ExecuteRawSqlRequest) Descriptor() ([]byte, []int) {
-	return file_v1_request_sql_proto_rawDescGZIP(), []int{2}
-}
-
-func (x *ExecuteRawSqlRequest) GetSQL() string {
-	if x != nil {
-		return x.SQL
-	}
-	return ""
-}
-
-func (x *ExecuteRawSqlRequest) GetExecuteParams() string {
-	if x != nil {
-		return x.ExecuteParams
-	}
-	return ""
-}
-
-type ExecuteSqlRequest struct {
-	state         protoimpl.MessageState
-	sizeCache     protoimpl.SizeCache
-	unknownFields protoimpl.UnknownFields
-
-	Name          string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"`
-	ExecuteParams string `protobuf:"bytes,2,opt,name=ExecuteParams,proto3" json:"ExecuteParams,omitempty"`
-}
-
-func (x *ExecuteSqlRequest) Reset() {
-	*x = ExecuteSqlRequest{}
-	if protoimpl.UnsafeEnabled {
-		mi := &file_v1_request_sql_proto_msgTypes[3]
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		ms.StoreMessageInfo(mi)
-	}
-}
-
-func (x *ExecuteSqlRequest) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ExecuteSqlRequest) ProtoMessage() {}
-
-func (x *ExecuteSqlRequest) ProtoReflect() protoreflect.Message {
-	mi := &file_v1_request_sql_proto_msgTypes[3]
-	if protoimpl.UnsafeEnabled && x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-// Deprecated: Use ExecuteSqlRequest.ProtoReflect.Descriptor instead.
-func (*ExecuteSqlRequest) Descriptor() ([]byte, []int) {
-	return file_v1_request_sql_proto_rawDescGZIP(), []int{3}
-}
-
-func (x *ExecuteSqlRequest) GetName() string {
-	if x != nil {
-		return x.Name
-	}
-	return ""
-}
-
-func (x *ExecuteSqlRequest) GetExecuteParams() string {
-	if x != nil {
-		return x.ExecuteParams
-	}
-	return ""
-}
-
 type TransactionOperation struct {
 type TransactionOperation struct {
 	state         protoimpl.MessageState
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	sizeCache     protoimpl.SizeCache
@@ -241,15 +131,14 @@ type TransactionOperation struct {
 	//
 	//
 	//	*TransactionOperation_TransactionBeginRequest
 	//	*TransactionOperation_TransactionBeginRequest
 	//	*TransactionOperation_TransactionEndRequest
 	//	*TransactionOperation_TransactionEndRequest
-	//	*TransactionOperation_ExecuteRawSqlRequest
+	//	*TransactionOperation_ExecuteRawSqlJsonRequest
-	//	*TransactionOperation_ExecuteSqlRequest
 	Request isTransactionOperation_Request `protobuf_oneof:"Request"`
 	Request isTransactionOperation_Request `protobuf_oneof:"Request"`
 }
 }
 
 
 func (x *TransactionOperation) Reset() {
 func (x *TransactionOperation) Reset() {
 	*x = TransactionOperation{}
 	*x = TransactionOperation{}
 	if protoimpl.UnsafeEnabled {
 	if protoimpl.UnsafeEnabled {
-		mi := &file_v1_request_sql_proto_msgTypes[4]
+		mi := &file_v1_request_sql_proto_msgTypes[2]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 		ms.StoreMessageInfo(mi)
 	}
 	}
@@ -262,7 +151,7 @@ func (x *TransactionOperation) String() string {
 func (*TransactionOperation) ProtoMessage() {}
 func (*TransactionOperation) ProtoMessage() {}
 
 
 func (x *TransactionOperation) ProtoReflect() protoreflect.Message {
 func (x *TransactionOperation) ProtoReflect() protoreflect.Message {
-	mi := &file_v1_request_sql_proto_msgTypes[4]
+	mi := &file_v1_request_sql_proto_msgTypes[2]
 	if protoimpl.UnsafeEnabled && x != nil {
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
 		if ms.LoadMessageInfo() == nil {
@@ -275,7 +164,7 @@ func (x *TransactionOperation) ProtoReflect() protoreflect.Message {
 
 
 // Deprecated: Use TransactionOperation.ProtoReflect.Descriptor instead.
 // Deprecated: Use TransactionOperation.ProtoReflect.Descriptor instead.
 func (*TransactionOperation) Descriptor() ([]byte, []int) {
 func (*TransactionOperation) Descriptor() ([]byte, []int) {
-	return file_v1_request_sql_proto_rawDescGZIP(), []int{4}
+	return file_v1_request_sql_proto_rawDescGZIP(), []int{2}
 }
 }
 
 
 func (m *TransactionOperation) GetRequest() isTransactionOperation_Request {
 func (m *TransactionOperation) GetRequest() isTransactionOperation_Request {
@@ -299,18 +188,11 @@ func (x *TransactionOperation) GetTransactionEndRequest() *TransactionEndRequest
 	return nil
 	return nil
 }
 }
 
 
-func (x *TransactionOperation) GetExecuteRawSqlRequest() *ExecuteRawSqlRequest {
+func (x *TransactionOperation) GetExecuteRawSqlJsonRequest() string {
-	if x, ok := x.GetRequest().(*TransactionOperation_ExecuteRawSqlRequest); ok {
+	if x, ok := x.GetRequest().(*TransactionOperation_ExecuteRawSqlJsonRequest); ok {
-		return x.ExecuteRawSqlRequest
+		return x.ExecuteRawSqlJsonRequest
-	}
-	return nil
-}
-
-func (x *TransactionOperation) GetExecuteSqlRequest() *ExecuteSqlRequest {
-	if x, ok := x.GetRequest().(*TransactionOperation_ExecuteSqlRequest); ok {
-		return x.ExecuteSqlRequest
 	}
 	}
-	return nil
+	return ""
 }
 }
 
 
 type isTransactionOperation_Request interface {
 type isTransactionOperation_Request interface {
@@ -325,21 +207,15 @@ type TransactionOperation_TransactionEndRequest struct {
 	TransactionEndRequest *TransactionEndRequest `protobuf:"bytes,2,opt,name=TransactionEndRequest,proto3,oneof"`
 	TransactionEndRequest *TransactionEndRequest `protobuf:"bytes,2,opt,name=TransactionEndRequest,proto3,oneof"`
 }
 }
 
 
-type TransactionOperation_ExecuteRawSqlRequest struct {
+type TransactionOperation_ExecuteRawSqlJsonRequest struct {
-	ExecuteRawSqlRequest *ExecuteRawSqlRequest `protobuf:"bytes,3,opt,name=ExecuteRawSqlRequest,proto3,oneof"`
+	ExecuteRawSqlJsonRequest string `protobuf:"bytes,3,opt,name=ExecuteRawSqlJsonRequest,proto3,oneof"`
-}
-
-type TransactionOperation_ExecuteSqlRequest struct {
-	ExecuteSqlRequest *ExecuteSqlRequest `protobuf:"bytes,4,opt,name=ExecuteSqlRequest,proto3,oneof"`
 }
 }
 
 
 func (*TransactionOperation_TransactionBeginRequest) isTransactionOperation_Request() {}
 func (*TransactionOperation_TransactionBeginRequest) isTransactionOperation_Request() {}
 
 
 func (*TransactionOperation_TransactionEndRequest) isTransactionOperation_Request() {}
 func (*TransactionOperation_TransactionEndRequest) isTransactionOperation_Request() {}
 
 
-func (*TransactionOperation_ExecuteRawSqlRequest) isTransactionOperation_Request() {}
+func (*TransactionOperation_ExecuteRawSqlJsonRequest) isTransactionOperation_Request() {}
-
-func (*TransactionOperation_ExecuteSqlRequest) isTransactionOperation_Request() {}
 
 
 var File_v1_request_sql_proto protoreflect.FileDescriptor
 var File_v1_request_sql_proto protoreflect.FileDescriptor
 
 
@@ -359,44 +235,27 @@ var file_v1_request_sql_proto_rawDesc = []byte{
 	0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xe2, 0xdf, 0x1f,
 	0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xe2, 0xdf, 0x1f,
 	0x02, 0x58, 0x01, 0x52, 0x0a, 0x44, 0x61, 0x74, 0x61, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22,
 	0x02, 0x58, 0x01, 0x52, 0x0a, 0x44, 0x61, 0x74, 0x61, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22,
 	0x17, 0x0a, 0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e,
 	0x17, 0x0a, 0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e,
-	0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x56, 0x0a, 0x14, 0x45, 0x78, 0x65, 0x63,
+	0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x95, 0x02, 0x0a, 0x14, 0x54, 0x72, 0x61,
-	0x75, 0x74, 0x65, 0x52, 0x61, 0x77, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
+	0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
-	0x12, 0x18, 0x0a, 0x03, 0x53, 0x51, 0x4c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xe2,
+	0x6e, 0x12, 0x5c, 0x0a, 0x17, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
-	0xdf, 0x1f, 0x02, 0x58, 0x01, 0x52, 0x03, 0x53, 0x51, 0x4c, 0x12, 0x24, 0x0a, 0x0d, 0x45, 0x78,
+	0x42, 0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01,
-	0x65, 0x63, 0x75, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28,
+	0x28, 0x0b, 0x32, 0x20, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x72, 0x61,
-	0x09, 0x52, 0x0d, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73,
+	0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71,
-	0x22, 0x55, 0x0a, 0x11, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x53, 0x71, 0x6c, 0x52, 0x65,
+	0x75, 0x65, 0x73, 0x74, 0x48, 0x00, 0x52, 0x17, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74,
-	0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
+	0x69, 0x6f, 0x6e, 0x42, 0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
-	0x01, 0x28, 0x09, 0x42, 0x06, 0xe2, 0xdf, 0x1f, 0x02, 0x58, 0x01, 0x52, 0x04, 0x4e, 0x61, 0x6d,
+	0x56, 0x0a, 0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e,
-	0x65, 0x12, 0x24, 0x0a, 0x0d, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61,
+	0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e,
-	0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
+	0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63,
-	0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xf8, 0x02, 0x0a, 0x14, 0x54, 0x72, 0x61, 0x6e,
+	0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x00,
-	0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e,
+	0x52, 0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64,
-	0x12, 0x5c, 0x0a, 0x17, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x3c, 0x0a, 0x18, 0x45, 0x78, 0x65, 0x63, 0x75,
-	0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
+	0x74, 0x65, 0x52, 0x61, 0x77, 0x53, 0x71, 0x6c, 0x4a, 0x73, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75,
-	0x0b, 0x32, 0x20, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x6e,
+	0x65, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x18, 0x45, 0x78, 0x65,
-	0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75,
+	0x63, 0x75, 0x74, 0x65, 0x52, 0x61, 0x77, 0x53, 0x71, 0x6c, 0x4a, 0x73, 0x6f, 0x6e, 0x52, 0x65,
-	0x65, 0x73, 0x74, 0x48, 0x00, 0x52, 0x17, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69,
+	0x71, 0x75, 0x65, 0x73, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
-	0x6f, 0x6e, 0x42, 0x65, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x56,
+	0x42, 0x1b, 0x5a, 0x19, 0x64, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f,
-	0x0a, 0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64,
+	0x70, 0x62, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70,
-	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e,
+	0x72, 0x6f, 0x74, 0x6f, 0x33,
-	0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74,
-	0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x00, 0x52,
-	0x15, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64, 0x52,
-	0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x53, 0x0a, 0x14, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
-	0x65, 0x52, 0x61, 0x77, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x03,
-	0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45,
-	0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x61, 0x77, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x48, 0x00, 0x52, 0x14, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x61,
-	0x77, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x4a, 0x0a, 0x11, 0x45,
-	0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
-	0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
-	0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x53, 0x71, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x48, 0x00, 0x52, 0x11, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x53, 0x71, 0x6c,
-	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x42, 0x1f, 0x5a, 0x1d, 0x64, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70,
-	0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 }
 
 
 var (
 var (
@@ -411,24 +270,20 @@ func file_v1_request_sql_proto_rawDescGZIP() []byte {
 	return file_v1_request_sql_proto_rawDescData
 	return file_v1_request_sql_proto_rawDescData
 }
 }
 
 
-var file_v1_request_sql_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
+var file_v1_request_sql_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
 var file_v1_request_sql_proto_goTypes = []interface{}{
 var file_v1_request_sql_proto_goTypes = []interface{}{
 	(*TransactionBeginRequest)(nil), // 0: request.TransactionBeginRequest
 	(*TransactionBeginRequest)(nil), // 0: request.TransactionBeginRequest
 	(*TransactionEndRequest)(nil),   // 1: request.TransactionEndRequest
 	(*TransactionEndRequest)(nil),   // 1: request.TransactionEndRequest
-	(*ExecuteRawSqlRequest)(nil),    // 2: request.ExecuteRawSqlRequest
+	(*TransactionOperation)(nil),    // 2: request.TransactionOperation
-	(*ExecuteSqlRequest)(nil),       // 3: request.ExecuteSqlRequest
-	(*TransactionOperation)(nil),    // 4: request.TransactionOperation
 }
 }
 var file_v1_request_sql_proto_depIdxs = []int32{
 var file_v1_request_sql_proto_depIdxs = []int32{
 	0, // 0: request.TransactionOperation.TransactionBeginRequest:type_name -> request.TransactionBeginRequest
 	0, // 0: request.TransactionOperation.TransactionBeginRequest:type_name -> request.TransactionBeginRequest
 	1, // 1: request.TransactionOperation.TransactionEndRequest:type_name -> request.TransactionEndRequest
 	1, // 1: request.TransactionOperation.TransactionEndRequest:type_name -> request.TransactionEndRequest
-	2, // 2: request.TransactionOperation.ExecuteRawSqlRequest:type_name -> request.ExecuteRawSqlRequest
+	2, // [2:2] is the sub-list for method output_type
-	3, // 3: request.TransactionOperation.ExecuteSqlRequest:type_name -> request.ExecuteSqlRequest
+	2, // [2:2] is the sub-list for method input_type
-	4, // [4:4] is the sub-list for method output_type
+	2, // [2:2] is the sub-list for extension type_name
-	4, // [4:4] is the sub-list for method input_type
+	2, // [2:2] is the sub-list for extension extendee
-	4, // [4:4] is the sub-list for extension type_name
+	0, // [0:2] is the sub-list for field type_name
-	4, // [4:4] is the sub-list for extension extendee
-	0, // [0:4] is the sub-list for field type_name
 }
 }
 
 
 func init() { file_v1_request_sql_proto_init() }
 func init() { file_v1_request_sql_proto_init() }
@@ -462,30 +317,6 @@ func file_v1_request_sql_proto_init() {
 			}
 			}
 		}
 		}
 		file_v1_request_sql_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 		file_v1_request_sql_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*ExecuteRawSqlRequest); i {
-			case 0:
-				return &v.state
-			case 1:
-				return &v.sizeCache
-			case 2:
-				return &v.unknownFields
-			default:
-				return nil
-			}
-		}
-		file_v1_request_sql_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*ExecuteSqlRequest); i {
-			case 0:
-				return &v.state
-			case 1:
-				return &v.sizeCache
-			case 2:
-				return &v.unknownFields
-			default:
-				return nil
-			}
-		}
-		file_v1_request_sql_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TransactionOperation); i {
 			switch v := v.(*TransactionOperation); i {
 			case 0:
 			case 0:
 				return &v.state
 				return &v.state
@@ -498,11 +329,10 @@ func file_v1_request_sql_proto_init() {
 			}
 			}
 		}
 		}
 	}
 	}
-	file_v1_request_sql_proto_msgTypes[4].OneofWrappers = []interface{}{
+	file_v1_request_sql_proto_msgTypes[2].OneofWrappers = []interface{}{
 		(*TransactionOperation_TransactionBeginRequest)(nil),
 		(*TransactionOperation_TransactionBeginRequest)(nil),
 		(*TransactionOperation_TransactionEndRequest)(nil),
 		(*TransactionOperation_TransactionEndRequest)(nil),
-		(*TransactionOperation_ExecuteRawSqlRequest)(nil),
+		(*TransactionOperation_ExecuteRawSqlJsonRequest)(nil),
-		(*TransactionOperation_ExecuteSqlRequest)(nil),
 	}
 	}
 	type x struct{}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
 	out := protoimpl.TypeBuilder{
@@ -510,7 +340,7 @@ func file_v1_request_sql_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_v1_request_sql_proto_rawDesc,
 			RawDescriptor: file_v1_request_sql_proto_rawDesc,
 			NumEnums:      0,
 			NumEnums:      0,
-			NumMessages:   5,
+			NumMessages:   3,
 			NumExtensions: 0,
 			NumExtensions: 0,
 			NumServices:   0,
 			NumServices:   0,
 		},
 		},

+ 0 - 26
grpc_client/v1/request/sql.validator.pb.go

@@ -31,18 +31,6 @@ func (this *TransactionBeginRequest) Validate() error {
 func (this *TransactionEndRequest) Validate() error {
 func (this *TransactionEndRequest) Validate() error {
 	return nil
 	return nil
 }
 }
-func (this *ExecuteRawSqlRequest) Validate() error {
-	if this.SQL == "" {
-		return github_com_mwitkow_go_proto_validators.FieldError("SQL", fmt.Errorf(`value '%v' must not be an empty string`, this.SQL))
-	}
-	return nil
-}
-func (this *ExecuteSqlRequest) Validate() error {
-	if this.Name == "" {
-		return github_com_mwitkow_go_proto_validators.FieldError("Name", fmt.Errorf(`value '%v' must not be an empty string`, this.Name))
-	}
-	return nil
-}
 func (this *TransactionOperation) Validate() error {
 func (this *TransactionOperation) Validate() error {
 	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_TransactionBeginRequest); ok {
 	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_TransactionBeginRequest); ok {
 		if oneOfNester.TransactionBeginRequest != nil {
 		if oneOfNester.TransactionBeginRequest != nil {
@@ -58,19 +46,5 @@ func (this *TransactionOperation) Validate() error {
 			}
 			}
 		}
 		}
 	}
 	}
-	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_ExecuteRawSqlRequest); ok {
-		if oneOfNester.ExecuteRawSqlRequest != nil {
-			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.ExecuteRawSqlRequest); err != nil {
-				return github_com_mwitkow_go_proto_validators.FieldError("ExecuteRawSqlRequest", err)
-			}
-		}
-	}
-	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_ExecuteSqlRequest); ok {
-		if oneOfNester.ExecuteSqlRequest != nil {
-			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.ExecuteSqlRequest); err != nil {
-				return github_com_mwitkow_go_proto_validators.FieldError("ExecuteSqlRequest", err)
-			}
-		}
-	}
 	return nil
 	return nil
 }
 }

+ 4 - 4
grpc_client/v1/response/sql.pb.go

@@ -93,10 +93,10 @@ var file_v1_response_sql_proto_rawDesc = []byte{
 	0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65,
 	0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65,
 	0x73, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
 	0x73, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
 	0x03, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18,
 	0x03, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18,
-	0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x42, 0x20,
+	0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x42, 0x1c,
-	0x5a, 0x1e, 0x64, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70,
+	0x5a, 0x1a, 0x64, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62,
-	0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
+	0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72,
-	0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x6f, 0x74, 0x6f, 0x33,
 }
 }
 
 
 var (
 var (

+ 2 - 3
grpc_client/v1/sql.pb.go

@@ -34,9 +34,8 @@ var file_v1_sql_proto_rawDesc = []byte{
 	0x6f, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x1d, 0x2e, 0x72, 0x65,
 	0x6f, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x1d, 0x2e, 0x72, 0x65,
 	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69,
 	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69,
 	0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01,
 	0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01,
-	0x42, 0x17, 0x5a, 0x15, 0x64, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f,
+	0x42, 0x13, 0x5a, 0x11, 0x64, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f,
-	0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+	0x70, 0x62, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
-	0x33,
 }
 }
 
 
 var file_v1_sql_proto_goTypes = []interface{}{
 var file_v1_sql_proto_goTypes = []interface{}{

+ 0 - 19
sdk/error.go

@@ -1,19 +0,0 @@
-package sdk
-
-import (
-	"errors"
-	"strings"
-)
-
-var (
-	ErrDBRecordHasExist = errors.New("记录已存在")
-	ErrDBRecordNotExist = errors.New("记录不存在")
-)
-
-func IsErrorDBRecordHasExist(err error) bool {
-	return strings.Contains(err.Error(), "记录已存在")
-}
-
-func IsErrorDBRecordNotExist(err error) bool {
-	return strings.Contains(err.Error(), "记录不存在")
-}

+ 1 - 1
sdk/instance.go

@@ -1,9 +1,9 @@
 package sdk
 package sdk
 
 
 import (
 import (
-	"errors"
 	"git.sxidc.com/service-supports/ds-sdk/client"
 	"git.sxidc.com/service-supports/ds-sdk/client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client"
+	"github.com/pkg/errors"
 )
 )
 
 
 var sdkInstance *SDK
 var sdkInstance *SDK

+ 1 - 54
sdk/sdk.go

@@ -1,11 +1,11 @@
 package sdk
 package sdk
 
 
 import (
 import (
-	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/ds-sdk/client"
 	"git.sxidc.com/service-supports/ds-sdk/client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1/request"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1/request"
+	"github.com/pkg/errors"
 	"io"
 	"io"
 )
 )
 
 
@@ -36,59 +36,6 @@ func (s *SDK) ExecuteRawSql(sql string, executeParams map[string]any) ([]SqlResu
 	return results, nil
 	return results, nil
 }
 }
 
 
-func (s *SDK) CreateSQL(name string, spec map[string]any) error {
-	if strutils.IsStringEmpty(name) {
-		return errors.New("没有传递SQL资源名称")
-	}
-
-	options := s.options
-
-	err := s.client.CreateSql(options.token, options.baseUrl,
-		options.namespace, options.dataSource, name, spec)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func (s *SDK) DeleteSQL(name string) error {
-	if strutils.IsStringEmpty(name) {
-		return errors.New("没有传递SQL资源名称")
-	}
-
-	options := s.options
-
-	err := s.client.DeleteSql(options.token, options.baseUrl,
-		options.namespace, options.dataSource, name)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func (s *SDK) ExecuteSql(name string, executeParams map[string]any) ([]SqlResult, error) {
-	if strutils.IsStringEmpty(name) {
-		return nil, errors.New("没有传递SQL资源名称")
-	}
-
-	options := s.options
-
-	tableRows, err := s.client.ExecuteSql(options.token, options.baseUrl,
-		options.namespace, options.dataSource, name, executeParams)
-	if err != nil {
-		return nil, err
-	}
-
-	results := make([]SqlResult, len(tableRows))
-	for i, row := range tableRows {
-		results[i] = row
-	}
-
-	return results, nil
-}
-
 func (s *SDK) Transaction(txFunc TxFunc) error {
 func (s *SDK) Transaction(txFunc TxFunc) error {
 	stream, err := s.grpcClient.Transaction()
 	stream, err := s.grpcClient.Transaction()
 	if err != nil {
 	if err != nil {

+ 0 - 9
sdk/spec.go

@@ -38,12 +38,3 @@ type DataContainerDatabaseColumnSpec struct {
 func (spec *DataContainerDatabaseSpec) ToMap() map[string]any {
 func (spec *DataContainerDatabaseSpec) ToMap() map[string]any {
 	return structs.Map(spec)
 	return structs.Map(spec)
 }
 }
-
-type SqlSpec struct {
-	Transaction bool   `structs:"transaction"`
-	Clauses     string `structs:"clauses"`
-}
-
-func (spec *SqlSpec) ToMap() map[string]any {
-	return structs.Map(spec)
-}

+ 23 - 62
sdk/transaction.go

@@ -2,9 +2,11 @@ package sdk
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
-	"errors"
+	"git.sxidc.com/go-tools/utils/reflectutils"
-	v1 "git.sxidc.com/service-supports/ds-sdk/grpc_client/v1"
+	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1/request"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1/request"
+	"github.com/pkg/errors"
+	"reflect"
 )
 )
 
 
 type TxFunc func(tx *Transaction) error
 type TxFunc func(tx *Transaction) error
@@ -13,7 +15,7 @@ type Transaction struct {
 	stream v1.SqlService_TransactionClient
 	stream v1.SqlService_TransactionClient
 }
 }
 
 
-func (tx *Transaction) ExecuteRawSql(sql string, executeParams map[string]any) ([]SqlResult, error) {
+func (tx *Transaction) ExecuteRawSql(sql string, values ...any) ([]SqlResult, error) {
 	var retErr error
 	var retErr error
 
 
 	defer func() {
 	defer func() {
@@ -25,75 +27,34 @@ func (tx *Transaction) ExecuteRawSql(sql string, executeParams map[string]any) (
 		}
 		}
 	}()
 	}()
 
 
-	executeParamsJsonBytes, err := json.Marshal(executeParams)
+	rawSqlValues := make([]map[string]any, 0)
-	if err != nil {
+	for _, value := range values {
-		retErr = err
+		typedValueReflectValue := reflect.ValueOf(value)
-		return nil, retErr
+		if !typedValueReflectValue.IsValid() {
-	}
+			return nil, errors.New("无效值")
-
+		}
-	err = tx.stream.SendMsg(&request.TransactionOperation{
-		Request: &request.TransactionOperation_ExecuteRawSqlRequest{
-			ExecuteRawSqlRequest: &request.ExecuteRawSqlRequest{
-				SQL:           sql,
-				ExecuteParams: string(executeParamsJsonBytes),
-			},
-		},
-	})
-	if err != nil {
-		retErr = err
-		return nil, retErr
-	}
 
 
-	resp, err := tx.stream.Recv()
+		typedValueReflectValueElem := reflectutils.PointerValueElem(typedValueReflectValue)
-	if err != nil {
+		values = append(values, map[string]any{
-		retErr = err
+			"kind":  typedValueReflectValueElem.Kind(),
-		return nil, retErr
+			"value": typedValueReflectValueElem.Interface(),
+		})
 	}
 	}
 
 
-	if !resp.Success {
+	requestMap := map[string]any{
-		retErr = errors.New(resp.Msg)
+		"sql":    sql,
-		return nil, retErr
+		"values": rawSqlValues,
 	}
 	}
 
 
-	tableRows := make([]map[string]any, 0)
+	requestJsonBytes, err := json.Marshal(requestMap)
-	err = json.Unmarshal([]byte(resp.Results), &tableRows)
 	if err != nil {
 	if err != nil {
 		retErr = err
 		retErr = err
 		return nil, retErr
 		return nil, retErr
 	}
 	}
 
 
-	results := make([]SqlResult, len(tableRows))
+	err = tx.stream.SendMsg(&request.TransactionOperation{
-	for i, row := range tableRows {
+		Request: &request.TransactionOperation_ExecuteRawSqlJsonRequest{
-		results[i] = row
+			ExecuteRawSqlJsonRequest: string(requestJsonBytes),
-	}
-
-	return results, nil
-}
-
-func (tx *Transaction) ExecuteSql(name string, executeParams map[string]any) ([]SqlResult, error) {
-	var retErr error
-
-	defer func() {
-		if retErr != nil {
-			innerErr := tx.stream.CloseSend()
-			if innerErr != nil {
-				panic(innerErr)
-			}
-		}
-	}()
-
-	executeParamsJsonBytes, err := json.Marshal(executeParams)
-	if err != nil {
-		retErr = err
-		return nil, retErr
-	}
-
-	err = tx.stream.Send(&request.TransactionOperation{
-		Request: &request.TransactionOperation_ExecuteSqlRequest{
-			ExecuteSqlRequest: &request.ExecuteSqlRequest{
-				Name:          name,
-				ExecuteParams: string(executeParamsJsonBytes),
-			},
 		},
 		},
 	})
 	})
 	if err != nil {
 	if err != nil {

+ 0 - 223
sql/parse_result.go

@@ -1,223 +0,0 @@
-package sql
-
-import (
-	"errors"
-	"fmt"
-	"git.sxidc.com/go-tools/utils/encoding"
-	"git.sxidc.com/go-tools/utils/reflectutils"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"reflect"
-	"strings"
-	"time"
-)
-
-func ParseSqlResult[T any](input any) (T, error) {
-	var zero T
-
-	if input == nil {
-		return zero, nil
-	}
-
-	// 构造需要遍历的tableRows
-	tableRows, ok := input.([]sdk.SqlResult)
-	if !ok {
-		tableRow, ok := input.(sdk.SqlResult)
-		if !ok {
-			return zero, errors.New("输入数据应该为sdk.SqlResult或[]sdk.SqlResult")
-		}
-
-		tableRows = []sdk.SqlResult{tableRow}
-	}
-
-	// 构造outputValue
-	typeCheckErr := errors.New("可以接受的类型为struct, *struct, []struct, []*struct")
-	outputType := reflect.TypeOf(zero)
-
-	if outputType.Kind() != reflect.Struct && outputType.Kind() != reflect.Ptr && outputType.Kind() != reflect.Slice {
-		return zero, typeCheckErr
-	} else if outputType.Kind() == reflect.Ptr && outputType.Elem().Kind() != reflect.Struct {
-		return zero, typeCheckErr
-	} else if outputType.Kind() == reflect.Slice &&
-		(outputType.Elem().Kind() != reflect.Struct && outputType.Elem().Kind() != reflect.Ptr) {
-		return zero, typeCheckErr
-	} else if outputType.Kind() == reflect.Slice &&
-		outputType.Elem().Kind() == reflect.Ptr && outputType.Elem().Elem().Kind() != reflect.Struct {
-		return zero, typeCheckErr
-	}
-
-	var outputValue reflect.Value
-	if outputType.Kind() == reflect.Struct || outputType.Kind() == reflect.Ptr {
-		outputValue = reflect.New(outputType).Elem()
-	} else {
-		outputValue = reflect.MakeSlice(outputType, 0, 0)
-	}
-
-	for _, tableRow := range tableRows {
-		// 构造输出实体
-		var outputEntity any
-		if outputType.Kind() == reflect.Struct {
-			outputEntity = outputValue.Addr().Interface()
-		} else if outputType.Kind() == reflect.Ptr {
-			outputEntity = reflect.New(outputType.Elem()).Interface()
-		} else {
-			if outputType.Elem().Kind() == reflect.Struct {
-				outputEntity = reflect.New(outputType.Elem()).Interface()
-			} else {
-				outputValueElemPtr := reflect.New(outputType.Elem()).Elem()
-				outputValueElemPtr.Set(reflect.New(outputType.Elem().Elem()))
-				outputEntity = outputValueElemPtr.Interface()
-			}
-		}
-
-		sqlResult, err := ParseSqlResultTag(outputEntity)
-		if err != nil {
-			return zero, err
-		}
-
-		err = formOutputEntity(tableRow, sqlResult)
-		if err != nil {
-			return zero, err
-		}
-
-		if outputType.Kind() == reflect.Ptr {
-			outputValue = reflect.ValueOf(outputEntity)
-		} else if outputType.Kind() == reflect.Slice {
-			if outputType.Elem().Kind() == reflect.Struct {
-				outputValue = reflect.Append(outputValue, reflect.ValueOf(outputEntity).Elem())
-			} else {
-				outputValue = reflect.Append(outputValue, reflect.ValueOf(outputEntity))
-			}
-		}
-	}
-
-	output, ok := outputValue.Interface().(T)
-	if !ok {
-		return zero, errors.New("输出类型不匹配")
-	}
-
-	return output, nil
-}
-
-func formOutputEntity(tableRow sdk.SqlResult, sqlResult *Result) error {
-	for fieldName, resultElement := range sqlResult.ResultElement {
-		switch element := resultElement.(type) {
-		case *Result:
-			err := formOutputEntity(tableRow, element)
-			if err != nil {
-				return err
-			}
-		case *ResultColumn:
-			tableRowValue, ok := tableRow[element.Name]
-			if !ok {
-				continue
-			}
-
-			if tableRowValue == nil {
-				continue
-			}
-
-			// 构造结构字段,如果结构字段是指针且为nil,需要构造元素
-			fieldTypeElem := element.FieldTypeElem
-			fieldValueElem := element.FieldValueElem
-			outputKind := reflectutils.GroupValueKind(fieldValueElem)
-
-			if !fieldValueElem.CanSet() {
-				continue
-			}
-
-			switch outputKind {
-			case reflect.Bool:
-				err := reflectutils.AssignBoolValue(tableRowValue, fieldValueElem)
-				if err != nil {
-					return err
-				}
-			case reflect.String:
-				strValue := tableRowValue.(string)
-
-				if strutils.IsStringNotEmpty(element.ParseTime) {
-					parsedTime, err := sdk.ParseSqlResultTimeStr(strValue)
-					if err != nil {
-						return err
-					}
-
-					strValue = parsedTime.Format(element.ParseTime)
-				} else if strutils.IsStringNotEmpty(element.AESKey) {
-					if strutils.IsStringNotEmpty(strValue) {
-						decryptedValue, err := encoding.AESDecrypt(strValue, element.AESKey)
-						if err != nil {
-							return err
-						}
-
-						strValue = decryptedValue
-					}
-				}
-
-				err := reflectutils.AssignStringValue(strValue, fieldValueElem)
-				if err != nil {
-					return err
-				}
-			case reflect.Int64:
-				err := reflectutils.AssignInt64Value(tableRowValue, fieldValueElem)
-				if err != nil {
-					return err
-				}
-			case reflect.Uint64:
-				err := reflectutils.AssignUint64Value(tableRowValue, fieldValueElem)
-				if err != nil {
-					return err
-				}
-			case reflect.Float64:
-				err := reflectutils.AssignFloat64Value(tableRowValue, fieldValueElem)
-				if err != nil {
-					return err
-				}
-			case reflect.Struct:
-				if fieldValueElem.Type() == reflect.TypeOf(time.Time{}) {
-					parsedTime, err := sdk.ParseSqlResultTimeStr(tableRowValue.(string))
-					if err != nil {
-						return err
-					}
-
-					fieldValueElem.Set(reflect.ValueOf(parsedTime))
-					continue
-				}
-
-				return fmt.Errorf("字段: %s 列: %s 不支持的类型: %s",
-					fieldName, element.Name, fieldTypeElem.String())
-			case reflect.Slice:
-				if fieldTypeElem.Elem().Kind() != reflect.String {
-					return errors.New("slice仅支持[]string")
-				}
-
-				strValue, ok := tableRowValue.(string)
-				if !ok {
-					return errors.New("slice仅支持[]string")
-				}
-
-				strParts := strings.Split(strValue, element.SplitWith)
-				if strParts == nil || len(strParts) == 0 {
-					return nil
-				}
-
-				valSlice := fieldValueElem
-				if valSlice.IsNil() {
-					valSlice = reflect.MakeSlice(fieldTypeElem, 0, 0)
-				}
-
-				for _, strPart := range strParts {
-					valSlice = reflect.Append(valSlice, reflect.ValueOf(strPart))
-				}
-
-				fieldValueElem.Set(valSlice)
-			default:
-				return fmt.Errorf("字段: %s 列: %s 不支持的类型: %s",
-					fieldName, element.Name, fieldTypeElem.String())
-			}
-		default:
-			return errors.New("不支持的元素类型")
-		}
-	}
-
-	return nil
-}

+ 0 - 623
sql/sql.go

@@ -1,623 +0,0 @@
-package sql
-
-import (
-	"errors"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"git.sxidc.com/service-supports/ds-sdk/sql/sql_tpl"
-	"reflect"
-	"strings"
-	"time"
-)
-
-type Executor interface {
-	ExecuteRawSql(sql string, executeParams map[string]any) ([]sdk.SqlResult, error)
-	ExecuteSql(name string, executeParams map[string]any) ([]sdk.SqlResult, error)
-}
-
-const (
-	createdTimeFieldName     = "CreatedTime"
-	lastUpdatedTimeFieldName = "LastUpdatedTime"
-)
-
-func InsertEntity[T any](executor Executor, tableName string, e T) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if strutils.IsStringEmpty(tableName) {
-		return errors.New("没有传递表名")
-	}
-
-	entityType := reflect.TypeOf(e)
-
-	if entityType == nil {
-		return errors.New("没有传递实体")
-	}
-
-	typeCheckErr := errors.New("可以接受的类型为struct, *struct, []struct, []*struct")
-
-	if entityType.Kind() != reflect.Struct && entityType.Kind() != reflect.Ptr && entityType.Kind() != reflect.Slice {
-		return typeCheckErr
-	} else if entityType.Kind() == reflect.Ptr && entityType.Elem().Kind() != reflect.Struct {
-		return typeCheckErr
-	} else if entityType.Kind() == reflect.Slice &&
-		(entityType.Elem().Kind() != reflect.Struct && entityType.Elem().Kind() != reflect.Ptr) {
-		return typeCheckErr
-	} else if entityType.Kind() == reflect.Slice &&
-		entityType.Elem().Kind() == reflect.Ptr && entityType.Elem().Elem().Kind() != reflect.Struct {
-		return typeCheckErr
-	}
-
-	var executeParamsMap map[string]any
-
-	if entityType.Kind() == reflect.Struct || entityType.Kind() == reflect.Ptr {
-		sqlMapping, err := ParseSqlMappingTag(reflect.ValueOf(e).Interface())
-		if err != nil {
-			return err
-		}
-
-		tableRow := sql_tpl.NewTableRow()
-		err = formInsertTableRow(sqlMapping, tableRow)
-		if err != nil {
-			return err
-		}
-
-		innerExecuteParamsMap, err := sql_tpl.InsertExecuteParams{
-			TableName: tableName,
-			TableRow:  tableRow,
-		}.Map()
-		if err != nil {
-			return err
-		}
-
-		executeParamsMap = innerExecuteParamsMap
-	} else {
-		entitySliceValue := reflect.ValueOf(e)
-		if entitySliceValue.Len() == 0 {
-			return nil
-		}
-
-		tableRowBatch := make([]sql_tpl.TableRow, 0)
-
-		for i := 0; i < entitySliceValue.Len(); i++ {
-			sqlMapping, err := ParseSqlMappingTag(entitySliceValue.Index(i).Interface())
-			if err != nil {
-				return err
-			}
-
-			tableRow := sql_tpl.NewTableRow()
-			err = formInsertTableRow(sqlMapping, tableRow)
-			if err != nil {
-				return err
-			}
-
-			tableRowBatch = append(tableRowBatch, *tableRow)
-		}
-
-		innerExecuteParamsMap, err := sql_tpl.InsertBatchExecuteParams{
-			TableName:     tableName,
-			TableRowBatch: tableRowBatch,
-		}.Map()
-		if err != nil {
-			return err
-		}
-
-		executeParamsMap = innerExecuteParamsMap
-	}
-
-	_, err := executor.ExecuteRawSql(sql_tpl.InsertTpl, executeParamsMap)
-	if err != nil {
-		if strings.Contains(err.Error(), "SQLSTATE 23505") {
-			return sdk.ErrDBRecordHasExist
-		}
-
-		return err
-	}
-
-	return nil
-}
-
-func formInsertTableRow(sqlMapping *Mapping, tableRow *sql_tpl.TableRow) error {
-	now := time.Now()
-
-	for fieldName, mappingElement := range sqlMapping.MappingElement {
-		switch element := mappingElement.(type) {
-		case *Mapping:
-			err := formInsertTableRow(element, tableRow)
-			if err != nil {
-				return err
-			}
-		case *MappingColumn:
-			if element.IsKey && element.FieldValueElem.IsZero() {
-				return errors.New("键字段没有传值")
-			}
-
-			fieldType := element.FieldTypeElem
-
-			// 有值取值,没有值构造零值
-			value := reflect.Zero(fieldType).Interface()
-			if fieldType.Kind() != reflect.Slice {
-				if element.FieldValueElem.IsValid() && !element.FieldValueElem.IsZero() {
-					value = element.FieldValueElem.Interface()
-				}
-
-				// 自动添加创建时间和更新时间
-				if (fieldName == createdTimeFieldName || fieldName == lastUpdatedTimeFieldName) &&
-					fieldType.String() == "time.Time" && value.(time.Time).IsZero() {
-					value = now
-				}
-			} else {
-				sliceElementType := fieldType.Elem()
-				if sliceElementType.Kind() != reflect.String {
-					return errors.New("slice仅支持[]string")
-				}
-
-				if element.FieldValueElem.Len() == 0 {
-					value = ""
-				} else {
-					strValues := make([]string, 0, 0)
-					for i := 0; i < element.FieldValueElem.Len(); i++ {
-						strValues = append(strValues, element.FieldValueElem.Index(i).String())
-					}
-
-					value = strings.Join(strValues, element.JoinWith)
-				}
-			}
-
-			var opts []sql_tpl.AfterParsedStrValueOption
-			if strutils.IsStringNotEmpty(element.AESKey) {
-				opts = append(opts, sql_tpl.WithAESKey(element.AESKey))
-			}
-
-			tableRow.Add(element.Name, value, opts...)
-		default:
-			return errors.New("不支持的元素类型")
-		}
-	}
-
-	return nil
-}
-
-func DeleteEntity[T any](executor Executor, tableName string, e T) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if strutils.IsStringEmpty(tableName) {
-		return errors.New("没有传递表名")
-	}
-
-	if reflect.TypeOf(e) == nil {
-		return errors.New("没有传递实体")
-	}
-
-	sqlMapping, err := ParseSqlMappingTag(e)
-	if err != nil {
-		return err
-	}
-
-	conditions := sql_tpl.NewConditions()
-	err = formDeleteConditions(sqlMapping, conditions)
-	if err != nil {
-		return err
-	}
-
-	executeParamsMap, err := sql_tpl.DeleteExecuteParams{
-		TableName:  tableName,
-		Conditions: conditions,
-	}.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.DeleteTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func formDeleteConditions(sqlMapping *Mapping, conditions *sql_tpl.Conditions) error {
-	for _, mappingElement := range sqlMapping.MappingElement {
-		switch element := mappingElement.(type) {
-		case *Mapping:
-			err := formDeleteConditions(element, conditions)
-			if err != nil {
-				return err
-			}
-		case *MappingColumn:
-			// 不是键,字段跳过
-			if !element.IsKey {
-				continue
-			}
-
-			// 键字段没有赋值
-			if !element.FieldValueElem.IsValid() || element.FieldValueElem.IsZero() {
-				return errors.New("键字段没有传值")
-			}
-
-			var opts []sql_tpl.AfterParsedStrValueOption
-			if strutils.IsStringNotEmpty(element.AESKey) {
-				opts = append(opts, sql_tpl.WithAESKey(element.AESKey))
-			}
-
-			conditions.Equal(element.Name, element.FieldValueElem.Interface(), opts...)
-		default:
-			return errors.New("不支持的元素类型")
-		}
-	}
-
-	return nil
-}
-
-func UpdateEntity[T any](executor Executor, tableName string, e T) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if strutils.IsStringEmpty(tableName) {
-		return errors.New("没有传递表名")
-	}
-
-	if reflect.TypeOf(e) == nil {
-		return errors.New("没有传递实体")
-	}
-
-	sqlMapping, err := ParseSqlMappingTag(e)
-	if err != nil {
-		return err
-	}
-
-	tableRow := sql_tpl.NewTableRow()
-	conditions := sql_tpl.NewConditions()
-	err = formUpdateTableRowAndConditions(sqlMapping, tableRow, conditions)
-	if err != nil {
-		return err
-	}
-
-	executeParamsMap, err := sql_tpl.UpdateExecuteParams{
-		TableName:  tableName,
-		TableRow:   tableRow,
-		Conditions: conditions,
-	}.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.UpdateTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func formUpdateTableRowAndConditions(sqlMapping *Mapping, tableRow *sql_tpl.TableRow, conditions *sql_tpl.Conditions) error {
-	now := time.Now()
-
-	for fieldName, mappingElement := range sqlMapping.MappingElement {
-		switch element := mappingElement.(type) {
-		case *Mapping:
-			err := formUpdateTableRowAndConditions(element, tableRow, conditions)
-			if err != nil {
-				return err
-			}
-		case *MappingColumn:
-			if element.IsKey {
-				// 键字段但是没有赋值
-				if element.FieldValueElem.IsZero() {
-					return errors.New("键字段没有传值")
-				}
-			} else {
-				// 不是更新时间字段
-				// 不是键字段
-				// 不更新的字段或者字段为空且不能清空,跳过
-				if fieldName != lastUpdatedTimeFieldName &&
-					(!element.CanUpdate || (element.FieldValueElem.IsZero() && !element.CanUpdateClear)) {
-					continue
-				}
-			}
-
-			fieldType := element.FieldTypeElem
-
-			value := reflect.Zero(fieldType).Interface()
-			if fieldType.Kind() != reflect.Slice {
-				if element.FieldValueElem.IsValid() && !element.FieldValueElem.IsZero() {
-					value = element.FieldValueElem.Interface()
-				}
-			} else {
-				sliceElementType := fieldType.Elem()
-				if sliceElementType.Kind() != reflect.String {
-					return errors.New("slice仅支持[]string")
-				}
-
-				if element.FieldValueElem.Len() == 0 {
-					value = ""
-				} else {
-					strValues := make([]string, 0, 0)
-					for i := 0; i < element.FieldValueElem.Len(); i++ {
-						strValues = append(strValues, element.FieldValueElem.Index(i).String())
-					}
-
-					value = strings.Join(strValues, element.JoinWith)
-				}
-			}
-
-			if fieldName == lastUpdatedTimeFieldName &&
-				fieldType.String() == "time.Time" && value.(time.Time).IsZero() {
-				value = now
-			}
-
-			var opts []sql_tpl.AfterParsedStrValueOption
-			if strutils.IsStringNotEmpty(element.AESKey) {
-				opts = append(opts, sql_tpl.WithAESKey(element.AESKey))
-			}
-
-			if element.IsKey {
-				conditions.Equal(element.Name, value, opts...)
-			} else {
-				tableRow.Add(element.Name, value, opts...)
-			}
-		default:
-			return errors.New("不支持的元素类型")
-		}
-	}
-
-	return nil
-}
-
-func Insert(executor Executor, executeParams *sql_tpl.InsertExecuteParams) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.InsertTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func InsertBatch(executor Executor, executeParams *sql_tpl.InsertBatchExecuteParams) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.InsertTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func Delete(executor Executor, executeParams *sql_tpl.DeleteExecuteParams) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.DeleteTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func Update(executor Executor, executeParams *sql_tpl.UpdateExecuteParams) error {
-	if executor == nil {
-		return errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return err
-	}
-
-	_, err = executor.ExecuteRawSql(sql_tpl.UpdateTpl, executeParamsMap)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func Query(executor Executor, executeParams *sql_tpl.QueryExecuteParams) ([]sdk.SqlResult, int64, error) {
-	if executor == nil {
-		return nil, 0, errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return nil, 0, errors.New("没有传递执行参数")
-	}
-
-	queryExecuteParamsMap, err := executeParams.Map()
-	if err != nil {
-		return nil, 0, err
-	}
-
-	countExecuteParamsMap, err := sql_tpl.CountExecuteParams{
-		TableName:  executeParams.TableName,
-		Conditions: executeParams.Conditions,
-	}.Map()
-	if err != nil {
-		return nil, 0, err
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql_tpl.QueryTpl, queryExecuteParamsMap)
-	if err != nil {
-		return nil, 0, err
-	}
-
-	countTableRow, err := executor.ExecuteRawSql(sql_tpl.CountTpl, countExecuteParamsMap)
-	if err != nil {
-		return nil, 0, err
-	}
-
-	results := make([]sdk.SqlResult, len(tableRows))
-	for i, row := range tableRows {
-		results[i] = row
-	}
-
-	return results, int64(countTableRow[0]["count"].(float64)), nil
-}
-
-func QueryOne(executor Executor, executeParams *sql_tpl.QueryOneExecuteParams) (sdk.SqlResult, error) {
-	if executor == nil {
-		return nil, errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return nil, errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return nil, err
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql_tpl.QueryTpl, executeParamsMap)
-	if err != nil {
-		return nil, err
-	}
-
-	if tableRows == nil || len(tableRows) == 0 {
-		return nil, sdk.ErrDBRecordNotExist
-	}
-
-	return tableRows[0], nil
-}
-
-func Count(executor Executor, executeParams *sql_tpl.CountExecuteParams) (int64, error) {
-	if executor == nil {
-		return 0, errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return 0, errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return 0, err
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql_tpl.CountTpl, executeParamsMap)
-	if err != nil {
-		return 0, err
-	}
-
-	return int64(tableRows[0]["count"].(float64)), nil
-}
-
-func CheckExist(executor Executor, executeParams *sql_tpl.CheckExistExecuteParams) (bool, error) {
-	if executor == nil {
-		return false, errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return false, errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return false, err
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql_tpl.CountTpl, executeParamsMap)
-	if err != nil {
-		return false, err
-	}
-
-	return int64(tableRows[0]["count"].(float64)) > 0, nil
-}
-
-func CheckHasOnlyOne(executor Executor, executeParams *sql_tpl.CheckHasOnlyOneExecuteParams) (bool, error) {
-	if executor == nil {
-		return false, errors.New("没有传递执行器")
-	}
-
-	if executeParams == nil {
-		return false, errors.New("没有传递执行参数")
-	}
-
-	executeParamsMap, err := executeParams.Map()
-	if err != nil {
-		return false, err
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql_tpl.CountTpl, executeParamsMap)
-	if err != nil {
-		return false, err
-	}
-
-	return int64(tableRows[0]["count"].(float64)) == 1, nil
-}
-
-func ExecuteRawSql(executor Executor, sql string, executeParams map[string]any) ([]sdk.SqlResult, error) {
-	if executor == nil {
-		return nil, errors.New("没有传递执行器")
-	}
-
-	if strutils.IsStringEmpty(sql) {
-		return nil, errors.New("没有sql")
-	}
-
-	tableRows, err := executor.ExecuteRawSql(sql, executeParams)
-	if err != nil {
-		return nil, err
-	}
-
-	return tableRows, nil
-}
-
-func ExecuteSql(executor Executor, name string, executeParams map[string]any) ([]sdk.SqlResult, error) {
-	if executor == nil {
-		return nil, errors.New("没有传递执行器")
-	}
-
-	if strutils.IsStringEmpty(name) {
-		return nil, errors.New("没有sql资源名称")
-	}
-
-	tableRows, err := executor.ExecuteSql(name, executeParams)
-	if err != nil {
-		return nil, err
-	}
-
-	return tableRows, nil
-}

+ 0 - 190
sql/sql_mapping.go

@@ -1,190 +0,0 @@
-package sql
-
-import (
-	"errors"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/iancoleman/strcase"
-	"reflect"
-	"strings"
-	"time"
-)
-
-const (
-	sqlMappingDefaultKeyColumnName     = "id"
-	sqlMappingDefaultJoinWith          = "::"
-	sqlMappingTagPartSeparator         = ";"
-	sqlMappingTagPartKeyValueSeparator = ":"
-)
-
-const (
-	sqlMappingTagKey      = "sqlmapping"
-	sqlMappingIgnore      = "-"
-	sqlMappingColumn      = "column"
-	sqlMappingKey         = "key"
-	sqlMappingNotUpdate   = "notUpdate"
-	sqlMappingUpdateClear = "updateClear"
-	sqlMappingAes         = "aes"
-	sqlMappingJoinWith    = "joinWith"
-)
-
-type Mapping struct {
-	MappingElement map[string]any
-}
-
-type MappingColumn struct {
-	Name           string
-	IsKey          bool
-	CanUpdate      bool
-	CanUpdateClear bool
-	AESKey         string
-	JoinWith       string
-
-	// 原字段的反射结构
-	OriginFieldType  reflect.Type
-	OriginFieldValue reflect.Value
-
-	// 值类型的反射结构
-	FieldTypeElem  reflect.Type
-	FieldValueElem reflect.Value
-}
-
-func ParseSqlMappingTag(e any) (*Mapping, error) {
-	if e == nil {
-		return nil, errors.New("没有传递实体")
-	}
-
-	entityType := reflect.TypeOf(e)
-	if entityType.Kind() == reflect.Ptr {
-		entityType = entityType.Elem()
-	}
-
-	if entityType.Kind() != reflect.Struct {
-		return nil, errors.New("传递的实体不是结构类型")
-	}
-
-	entityValue := reflect.ValueOf(e)
-	if entityValue.Kind() == reflect.Ptr {
-		entityValue = entityValue.Elem()
-	}
-
-	sqlMapping := new(Mapping)
-	sqlMapping.MappingElement = make(map[string]any)
-
-	fieldNum := entityType.NumField()
-	for i := 0; i < fieldNum; i++ {
-		field := entityType.Field(i)
-		fieldValue := entityValue.Field(i)
-
-		element, err := parseSqlMappingElement(field, fieldValue)
-		if err != nil {
-			return nil, err
-		}
-
-		if element == nil {
-			continue
-		}
-
-		sqlMapping.MappingElement[field.Name] = element
-	}
-
-	return sqlMapping, nil
-}
-
-func parseSqlMappingElement(field reflect.StructField, fieldValue reflect.Value) (any, error) {
-	sqlMappingTag := field.Tag.Get(sqlMappingTagKey)
-	if sqlMappingTag == sqlMappingIgnore {
-		return nil, nil
-	}
-
-	fieldValueTypeElem := field.Type
-	if field.Type.Kind() == reflect.Ptr {
-		fieldValueTypeElem = field.Type.Elem()
-	}
-
-	fieldValueElem := fieldValue
-	if fieldValue.Kind() == reflect.Ptr {
-		if !fieldValue.IsValid() || fieldValue.IsNil() {
-			fieldValueElem = reflect.New(fieldValueTypeElem).Elem()
-		} else {
-			fieldValueElem = fieldValue.Elem()
-		}
-	}
-
-	if fieldValueTypeElem.Kind() == reflect.Struct && fieldValueTypeElem != reflect.TypeOf(time.Time{}) {
-		return ParseSqlMappingTag(fieldValueElem.Interface())
-	}
-
-	sqlColumn := &MappingColumn{
-		Name:           strcase.ToSnake(field.Name),
-		IsKey:          false,
-		CanUpdate:      true,
-		CanUpdateClear: false,
-		AESKey:         "",
-		JoinWith:       sqlMappingDefaultJoinWith,
-
-		OriginFieldType:  field.Type,
-		OriginFieldValue: fieldValue,
-		FieldTypeElem:    fieldValueTypeElem,
-		FieldValueElem:   fieldValueElem,
-	}
-
-	if sqlColumn.Name == sqlMappingDefaultKeyColumnName {
-		sqlColumn.IsKey = true
-		sqlColumn.CanUpdate = false
-	}
-
-	if strutils.IsStringEmpty(sqlMappingTag) {
-		return sqlColumn, nil
-	}
-
-	sqlMappingParts := strings.Split(sqlMappingTag, sqlMappingTagPartSeparator)
-	if sqlMappingParts != nil || len(sqlMappingParts) != 0 {
-		for _, sqlMappingPart := range sqlMappingParts {
-			sqlPartKeyValue := strings.SplitN(strings.TrimSpace(sqlMappingPart), sqlMappingTagPartKeyValueSeparator, 2)
-			if sqlPartKeyValue != nil && len(sqlPartKeyValue) == 2 && strutils.IsStringNotEmpty(sqlPartKeyValue[1]) {
-				sqlPartKeyValue[1] = strings.Trim(sqlPartKeyValue[1], "'")
-			}
-
-			switch sqlPartKeyValue[0] {
-			case sqlMappingColumn:
-				if strutils.IsStringEmpty(sqlPartKeyValue[1]) {
-					return nil, errors.New("column没有赋值列名")
-				}
-
-				sqlColumn.Name = sqlPartKeyValue[1]
-			case sqlMappingKey:
-				sqlColumn.IsKey = true
-				sqlColumn.CanUpdate = false
-			case sqlMappingNotUpdate:
-				sqlColumn.CanUpdate = false
-				sqlColumn.CanUpdateClear = false
-			case sqlMappingUpdateClear:
-				if !sqlColumn.CanUpdate {
-					sqlColumn.CanUpdateClear = false
-				} else {
-					sqlColumn.CanUpdateClear = true
-				}
-			case sqlMappingAes:
-				if len(sqlPartKeyValue[1]) != 32 {
-					return nil, errors.New("AES密钥长度应该为32个字节")
-				}
-
-				sqlColumn.AESKey = sqlPartKeyValue[1]
-			case sqlMappingJoinWith:
-				if strutils.IsStringEmpty(sqlPartKeyValue[1]) {
-					return nil, errors.New(sqlMappingJoinWith + "没有赋值分隔符")
-				}
-
-				if fieldValueTypeElem.Kind() != reflect.Slice || fieldValueTypeElem.Elem().Kind() != reflect.String {
-					return nil, errors.New(sqlMappingJoinWith + "应该添加在[]string字段上")
-				}
-
-				sqlColumn.JoinWith = sqlPartKeyValue[1]
-			default:
-				continue
-			}
-		}
-	}
-
-	return sqlColumn, nil
-}

+ 0 - 172
sql/sql_result.go

@@ -1,172 +0,0 @@
-package sql
-
-import (
-	"errors"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/iancoleman/strcase"
-	"reflect"
-	"strings"
-	"time"
-)
-
-const (
-	sqlResultDefaultSplitWith         = "::"
-	sqlResultTagPartSeparator         = ";"
-	sqlResultTagPartKeyValueSeparator = ":"
-)
-
-const (
-	sqlResultTagKey    = "sqlresult"
-	sqlResultIgnore    = "-"
-	sqlResultColumn    = "column"
-	sqlResultParseTime = "parseTime"
-	sqlResultAes       = "aes"
-	sqlResultSplitWith = "splitWith"
-)
-
-type Result struct {
-	ResultElement map[string]any
-}
-
-type ResultColumn struct {
-	Name      string
-	ParseTime string
-	AESKey    string
-	SplitWith string
-
-	// 原字段的反射结构
-	OriginFieldType  reflect.Type
-	OriginFieldValue reflect.Value
-
-	// 值类型的反射结构
-	FieldTypeElem  reflect.Type
-	FieldValueElem reflect.Value
-}
-
-func ParseSqlResultTag(e any) (*Result, error) {
-	if e == nil {
-		return nil, errors.New("没有传递实体")
-	}
-
-	entityType := reflect.TypeOf(e)
-	if entityType.Kind() == reflect.Ptr {
-		entityType = entityType.Elem()
-	}
-
-	if entityType.Kind() != reflect.Struct {
-		return nil, errors.New("传递的实体不是结构类型")
-	}
-
-	entityValue := reflect.ValueOf(e)
-	if entityValue.Kind() == reflect.Ptr {
-		entityValue = entityValue.Elem()
-	}
-
-	sqlResult := new(Result)
-	sqlResult.ResultElement = make(map[string]any)
-
-	fieldNum := entityType.NumField()
-	for i := 0; i < fieldNum; i++ {
-		field := entityType.Field(i)
-		fieldValue := entityValue.Field(i)
-
-		element, err := parseSqlResultElement(field, fieldValue)
-		if err != nil {
-			return nil, err
-		}
-
-		if element == nil {
-			continue
-		}
-
-		sqlResult.ResultElement[field.Name] = element
-	}
-
-	return sqlResult, nil
-}
-
-func parseSqlResultElement(field reflect.StructField, fieldValue reflect.Value) (any, error) {
-	sqlResultTag := field.Tag.Get(sqlResultTagKey)
-	if sqlResultTag == sqlResultIgnore {
-		return nil, nil
-	}
-
-	fieldValueTypeElem := field.Type
-	if field.Type.Kind() == reflect.Ptr {
-		fieldValueTypeElem = field.Type.Elem()
-	}
-
-	fieldValueElem := fieldValue
-	if fieldValue.Kind() == reflect.Ptr {
-		if !fieldValue.IsValid() || fieldValue.IsNil() {
-			if !fieldValue.CanSet() {
-				return nil, nil
-			}
-
-			fieldValue.Set(reflect.New(fieldValueTypeElem).Elem().Addr())
-		}
-
-		fieldValueElem = fieldValue.Elem()
-	}
-
-	if fieldValueTypeElem.Kind() == reflect.Struct && fieldValueTypeElem != reflect.TypeOf(time.Time{}) {
-		if !fieldValueElem.CanAddr() {
-			return nil, errors.New("请使用指针作为变量")
-		}
-
-		return ParseSqlResultTag(fieldValueElem.Addr().Interface())
-	}
-
-	sqlColumn := &ResultColumn{
-		Name:      strcase.ToSnake(field.Name),
-		ParseTime: "",
-		AESKey:    "",
-		SplitWith: sqlResultDefaultSplitWith,
-
-		OriginFieldType:  field.Type,
-		OriginFieldValue: fieldValue,
-		FieldTypeElem:    fieldValueTypeElem,
-		FieldValueElem:   fieldValueElem,
-	}
-
-	if strutils.IsStringEmpty(sqlResultTag) {
-		return sqlColumn, nil
-	}
-
-	sqlResultParts := strings.Split(sqlResultTag, sqlResultTagPartSeparator)
-	if sqlResultParts != nil || len(sqlResultParts) != 0 {
-		for _, sqlResultPart := range sqlResultParts {
-			sqlPartKeyValue := strings.SplitN(strings.TrimSpace(sqlResultPart), sqlResultTagPartKeyValueSeparator, 2)
-			if sqlPartKeyValue != nil && len(sqlPartKeyValue) == 2 && strutils.IsStringNotEmpty(sqlPartKeyValue[1]) {
-				sqlPartKeyValue[1] = strings.Trim(sqlPartKeyValue[1], "'")
-			}
-
-			switch sqlPartKeyValue[0] {
-			case sqlResultColumn:
-				sqlColumn.Name = sqlPartKeyValue[1]
-			case sqlResultParseTime:
-				sqlColumn.ParseTime = sqlPartKeyValue[1]
-			case sqlResultAes:
-				if len(sqlPartKeyValue[1]) != 32 {
-					return nil, errors.New("AES密钥长度应该为32个字节")
-				}
-
-				sqlColumn.AESKey = sqlPartKeyValue[1]
-			case sqlResultSplitWith:
-				if strutils.IsStringEmpty(sqlPartKeyValue[1]) {
-					return nil, errors.New(sqlResultDefaultSplitWith + "没有赋值分隔符")
-				}
-
-				if fieldValueTypeElem.Kind() != reflect.Slice || fieldValueTypeElem.Elem().Kind() != reflect.String {
-					return nil, errors.New(sqlResultDefaultSplitWith + "应该添加在[]string字段上")
-				}
-
-				sqlColumn.SplitWith = sqlPartKeyValue[1]
-			default:
-				continue
-			}
-		}
-	}
-
-	return sqlColumn, nil
-}

+ 0 - 161
sql/sql_tpl/condition.go

@@ -1,161 +0,0 @@
-package sql_tpl
-
-type Conditions struct {
-	Conditions []string
-	err        error
-}
-
-func NewConditions() *Conditions {
-	return &Conditions{
-		Conditions: make([]string, 0),
-	}
-}
-
-func (conditions *Conditions) AddCondition(condition string) *Conditions {
-	conditions.Conditions = append(conditions.Conditions, condition)
-	return conditions
-}
-
-func (conditions *Conditions) Equal(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" = "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) Like(columnName string, value string, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" LIKE "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) In(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseSliceValues(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" IN "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) NotIn(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseSliceValues(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" NOT IN "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) Not(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" != "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) LessThan(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" < "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) LessThanAndEqual(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" <= "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) GreaterThan(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" > "+parsedValue)
-
-	return conditions
-}
-
-func (conditions *Conditions) GreaterThanAndEqual(columnName string, value any, opts ...AfterParsedStrValueOption) *Conditions {
-	if conditions.err != nil {
-		return conditions
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		conditions.err = err
-		return conditions
-	}
-
-	conditions.Conditions = append(conditions.Conditions, columnName+" >= "+parsedValue)
-
-	return conditions
-}

+ 0 - 304
sql/sql_tpl/sql_tpl.go

@@ -1,304 +0,0 @@
-package sql_tpl
-
-import "errors"
-
-const InsertTpl = `
-INSERT INTO
-    {{ .table_name }} ({{ .columns | join "," }})
-VALUES
-{{- $valuesClauses := list }}
-{{- range .values_list }}
-{{- $valuesClause := printf "(%s)" ( . | join "," ) }}
-{{- $valuesClauses = append $valuesClauses $valuesClause }}
-{{- end }}
-    {{ $valuesClauses | join "," }}
-`
-
-type InsertExecuteParams struct {
-	TableName string
-	*TableRow
-}
-
-func (params InsertExecuteParams) Map() (map[string]any, error) {
-	if params.TableRow == nil {
-		return nil, nil
-	}
-
-	if params.TableRow.err != nil {
-		return nil, params.TableRow.err
-	}
-
-	columns := make([]string, 0)
-	values := make([]any, 0)
-
-	for _, cv := range params.TableRow.columnValues {
-		columns = append(columns, cv.column)
-		values = append(values, cv.value)
-	}
-
-	return map[string]any{
-		"table_name":  params.TableName,
-		"columns":     columns,
-		"values_list": []any{values},
-	}, nil
-}
-
-type InsertBatchExecuteParams struct {
-	TableName     string
-	TableRowBatch []TableRow
-}
-
-func (params InsertBatchExecuteParams) Map() (map[string]any, error) {
-	if params.TableRowBatch == nil || len(params.TableRowBatch) == 0 {
-		return nil, nil
-	}
-
-	columns := make([]string, 0)
-	for _, cv := range params.TableRowBatch[0].columnValues {
-		columns = append(columns, cv.column)
-	}
-
-	valuesList := make([]any, 0)
-
-	for _, tableRow := range params.TableRowBatch {
-		if tableRow.err != nil {
-			return nil, tableRow.err
-		}
-
-		if len(columns) != len(tableRow.columnValues) {
-			return nil, errors.New("列数不匹配,保证每个TableRow的Add数量一致")
-		}
-
-		columnAndValueMap := make(map[string]any, 0)
-
-		for _, cv := range tableRow.columnValues {
-			columnAndValueMap[cv.column] = cv.value
-		}
-
-		values := make([]any, len(columnAndValueMap))
-		for _, column := range columns {
-			values = append(values, columnAndValueMap[column])
-		}
-
-		valuesList = append(valuesList, values)
-	}
-
-	return map[string]any{
-		"table_name":  params.TableName,
-		"columns":     columns,
-		"values_list": valuesList,
-	}, nil
-}
-
-const DeleteTpl = `
-DELETE FROM
-    {{ .table_name }}
-WHERE
-    {{ range .conditions }} {{ . }} AND {{ end }} 1 = 1
-`
-
-type DeleteExecuteParams struct {
-	TableName string
-	*Conditions
-}
-
-func (params DeleteExecuteParams) Map() (map[string]any, error) {
-	if params.Conditions == nil {
-		return nil, errors.New("没有传递删除条件")
-	}
-
-	if params.Conditions.err != nil {
-		return nil, params.Conditions.err
-	}
-
-	return map[string]any{
-		"table_name": params.TableName,
-		"conditions": params.Conditions.Conditions,
-	}, nil
-}
-
-const UpdateTpl = `
-UPDATE
-    {{ .table_name }}
-SET
-    {{ .set_list | join "," }}
-WHERE
-    {{ range .conditions }} {{ . }} AND {{ end }} 1 = 1
-`
-
-type UpdateExecuteParams struct {
-	TableName string
-	*TableRow
-	*Conditions
-}
-
-func (params UpdateExecuteParams) Map() (map[string]any, error) {
-	if params.TableRow == nil {
-		return nil, nil
-	}
-
-	if params.TableRow.err != nil {
-		return nil, params.TableRow.err
-	}
-
-	setList := make([]string, 0)
-	for _, cv := range params.TableRow.columnValues {
-		setList = append(setList, cv.column+" = "+cv.value)
-	}
-
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name": params.TableName,
-		"set_list":   setList,
-		"conditions": conditions,
-	}, nil
-}
-
-const QueryTpl = `
-SELECT
-    {{ if .select_columns }}{{ .select_columns | join "," }}{{ else }}*{{ end }} 
-FROM
-    {{ .table_name }}
-WHERE
-    {{ range .conditions }} {{ . }} AND {{ end }} 1 = 1 
-{{ if .limit }}LIMIT {{ .limit }}{{ end }}
-{{ if .offset }}OFFSET {{ .offset }}{{ end }}
-`
-
-type QueryExecuteParams struct {
-	TableName     string
-	SelectColumns []string
-	*Conditions
-	PageNo   int
-	PageSize int
-}
-
-func (params QueryExecuteParams) Map() (map[string]any, error) {
-	var limit int
-	var offset int
-
-	if params.PageNo != 0 && params.PageSize != 0 {
-		limit = params.PageSize
-		offset = (params.PageNo - 1) * params.PageSize
-	}
-
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name":     params.TableName,
-		"select_columns": params.SelectColumns,
-		"conditions":     conditions,
-		"limit":          limit,
-		"offset":         offset,
-	}, nil
-}
-
-type QueryOneExecuteParams struct {
-	TableName     string
-	SelectColumns []string
-	*Conditions
-}
-
-func (params QueryOneExecuteParams) Map() (map[string]any, error) {
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name":     params.TableName,
-		"select_columns": params.SelectColumns,
-		"conditions":     conditions,
-	}, nil
-}
-
-const CountTpl = `
-SELECT
-    COUNT(*)
-FROM
-    {{ .table_name }}
-WHERE
-    {{ range .conditions }} {{ . }} AND {{ end }} 1 = 1
-`
-
-type CountExecuteParams struct {
-	TableName string
-	*Conditions
-}
-
-func (params CountExecuteParams) Map() (map[string]any, error) {
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name": params.TableName,
-		"conditions": conditions,
-	}, nil
-}
-
-type CheckExistExecuteParams struct {
-	TableName string
-	*Conditions
-}
-
-func (params CheckExistExecuteParams) Map() (map[string]any, error) {
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name": params.TableName,
-		"conditions": conditions,
-	}, nil
-}
-
-type CheckHasOnlyOneExecuteParams struct {
-	TableName string
-	*Conditions
-}
-
-func (params CheckHasOnlyOneExecuteParams) Map() (map[string]any, error) {
-	conditions := make([]string, 0)
-	if params.Conditions != nil {
-		if params.Conditions.err != nil {
-			return nil, params.Conditions.err
-		}
-
-		conditions = params.Conditions.Conditions
-	}
-
-	return map[string]any{
-		"table_name": params.TableName,
-		"conditions": conditions,
-	}, nil
-}

+ 0 - 36
sql/sql_tpl/table_row.go

@@ -1,36 +0,0 @@
-package sql_tpl
-
-type TableRow struct {
-	columnValues []columnValue
-	err          error
-}
-
-type columnValue struct {
-	column string
-	value  string
-}
-
-func NewTableRow() *TableRow {
-	return &TableRow{
-		columnValues: make([]columnValue, 0),
-	}
-}
-
-func (tableRow *TableRow) Add(column string, value any, opts ...AfterParsedStrValueOption) *TableRow {
-	if tableRow.err != nil {
-		return tableRow
-	}
-
-	parsedValue, err := parseValue(value, opts...)
-	if err != nil {
-		tableRow.err = err
-		return tableRow
-	}
-
-	tableRow.columnValues = append(tableRow.columnValues, columnValue{
-		column: column,
-		value:  parsedValue,
-	})
-
-	return tableRow
-}

+ 0 - 190
sql/sql_tpl/value.go

@@ -1,190 +0,0 @@
-package sql_tpl
-
-import (
-	"errors"
-	"git.sxidc.com/go-tools/utils/encoding"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"reflect"
-	"strconv"
-	"strings"
-	"time"
-)
-
-const (
-	timeWriteFormat = time.DateTime + ".000000 +08:00"
-)
-
-type AfterParsedStrValueOption func(strValue string) (string, error)
-
-func WithAESKey(aesKey string) AfterParsedStrValueOption {
-	return func(strValue string) (string, error) {
-		if strutils.IsStringEmpty(strValue) {
-			return "''", nil
-		}
-
-		encrypted, err := encoding.AESEncrypt(strValue, aesKey)
-		if err != nil {
-			return "", err
-		}
-
-		return "'" + encrypted + "'", nil
-	}
-}
-
-func parseValue(value any, opts ...AfterParsedStrValueOption) (string, error) {
-	valueValue := reflect.ValueOf(value)
-
-	if !valueValue.IsValid() {
-		return "", errors.New("无效值")
-	}
-
-	if valueValue.Kind() == reflect.Ptr && valueValue.IsNil() {
-		return "", errors.New("空值")
-	}
-
-	if valueValue.Kind() == reflect.Ptr {
-		valueValue = valueValue.Elem()
-	}
-
-	var parsedValue string
-
-	switch v := valueValue.Interface().(type) {
-	case string:
-		parsedValue = v
-
-		if opts == nil || len(opts) == 0 {
-			return "'" + parsedValue + "'", nil
-		}
-	case bool:
-		parsedValue = strconv.FormatBool(v)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case time.Time:
-		parsedValue = v.Format(timeWriteFormat)
-
-		if opts == nil || len(opts) == 0 {
-			return "'" + parsedValue + "'", nil
-		}
-	case int:
-		parsedValue = strconv.Itoa(v)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case int8:
-		parsedValue = strconv.FormatInt(int64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case int16:
-		parsedValue = strconv.FormatInt(int64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case int32:
-		parsedValue = strconv.FormatInt(int64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case int64:
-		parsedValue = strconv.FormatInt(v, 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case uint:
-		parsedValue = strconv.FormatUint(uint64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case uint8:
-		parsedValue = strconv.FormatUint(uint64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case uint16:
-		parsedValue = strconv.FormatUint(uint64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case uint32:
-		parsedValue = strconv.FormatUint(uint64(v), 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	case uint64:
-		parsedValue = strconv.FormatUint(v, 10)
-
-		if opts == nil || len(opts) == 0 {
-			return parsedValue, nil
-		}
-	default:
-		return "", errors.New("不支持的类型")
-	}
-
-	for _, opt := range opts {
-		innerParsedValue, err := opt(parsedValue)
-		if err != nil {
-			return "", err
-		}
-
-		parsedValue = innerParsedValue
-	}
-
-	return parsedValue, nil
-}
-
-func parseSliceValues(values any, opts ...AfterParsedStrValueOption) (string, error) {
-	sliceValue := reflect.ValueOf(values)
-
-	if !sliceValue.IsValid() {
-		return "", errors.New("无效值")
-	}
-
-	if sliceValue.Kind() == reflect.Ptr && sliceValue.IsNil() {
-		return "()", nil
-	}
-
-	if sliceValue.Kind() == reflect.Ptr {
-		sliceValue = sliceValue.Elem()
-	}
-
-	if sliceValue.Kind() != reflect.Slice {
-		return "", errors.New("传递的不是slice")
-	}
-
-	parsedValues := make([]string, 0)
-	for i := 0; i < sliceValue.Len(); i++ {
-		value := sliceValue.Index(i).Interface()
-		parsedValue, err := parseValue(value)
-		if err != nil {
-			return "", err
-		}
-
-		for _, opt := range opts {
-			innerParsedValue, err := opt(parsedValue)
-			if err != nil {
-				return "", err
-			}
-
-			parsedValue = innerParsedValue
-		}
-
-		parsedValues = append(parsedValues, parsedValue)
-	}
-
-	if len(parsedValues) == 0 {
-		return "()", nil
-	}
-
-	return "(" + strings.Join(parsedValues, ",") + ")", nil
-}

+ 0 - 58
test/resources.yaml

@@ -1,58 +0,0 @@
-kind: Namespace
-spec:
-  name: ns-sdk-demo
-
----
-
-kind: DataSource
-spec:
-  type: database
-  namespace: ns-sdk-demo
-  name: ds-sdk-demo
-  spec:
-    type: postgres
-    user_name: test
-    password: "123456"
-    address: "10.0.0.84"
-    port: "30432"
-    database: test
-    max_connections: 40
-    max_idle_connections: 10
-
----
-
-kind: DataContainer
-spec:
-  namespace: ns-sdk-demo
-  data_source: ds-sdk-demo
-  name: dc-sdk-demo
-  spec:
-    table_name: test.classes
-    columns:
-      - name: id
-        type: varchar(32)
-        comment: id
-        primary_key: true
-      - name: name
-        type: varchar(128)
-        comment: 班名
-        not_null: true
-      - name: student_num
-        type: integer
-        comment: 学生数量
-        default: 60
-      - name: student_ids
-        type: text
-        comment: 学生ID
-        not_null: true
-      - name: graduated_time
-        type: "timestamp with time zone"
-        comment: 毕业时间
-      - name: created_time
-        type: "timestamp with time zone"
-        comment: 创建时间
-        not_null: true
-      - name: last_updated_time
-        type: "timestamp with time zone"
-        comment: 最近更新时间
-        not_null: true

+ 0 - 957
test/sdk_test.go

@@ -1,957 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"git.sxidc.com/service-supports/ds-sdk/sql"
-	"git.sxidc.com/service-supports/ds-sdk/sql/sql_tpl"
-	"github.com/iancoleman/strcase"
-	"math/rand"
-	"strings"
-	"sync"
-	"testing"
-	"time"
-)
-
-type IDField struct {
-	ID string
-}
-
-type TimeFields struct {
-	CreatedTime     *time.Time
-	LastUpdatedTime time.Time
-}
-
-type GraduatedTimeTestStruct struct {
-	Field *string `sqlmapping:"-" sqlresult:"column:graduated_time;parseTime:2006-01-02 15:04:05"`
-}
-
-type Class struct {
-	IDField
-	Name          string `sqlmapping:"updateClear;aes:@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L;" sqlresult:"aes:@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L;"`
-	StudentNum    int    `sqlmapping:"column:student_num;notUpdate;" sqlresult:"column:student_num_alias"`
-	GraduatedTime *time.Time
-	StudentIDs    []string `sqlmapping:"column:student_ids;joinWith:'\n'" sqlresult:"column:student_ids;splitWith:'\n'"`
-	TimeFields
-	Ignored string `sqlmapping:"-" sqlresult:"-"`
-	*GraduatedTimeTestStruct
-}
-
-const (
-	token          = "IpTTwAQweh/BP51fz5CzWKQFaXHvZe6ewvk6yOcAOkU="
-	address        = "localhost"
-	httpPort       = "10000"
-	grpcPort       = "10001"
-	namespace      = "ns-sdk-demo"
-	dataSource     = "ds-sdk-demo"
-	deleteSql      = "delete-sdk-demo"
-	goRoutineCount = 100
-	tableName      = "test.classes"
-)
-
-var (
-	sqlSpec = sdk.SqlSpec{
-		Clauses: "- DELETE FROM {{ .table_name }} WHERE id = '{{ .id }}'",
-	}
-)
-
-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 chooseTimeLayout(timeStr string) string {
-	if strings.HasSuffix(timeStr, ".000000+08:00") {
-		return sqlResultTimeMicroFormat
-	} else if strings.HasSuffix(timeStr, ".000+08:00") {
-		return sqlResultTimeMilliFormat
-	} else {
-		return sqlResultTimeSecFormat
-	}
-}
-
-func TestBasic(t *testing.T) {
-	classID := strutils.SimpleUUID()
-	className := strutils.SimpleUUID()
-	studentNum := rand.Int31n(100)
-	studentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID()}
-	now := time.Now()
-
-	insertExecuteParams, err := sql_tpl.InsertExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().Add("id", classID).
-			Add("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_num", studentNum).
-			Add("student_ids", strings.Join(studentIDs, "\n")).
-			Add("graduated_time", now).
-			Add("created_time", now).
-			Add("last_updated_time", now),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	deleteExecuteParams := map[string]any{
-		"table_name": tableName,
-		"id":         classID,
-	}
-
-	err = sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	err = sdk.GetInstance().CreateSQL(deleteSql, sqlSpec.ToMap())
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err = sdk.GetInstance().DeleteSQL(deleteSql)
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	_, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.InsertTpl, insertExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	_, err = sdk.GetInstance().ExecuteSql(deleteSql, deleteExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	wg := sync.WaitGroup{}
-	wg.Add(goRoutineCount)
-
-	start := time.Now()
-
-	for i := 0; i < goRoutineCount; i++ {
-		go func() {
-			defer wg.Done()
-
-			err = sdk.GetInstance().Transaction(func(tx *sdk.Transaction) error {
-				_, err := tx.ExecuteRawSql(sql_tpl.InsertTpl, insertExecuteParams)
-				if err != nil {
-					return err
-				}
-
-				_, err = tx.ExecuteSql(deleteSql, deleteExecuteParams)
-				if err != nil {
-					return err
-				}
-
-				return nil
-			})
-			if err != nil {
-				panic(err)
-			}
-		}()
-	}
-
-	wg.Wait()
-
-	end := time.Now()
-
-	fmt.Println(end.Sub(start).Milliseconds())
-}
-
-func TestRawSqlTemplate(t *testing.T) {
-	classID := strutils.SimpleUUID()
-	className := strutils.SimpleUUID()
-	studentNum := rand.Int31n(100)
-	studentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID()}
-	newClassName := strutils.SimpleUUID()
-	newStudentNum := rand.Int31n(100)
-	newStudentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID()}
-
-	now := time.Now()
-
-	insertExecuteParams, err := sql_tpl.InsertExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().Add("id", classID).
-			Add("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_num", studentNum).
-			Add("student_ids", strings.Join(studentIDs, "\n")).
-			Add("graduated_time", now).
-			Add("created_time", now).
-			Add("last_updated_time", now),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	deleteExecuteParams, err := sql_tpl.DeleteExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().Equal("id", classID),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	updateExecuteParams, err := sql_tpl.UpdateExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().
-			Add("name", newClassName, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_num", newStudentNum).
-			Add("student_ids", strings.Join(newStudentIDs, "\n")),
-		Conditions: sql_tpl.NewConditions().Equal("id", classID),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	queryExecuteParams, err := sql_tpl.QueryExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name", "student_num as student_num_alias", "student_ids", "graduated_time", "created_time", "last_updated_time"},
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-		PageNo:   1,
-		PageSize: 1,
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	newQueryExecuteParams, err := sql_tpl.QueryExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name", "student_num as student_num_alias", "student_ids", "graduated_time", "created_time", "last_updated_time"},
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", newClassName, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", newStudentNum),
-		PageNo:   0,
-		PageSize: 0,
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	countExecuteParams, err := sql_tpl.CountExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	newCountExecuteParams, err := sql_tpl.CountExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", newClassName, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", newStudentNum),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	_, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.InsertTpl, insertExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	queryResults, err := sdk.GetInstance().ExecuteRawSql(sql_tpl.QueryTpl, queryExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	countResults, err := sdk.GetInstance().ExecuteRawSql(sql_tpl.CountTpl, countExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	classes, err := sql.ParseSqlResult[[]Class](queryResults)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if float64(len(classes)) != countResults[0]["count"].(float64) {
-		t.Fatal("总数不正确")
-	}
-
-	graduatedTimeLayout := chooseTimeLayout(queryResults[0]["graduated_time"].(string))
-	createdTimeLayout := chooseTimeLayout(queryResults[0]["created_time"].(string))
-	lastUpdatedTimeLayout := chooseTimeLayout(queryResults[0]["last_updated_time"].(string))
-
-	if classes[0].ID != classID ||
-		classes[0].Name != className ||
-		classes[0].StudentNum != int(studentNum) ||
-		strings.Join(classes[0].StudentIDs, "\n") != strings.Join(studentIDs, "\n") ||
-		classes[0].GraduatedTime.Format(graduatedTimeLayout) != now.Format(graduatedTimeLayout) ||
-		classes[0].CreatedTime.Format(createdTimeLayout) != now.Format(createdTimeLayout) ||
-		classes[0].LastUpdatedTime.Format(lastUpdatedTimeLayout) != now.Format(lastUpdatedTimeLayout) {
-		t.Fatal("查询数据不正确")
-	}
-
-	_, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.UpdateTpl, updateExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	queryResults, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.QueryTpl, newQueryExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	countResults, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.CountTpl, newCountExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	classes, err = sql.ParseSqlResult[[]Class](queryResults)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if float64(len(classes)) != countResults[0]["count"].(float64) {
-		t.Fatal("总数不正确")
-	}
-
-	graduatedTimeLayout = chooseTimeLayout(queryResults[0]["graduated_time"].(string))
-	createdTimeLayout = chooseTimeLayout(queryResults[0]["created_time"].(string))
-	lastUpdatedTimeLayout = chooseTimeLayout(queryResults[0]["last_updated_time"].(string))
-
-	if classes[0].ID != classID ||
-		classes[0].Name != newClassName ||
-		classes[0].StudentNum != int(newStudentNum) ||
-		strings.Join(classes[0].StudentIDs, "\n") != strings.Join(newStudentIDs, "\n") ||
-		classes[0].GraduatedTime.Format(graduatedTimeLayout) != now.Format(graduatedTimeLayout) ||
-		classes[0].CreatedTime.Format(createdTimeLayout) != now.Format(createdTimeLayout) ||
-		classes[0].LastUpdatedTime.Format(lastUpdatedTimeLayout) != now.Format(lastUpdatedTimeLayout) {
-		t.Fatal("查询数据不正确")
-	}
-
-	_, err = sdk.GetInstance().ExecuteRawSql(sql_tpl.DeleteTpl, deleteExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-}
-
-func TestSqlMapping(t *testing.T) {
-	sqlMapping, err := sql.ParseSqlMappingTag(&Class{})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	checkSqlMapping(t, sqlMapping)
-}
-
-func checkSqlMapping(t *testing.T, sqlMapping *sql.Mapping) {
-	for fieldName, mappingElement := range sqlMapping.MappingElement {
-		switch element := mappingElement.(type) {
-		case *sql.Mapping:
-			checkSqlMapping(t, element)
-		case *sql.MappingColumn:
-			if fieldName != "ID" && fieldName != "Name" &&
-				fieldName != "StudentNum" && fieldName != "StudentIDs" &&
-				fieldName != "GraduatedTime" && fieldName != "CreatedTime" &&
-				fieldName != "LastUpdatedTime" {
-				t.Fatal("字段名不正确")
-			}
-
-			if element.Name != "id" && element.Name != "name" &&
-				element.Name != "student_num" && element.Name != "student_ids" &&
-				element.Name != "graduated_time" && element.Name != "created_time" &&
-				element.Name != "last_updated_time" {
-				t.Fatal("列名不正确")
-			}
-
-			if element.Name != "student_ids" && element.Name != strcase.ToSnake(fieldName) {
-				t.Fatal("列名不正确")
-			}
-
-			if element.Name == "id" {
-				if !element.IsKey || element.CanUpdate || element.CanUpdateClear ||
-					strutils.IsStringNotEmpty(element.AESKey) {
-					t.Fatal("id字段Tag不正确")
-				}
-			}
-
-			if element.Name == "name" {
-				if element.IsKey || !element.CanUpdate || !element.CanUpdateClear ||
-					strutils.IsStringEmpty(element.AESKey) || element.AESKey != "@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L" {
-					t.Fatal("name字段Tag不正确")
-				}
-			}
-
-			if element.Name == "student_num" {
-				if element.IsKey || element.CanUpdate || element.CanUpdateClear ||
-					strutils.IsStringNotEmpty(element.AESKey) {
-					t.Fatal("student_num字段Tag不正确")
-				}
-			}
-
-			if element.Name == "student_ids" {
-				if element.JoinWith != "\n" {
-					t.Fatal("student_ids字段Tag不正确")
-				}
-			}
-		default:
-			t.Fatal("不支持的元素类型")
-		}
-	}
-}
-
-func TestSqlResult(t *testing.T) {
-	sqlResult, err := sql.ParseSqlResultTag(&Class{})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	checkSqlResult(t, sqlResult)
-}
-
-func checkSqlResult(t *testing.T, sqlResult *sql.Result) {
-	for fieldName, resultElement := range sqlResult.ResultElement {
-		switch element := resultElement.(type) {
-		case *sql.Result:
-			checkSqlResult(t, element)
-		case *sql.ResultColumn:
-			if fieldName != "ID" && fieldName != "Name" &&
-				fieldName != "StudentNum" && fieldName != "StudentIDs" &&
-				fieldName != "GraduatedTime" && fieldName != "CreatedTime" &&
-				fieldName != "LastUpdatedTime" && fieldName != "Field" {
-				t.Fatal("字段名不正确")
-			}
-
-			if element.Name != "id" && element.Name != "name" &&
-				element.Name != "student_num_alias" && element.Name != "student_ids" &&
-				element.Name != "graduated_time" && element.Name != "created_time" &&
-				element.Name != "last_updated_time" && element.Name != "graduated_time_test" {
-				t.Fatal("列名不正确")
-			}
-
-			if element.Name != "student_num_alias" &&
-				element.Name != "graduated_time" &&
-				element.Name != "student_ids" &&
-				element.Name != strcase.ToSnake(fieldName) {
-				t.Fatal("列名不正确")
-			}
-
-			if element.Name == "id" {
-				if strutils.IsStringNotEmpty(element.ParseTime) ||
-					strutils.IsStringNotEmpty(element.AESKey) {
-					t.Fatal("id字段Tag不正确")
-				}
-			}
-
-			if element.Name == "name" {
-				if strutils.IsStringNotEmpty(element.ParseTime) ||
-					strutils.IsStringEmpty(element.AESKey) ||
-					element.AESKey != "@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L" {
-					t.Fatal("name字段Tag不正确")
-				}
-			}
-
-			if element.Name == "student_num" {
-				if strutils.IsStringNotEmpty(element.ParseTime) ||
-					strutils.IsStringNotEmpty(element.AESKey) {
-					t.Fatal("student_num字段Tag不正确")
-				}
-			}
-
-			if element.Name == "student_ids" {
-				if element.SplitWith != "\n" {
-					t.Fatal("student_ids字段Tag不正确")
-				}
-			}
-
-			if element.Name == "graduate_time" {
-				if strutils.IsStringEmpty(element.ParseTime) ||
-					strutils.IsStringNotEmpty(element.AESKey) {
-					t.Fatal("graduate_time字段Tag不正确")
-				}
-			}
-		}
-	}
-}
-
-func TestSql(t *testing.T) {
-	classID := strutils.SimpleUUID()
-	className := strutils.SimpleUUID()
-	studentNum := rand.Int31n(100)
-	studentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID()}
-	newClassName := strutils.SimpleUUID()
-	newStudentNum := rand.Int31n(100)
-	newStudentIDs := []string{strutils.SimpleUUID(), strutils.SimpleUUID()}
-	now := time.Now()
-	newNow := time.Now()
-
-	insertExecuteParams, err := sql_tpl.InsertExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().Add("id", classID).
-			Add("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_num", studentNum).
-			Add("student_ids", strings.Join(studentIDs, "\n")).
-			Add("graduated_time", now).
-			Add("created_time", now).
-			Add("last_updated_time", now),
-	}.Map()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	deleteExecuteParams := map[string]any{
-		"table_name": tableName,
-		"id":         classID,
-	}
-
-	class := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          className,
-		StudentNum:    int(studentNum),
-		StudentIDs:    studentIDs,
-		GraduatedTime: &now,
-		Ignored:       "",
-	}
-
-	newClass := &Class{
-		IDField:       IDField{ID: classID},
-		Name:          newClassName,
-		StudentNum:    int(newStudentNum),
-		StudentIDs:    newStudentIDs,
-		GraduatedTime: &newNow,
-		Ignored:       "",
-	}
-
-	err = sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	err = sdk.GetInstance().CreateSQL(deleteSql, sqlSpec.ToMap())
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err = sdk.GetInstance().DeleteSQL(deleteSql)
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	err = sql.InsertEntity(sdk.GetInstance(), tableName, class)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.UpdateEntity(sdk.GetInstance(), tableName, newClass)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.DeleteEntity(sdk.GetInstance(), tableName, class)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.Insert(sdk.GetInstance(), &sql_tpl.InsertExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().Add("id", classID).
-			Add("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_num", studentNum).
-			Add("student_ids", strings.Join(studentIDs, "\n")).
-			Add("graduated_time", now).
-			Add("created_time", now).
-			Add("last_updated_time", now),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.Update(sdk.GetInstance(), &sql_tpl.UpdateExecuteParams{
-		TableName: tableName,
-		TableRow: sql_tpl.NewTableRow().Add("id", classID).
-			Add("name", newClassName, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Add("student_ids", strings.Join(newStudentIDs, "\n")).
-			Add("student_num", newStudentNum),
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.Delete(sdk.GetInstance(), &sql_tpl.DeleteExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	_, err = sql.ExecuteRawSql(sdk.GetInstance(), sql_tpl.InsertTpl, insertExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	_, err = sql.ExecuteSql(sdk.GetInstance(), deleteSql, deleteExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sdk.GetInstance().Transaction(func(tx *sdk.Transaction) error {
-		err = sql.InsertEntity(tx, tableName, class)
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		err = sql.UpdateEntity(tx, tableName, newClass)
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		err = sql.DeleteEntity(tx, tableName, class)
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		err = sql.Insert(tx, &sql_tpl.InsertExecuteParams{
-			TableName: tableName,
-			TableRow: sql_tpl.NewTableRow().Add("id", classID).
-				Add("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-				Add("student_num", studentNum).
-				Add("student_ids", strings.Join(studentIDs, "\n")).
-				Add("graduated_time", now).
-				Add("created_time", now).
-				Add("last_updated_time", now),
-		})
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		err = sql.Update(tx, &sql_tpl.UpdateExecuteParams{
-			TableName: tableName,
-			TableRow: sql_tpl.NewTableRow().Add("id", classID).
-				Add("name", newClassName, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-				Add("student_num", newStudentNum).
-				Add("student_ids", strings.Join(newStudentIDs, "\n")),
-			Conditions: sql_tpl.NewConditions().
-				Equal("id", classID),
-		})
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		err = sql.Delete(tx, &sql_tpl.DeleteExecuteParams{
-			TableName: tableName,
-			Conditions: sql_tpl.NewConditions().
-				Equal("id", classID),
-		})
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		_, err = sql.ExecuteRawSql(tx, sql_tpl.InsertTpl, insertExecuteParams)
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		_, err = sql.ExecuteSql(tx, deleteSql, deleteExecuteParams)
-		if err != nil {
-			t.Fatal(err)
-		}
-
-		return nil
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.InsertEntity(sdk.GetInstance(), tableName, class)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	tableRows, totalCount, err := sql.Query(sdk.GetInstance(), &sql_tpl.QueryExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name", "student_ids"},
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-		PageNo:   0,
-		PageSize: 0,
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if totalCount != 1 || len(tableRows) != int(totalCount) {
-		t.Fatal("总数不正确")
-	}
-
-	queryClasses, err := sql.ParseSqlResult[[]Class](tableRows)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if queryClasses[0].ID != classID ||
-		queryClasses[0].Name != className ||
-		queryClasses[0].StudentNum != 0 ||
-		strings.Join(queryClasses[0].StudentIDs, "\n") != strings.Join(studentIDs, "\n") ||
-		!queryClasses[0].GraduatedTime.IsZero() ||
-		(queryClasses[0].CreatedTime != nil && !queryClasses[0].CreatedTime.IsZero()) ||
-		!queryClasses[0].LastUpdatedTime.IsZero() {
-		t.Fatal("查询数据不正确")
-	}
-
-	tableRow, err := sql.QueryOne(sdk.GetInstance(), &sql_tpl.QueryOneExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name"},
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	queryClass, err := sql.ParseSqlResult[Class](tableRow)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if queryClass.ID != classID ||
-		queryClass.Name != className ||
-		queryClass.StudentNum != 0 ||
-		strings.Join(queryClasses[0].StudentIDs, "\n") != strings.Join(studentIDs, "\n") ||
-		!queryClass.GraduatedTime.IsZero() ||
-		(queryClass.CreatedTime != nil && !queryClass.CreatedTime.IsZero()) ||
-		!queryClass.LastUpdatedTime.IsZero() {
-		t.Fatal("查询数据不正确")
-	}
-
-	queryCount, err := sql.Count(sdk.GetInstance(), &sql_tpl.CountExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if queryCount != 1 {
-		t.Fatal("数量不正确")
-	}
-
-	exist, err := sql.CheckExist(sdk.GetInstance(), &sql_tpl.CheckExistExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if !exist {
-		t.Fatal("存在状态错误")
-	}
-
-	hasOnlyOne, err := sql.CheckHasOnlyOne(sdk.GetInstance(), &sql_tpl.CheckHasOnlyOneExecuteParams{
-		TableName: tableName,
-		Conditions: sql_tpl.NewConditions().
-			Equal("id", classID).
-			Equal("name", className, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-			Equal("student_num", studentNum),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if !hasOnlyOne {
-		t.Fatal("唯一性错误")
-	}
-
-	err = sql.DeleteEntity(sdk.GetInstance(), tableName, class)
-	if err != nil {
-		t.Fatal(err)
-	}
-}
-
-func TestInsertBatch(t *testing.T) {
-	classID1 := strutils.SimpleUUID()
-	className1 := strutils.SimpleUUID()
-	studentNum1 := rand.Int31n(100)
-	classID2 := strutils.SimpleUUID()
-	className2 := strutils.SimpleUUID()
-	studentNum2 := rand.Int31n(100)
-	now := time.Now()
-
-	insertBatchExecuteParams := &sql_tpl.InsertBatchExecuteParams{
-		TableName: tableName,
-		TableRowBatch: []sql_tpl.TableRow{
-			*(sql_tpl.NewTableRow().Add("id", classID1).
-				Add("name", className1, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-				Add("student_num", studentNum1).
-				Add("student_ids", "").
-				Add("created_time", now).
-				Add("last_updated_time", now)),
-			*(sql_tpl.NewTableRow().Add("id", classID2).
-				Add("name", className2, sql_tpl.WithAESKey("@MKU^AHYCN$:j76J<TAHCVD#$XZSWQ@L")).
-				Add("student_num", studentNum2).
-				Add("student_ids", "").
-				Add("created_time", now).
-				Add("last_updated_time", now)),
-		},
-	}
-
-	class1 := &Class{
-		IDField:    IDField{ID: classID1},
-		Name:       className1,
-		StudentNum: int(studentNum1),
-		StudentIDs: make([]string, 0),
-	}
-
-	class2 := &Class{
-		IDField:    IDField{ID: classID2},
-		Name:       className2,
-		StudentNum: int(studentNum2),
-		StudentIDs: make([]string, 0),
-	}
-
-	err := sdk.InitInstance(token, address, httpPort, grpcPort, namespace, dataSource)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	defer func() {
-		err := sdk.DestroyInstance()
-		if err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	err = sql.InsertBatch(sdk.GetInstance(), insertBatchExecuteParams)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	results, _, err := sql.Query(sdk.GetInstance(), &sql_tpl.QueryExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name", "student_num as student_num_alias"},
-		Conditions:    sql_tpl.NewConditions().In("id", []string{classID1, classID2}),
-		PageNo:        0,
-		PageSize:      0,
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	classInfos, err := sql.ParseSqlResult[[]Class](results)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	for _, classInfo := range classInfos {
-		if classInfo.ID != classID1 && classInfo.ID != classID2 {
-			t.Fatal("id不正确")
-		}
-
-		if classInfo.ID == classID1 &&
-			(classInfo.Name != className1 || classInfo.StudentNum != int(studentNum1)) {
-			t.Fatal("数据不正确")
-		}
-
-		if classInfo.ID == classID2 &&
-			(classInfo.Name != className2 || classInfo.StudentNum != int(studentNum2)) {
-			t.Fatal("数据不正确")
-		}
-	}
-
-	err = sql.Delete(sdk.GetInstance(), &sql_tpl.DeleteExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().In("id", []string{classID1, classID2}),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = sql.InsertEntity(sdk.GetInstance(), tableName, []*Class{class1, class2})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	results, _, err = sql.Query(sdk.GetInstance(), &sql_tpl.QueryExecuteParams{
-		TableName:     tableName,
-		SelectColumns: []string{"id", "name", "student_num as student_num_alias"},
-		Conditions:    sql_tpl.NewConditions().In("id", []string{classID1, classID2}),
-		PageNo:        0,
-		PageSize:      0,
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	classInfos, err = sql.ParseSqlResult[[]Class](results)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	for _, classInfo := range classInfos {
-		if classInfo.ID != classID1 && classInfo.ID != classID2 {
-			t.Fatal("id不正确")
-		}
-
-		if classInfo.ID == classID1 &&
-			(classInfo.Name != className1 || classInfo.StudentNum != int(studentNum1)) {
-			t.Fatal("数据不正确")
-		}
-
-		if classInfo.ID == classID2 &&
-			(classInfo.Name != className2 || classInfo.StudentNum != int(studentNum2)) {
-			t.Fatal("数据不正确")
-		}
-	}
-
-	err = sql.Delete(sdk.GetInstance(), &sql_tpl.DeleteExecuteParams{
-		TableName:  tableName,
-		Conditions: sql_tpl.NewConditions().In("id", []string{classID1, classID2}),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-}