Ver código fonte

修改变量名

yjp 11 meses atrás
pai
commit
bc8250b450
4 arquivos alterados com 32 adições e 32 exclusões
  1. 4 4
      README.md
  2. 18 18
      sql/sql.go
  3. 9 9
      sql/sql_tpl/sql_tpl.go
  4. 1 1
      test/sdk_test.go

+ 4 - 4
README.md

@@ -395,11 +395,11 @@ executeParams: 插入操作需要的参数,如下所示
 ```go
 type InsertExecuteParams struct {
 	TableName string
-	*TableRows
+	*TableRow
 }
 ```
 
-TableRows可以通过sql_tpl中的NewTableRows()函数创建,其中Add方法可以用来添加列
+TableRow可以通过sql_tpl中的NewTableRow()函数创建,其中Add方法可以用来添加列
 
 返回值:
 
@@ -465,12 +465,12 @@ executeParams: 更新操作需要的参数,如下所示
 ```go
 type UpdateExecuteParams struct {
     TableName string
-    *TableRows
+    *TableRow
     *Conditions
 }
 ```
 
-TableRows可以通过sql_tpl中的NewTableRows()函数创建,其中Add方法可以用来添加列
+TableRow可以通过sql_tpl中的NewTableRow()函数创建,其中Add方法可以用来添加列
 
 Conditions可以通过sql_tpl中的NewConditions()函数创建,其中有各种条件可供使用,如Equal,Like等
 

+ 18 - 18
sql/sql.go

@@ -57,15 +57,15 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
 			return err
 		}
 
-		tableRows := sql_tpl.NewTableRow()
-		err = formInsertTableRow(sqlMapping, tableRows)
+		tableRow := sql_tpl.NewTableRow()
+		err = formInsertTableRow(sqlMapping, tableRow)
 		if err != nil {
 			return err
 		}
 
 		innerExecuteParamsMap, err := sql_tpl.InsertExecuteParams{
 			TableName: tableName,
-			TableRow:  tableRows,
+			TableRow:  tableRow,
 		}.Map()
 		if err != nil {
 			return err
@@ -78,7 +78,7 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
 			return nil
 		}
 
-		tableRowsBatch := make([]sql_tpl.TableRow, 0)
+		tableRowBatch := make([]sql_tpl.TableRow, 0)
 
 		for i := 0; i < entitySliceValue.Len(); i++ {
 			sqlMapping, err := ParseSqlMappingTag(entitySliceValue.Index(i).Interface())
@@ -86,18 +86,18 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
 				return err
 			}
 
-			tableRows := sql_tpl.NewTableRow()
-			err = formInsertTableRow(sqlMapping, tableRows)
+			tableRow := sql_tpl.NewTableRow()
+			err = formInsertTableRow(sqlMapping, tableRow)
 			if err != nil {
 				return err
 			}
 
-			tableRowsBatch = append(tableRowsBatch, *tableRows)
+			tableRowBatch = append(tableRowBatch, *tableRow)
 		}
 
 		innerExecuteParamsMap, err := sql_tpl.InsertBatchExecuteParams{
-			TableName:      tableName,
-			TableRowsBatch: tableRowsBatch,
+			TableName:     tableName,
+			TableRowBatch: tableRowBatch,
 		}.Map()
 		if err != nil {
 			return err
@@ -118,13 +118,13 @@ func InsertEntity[T any](executor Executor, tableName string, e T) error {
 	return nil
 }
 
-func formInsertTableRow(sqlMapping *Mapping, tableRows *sql_tpl.TableRow) error {
+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, tableRows)
+			err := formInsertTableRow(element, tableRow)
 			if err != nil {
 				return err
 			}
@@ -170,7 +170,7 @@ func formInsertTableRow(sqlMapping *Mapping, tableRows *sql_tpl.TableRow) error
 				opts = append(opts, sql_tpl.WithAESKey(element.AESKey))
 			}
 
-			tableRows.Add(element.Name, value, opts...)
+			tableRow.Add(element.Name, value, opts...)
 		default:
 			return errors.New("不支持的元素类型")
 		}
@@ -270,16 +270,16 @@ func UpdateEntity[T any](executor Executor, tableName string, e T) error {
 		return err
 	}
 
-	tableRows := sql_tpl.NewTableRow()
+	tableRow := sql_tpl.NewTableRow()
 	conditions := sql_tpl.NewConditions()
-	err = formUpdateTableRowsAndConditions(sqlMapping, tableRows, conditions)
+	err = formUpdateTableRowAndConditions(sqlMapping, tableRow, conditions)
 	if err != nil {
 		return err
 	}
 
 	executeParamsMap, err := sql_tpl.UpdateExecuteParams{
 		TableName:  tableName,
-		TableRow:   tableRows,
+		TableRow:   tableRow,
 		Conditions: conditions,
 	}.Map()
 	if err != nil {
@@ -294,13 +294,13 @@ func UpdateEntity[T any](executor Executor, tableName string, e T) error {
 	return nil
 }
 
-func formUpdateTableRowsAndConditions(sqlMapping *Mapping, tableRows *sql_tpl.TableRow, conditions *sql_tpl.Conditions) error {
+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 := formUpdateTableRowsAndConditions(element, tableRows, conditions)
+			err := formUpdateTableRowAndConditions(element, tableRow, conditions)
 			if err != nil {
 				return err
 			}
@@ -364,7 +364,7 @@ func formUpdateTableRowsAndConditions(sqlMapping *Mapping, tableRows *sql_tpl.Ta
 			if element.IsKey {
 				conditions.Equal(element.Name, value, opts...)
 			} else {
-				tableRows.Add(element.Name, value, opts...)
+				tableRow.Add(element.Name, value, opts...)
 			}
 		default:
 			return errors.New("不支持的元素类型")

+ 9 - 9
sql/sql_tpl/sql_tpl.go

@@ -44,34 +44,34 @@ func (params InsertExecuteParams) Map() (map[string]any, error) {
 }
 
 type InsertBatchExecuteParams struct {
-	TableName      string
-	TableRowsBatch []TableRow
+	TableName     string
+	TableRowBatch []TableRow
 }
 
 func (params InsertBatchExecuteParams) Map() (map[string]any, error) {
-	if params.TableRowsBatch == nil || len(params.TableRowsBatch) == 0 {
+	if params.TableRowBatch == nil || len(params.TableRowBatch) == 0 {
 		return nil, nil
 	}
 
 	columns := make([]string, 0)
-	for _, cv := range params.TableRowsBatch[0].columnValues {
+	for _, cv := range params.TableRowBatch[0].columnValues {
 		columns = append(columns, cv.column)
 	}
 
 	valuesList := make([]any, 0)
 
-	for _, tableRows := range params.TableRowsBatch {
-		if tableRows.err != nil {
-			return nil, tableRows.err
+	for _, tableRow := range params.TableRowBatch {
+		if tableRow.err != nil {
+			return nil, tableRow.err
 		}
 
-		if len(columns) != len(tableRows.columnValues) {
+		if len(columns) != len(tableRow.columnValues) {
 			return nil, errors.New("列数不匹配,保证每个TableRow的Add数量一致")
 		}
 
 		columnAndValueMap := make(map[string]any, 0)
 
-		for _, cv := range tableRows.columnValues {
+		for _, cv := range tableRow.columnValues {
 			columnAndValueMap[cv.column] = cv.value
 		}
 

+ 1 - 1
test/sdk_test.go

@@ -823,7 +823,7 @@ func TestInsertBatch(t *testing.T) {
 
 	insertBatchExecuteParams := &sql_tpl.InsertBatchExecuteParams{
 		TableName: tableName,
-		TableRowsBatch: []sql_tpl.TableRow{
+		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).