yjp 1 år sedan
förälder
incheckning
2a4b9ad1b9
3 ändrade filer med 190 tillägg och 188 borttagningar
  1. 115 29
      sdk/raw_sql_tpl/raw_sql_tpl.go
  2. 31 111
      sdk/sql.go
  3. 44 48
      test/sdk_test.go

+ 115 - 29
sdk/raw_sql_tpl/raw_sql_tpl.go

@@ -4,40 +4,59 @@ import (
 	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/fatih/structs"
+	"reflect"
+	"strconv"
+	"time"
 )
 
 type TableRow struct {
-	Column string `structs:"column"`
-	Value  string `structs:"value"`
+	Column      string `structs:"column"`
+	Value       any    `structs:"-"`
+	ParsedValue string `structs:"value"`
 }
 
-func (tableRow TableRow) check() error {
+func (tableRow *TableRow) parse() error {
 	if strutils.IsStringEmpty(tableRow.Column) {
 		return errors.New("没有传递列名")
 	}
 
-	if strutils.IsStringEmpty(tableRow.Value) {
+	if tableRow.Value == nil {
 		return errors.New("没有传递列值")
 	}
 
+	parsedValue, err := parseValue(tableRow.Value)
+	if err != nil {
+		return err
+	}
+
+	tableRow.ParsedValue = parsedValue
+
 	return nil
 }
 
 type Condition struct {
-	Column   string `structs:"column"`
-	Operator string `structs:"operator"`
-	Value    string `structs:"value"`
+	Column      string `structs:"column"`
+	Operator    string `structs:"operator"`
+	Value       any    `structs:"-"`
+	ParsedValue string `structs:"value"`
 }
 
-func (cond Condition) check() error {
+func (cond *Condition) parse() error {
 	if strutils.IsStringEmpty(cond.Column) {
 		return errors.New("没有传递列名")
 	}
 
-	if strutils.IsStringEmpty(cond.Value) {
-		return errors.New("没有传递值")
+	if cond.Value == nil {
+		return errors.New("没有传递条件值")
 	}
 
+	parsedValue, err := parseValue(cond.Value)
+	if err != nil {
+		return err
+	}
+
+	cond.ParsedValue = parsedValue
+
 	return nil
 }
 
@@ -50,7 +69,7 @@ VALUES
 
 type InsertExecuteParams struct {
 	TableName string
-	TableRows []TableRow
+	TableRows []*TableRow
 }
 
 func (params InsertExecuteParams) check() error {
@@ -63,7 +82,7 @@ func (params InsertExecuteParams) check() error {
 	}
 
 	for _, tableRow := range params.TableRows {
-		if err := tableRow.check(); err != nil {
+		if err := tableRow.parse(); err != nil {
 			return err
 		}
 	}
@@ -77,10 +96,10 @@ func (params InsertExecuteParams) Map() (map[string]any, error) {
 	}
 
 	columns := make([]string, 0)
-	values := make([]string, 0)
+	values := make([]any, 0)
 	for _, tableRow := range params.TableRows {
 		columns = append(columns, tableRow.Column)
-		values = append(values, tableRow.Value)
+		values = append(values, tableRow.ParsedValue)
 	}
 
 	return map[string]any{
@@ -98,8 +117,8 @@ WHERE
 `
 
 type DeleteExecuteParams struct {
-	TableName  string      `structs:"table_name"`
-	Conditions []Condition `structs:"conditions"`
+	TableName  string       `structs:"table_name"`
+	Conditions []*Condition `structs:"conditions"`
 }
 
 func (params DeleteExecuteParams) check() error {
@@ -112,7 +131,7 @@ func (params DeleteExecuteParams) check() error {
 	}
 
 	for _, condition := range params.Conditions {
-		if err := condition.check(); err != nil {
+		if err := condition.parse(); err != nil {
 			return err
 		}
 	}
@@ -144,9 +163,9 @@ WHERE
 `
 
 type UpdateExecuteParams struct {
-	TableName  string      `structs:"table_name"`
-	TableRows  []TableRow  `structs:"table_rows"`
-	Conditions []Condition `structs:"conditions"`
+	TableName  string       `structs:"table_name"`
+	TableRows  []*TableRow  `structs:"table_rows"`
+	Conditions []*Condition `structs:"conditions"`
 }
 
 func (params UpdateExecuteParams) check() error {
@@ -159,7 +178,7 @@ func (params UpdateExecuteParams) check() error {
 	}
 
 	for _, tableRow := range params.TableRows {
-		if err := tableRow.check(); err != nil {
+		if err := tableRow.parse(); err != nil {
 			return err
 		}
 	}
@@ -169,7 +188,7 @@ func (params UpdateExecuteParams) check() error {
 	}
 
 	for _, condition := range params.Conditions {
-		if err := condition.check(); err != nil {
+		if err := condition.parse(); err != nil {
 			return err
 		}
 	}
@@ -197,11 +216,11 @@ WHERE
 `
 
 type QueryExecuteParams struct {
-	TableName     string      `structs:"table_name"`
-	SelectColumns []string    `structs:"select_columns"`
-	Conditions    []Condition `structs:"conditions"`
-	Limit         int         `structs:"limit"`
-	Offset        int         `structs:"offset"`
+	TableName     string       `structs:"table_name"`
+	SelectColumns []string     `structs:"select_columns"`
+	Conditions    []*Condition `structs:"conditions"`
+	Limit         int          `structs:"limit"`
+	Offset        int          `structs:"offset"`
 }
 
 func (params QueryExecuteParams) check() error {
@@ -209,6 +228,14 @@ func (params QueryExecuteParams) check() error {
 		return errors.New("没有传递表名")
 	}
 
+	if params.Conditions != nil && len(params.Conditions) != 0 {
+		for _, condition := range params.Conditions {
+			if err := condition.parse(); err != nil {
+				return err
+			}
+		}
+	}
+
 	return nil
 }
 
@@ -229,8 +256,8 @@ WHERE
 	{{ range .conditions }} {{ .column }} {{ if .operator }}{{ .operator }}{{ else }}={{ end }} {{ .value }} AND {{ end }} 1 = 1`
 
 type CountExecuteParams struct {
-	TableName  string      `structs:"table_name"`
-	Conditions []Condition `structs:"conditions"`
+	TableName  string       `structs:"table_name"`
+	Conditions []*Condition `structs:"conditions"`
 }
 
 func (params CountExecuteParams) check() error {
@@ -238,6 +265,14 @@ func (params CountExecuteParams) check() error {
 		return errors.New("没有传递表名")
 	}
 
+	if params.Conditions != nil && len(params.Conditions) != 0 {
+		for _, condition := range params.Conditions {
+			if err := condition.parse(); err != nil {
+				return err
+			}
+		}
+	}
+
 	return nil
 }
 
@@ -248,3 +283,54 @@ func (params CountExecuteParams) Map() (map[string]any, error) {
 
 	return structs.Map(params), nil
 }
+
+const (
+	timeWriteFormat = time.DateTime + ".000000 +08:00"
+)
+
+func parseValue(value any) (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()
+	}
+
+	switch v := valueValue.Interface().(type) {
+	case string:
+		return "'" + v + "'", nil
+	case bool:
+		return strconv.FormatBool(v), nil
+	case time.Time:
+		return "'" + v.Format(timeWriteFormat) + "'", nil
+	case int:
+		return strconv.Itoa(v), nil
+	case int8:
+		return strconv.FormatInt(int64(v), 10), nil
+	case int16:
+		return strconv.FormatInt(int64(v), 10), nil
+	case int32:
+		return strconv.FormatInt(int64(v), 10), nil
+	case int64:
+		return strconv.FormatInt(v, 10), nil
+	case uint:
+		return strconv.FormatUint(uint64(v), 10), nil
+	case uint8:
+		return strconv.FormatUint(uint64(v), 10), nil
+	case uint16:
+		return strconv.FormatUint(uint64(v), 10), nil
+	case uint32:
+		return strconv.FormatUint(uint64(v), 10), nil
+	case uint64:
+		return strconv.FormatUint(v, 10), nil
+	default:
+		return "", errors.New("不支持的类型")
+	}
+}

+ 31 - 111
sdk/sql.go

@@ -6,7 +6,6 @@ import (
 	"git.sxidc.com/service-supports/ds-sdk/sdk/raw_sql_tpl"
 	"git.sxidc.com/service-supports/ds-sdk/sdk/tag"
 	"reflect"
-	"strconv"
 	"strings"
 	"time"
 )
@@ -17,7 +16,6 @@ type SqlExecutor interface {
 }
 
 const (
-	timeWriteFormat          = time.DateTime + ".000000 +08:00"
 	createdTimeFieldName     = "CreatedTime"
 	lastUpdatedTimeFieldName = "LastUpdatedTime"
 )
@@ -80,14 +78,9 @@ func Insert[T any](executor SqlExecutor, tableName string, e T, callback ValueCa
 			value = now
 		}
 
-		tableRowValue, err := parseValue(value)
-		if err != nil {
-			return err
-		}
-
-		executeParams.TableRows = append(executeParams.TableRows, raw_sql_tpl.TableRow{
+		executeParams.TableRows = append(executeParams.TableRows, &raw_sql_tpl.TableRow{
 			Column: sqlMappingColumn.Name,
-			Value:  tableRowValue,
+			Value:  value,
 		})
 	}
 
@@ -128,7 +121,7 @@ func Delete[T any](executor SqlExecutor, tableName string, e T) error {
 
 	executeParams := raw_sql_tpl.DeleteExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for _, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -143,15 +136,10 @@ func Delete[T any](executor SqlExecutor, tableName string, e T) error {
 			value = sqlMappingColumn.ValueFieldValue.Interface()
 		}
 
-		tableRowValue, err := parseValue(value)
-		if err != nil {
-			return err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: "=",
-			Value:    tableRowValue,
+			Value:    value,
 		})
 	}
 
@@ -188,7 +176,7 @@ func Update[T any](executor SqlExecutor, tableName string, e T, callback ValueCa
 
 	executeParams := raw_sql_tpl.UpdateExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	now := time.Now()
@@ -233,23 +221,18 @@ func Update[T any](executor SqlExecutor, tableName string, e T, callback ValueCa
 			continue
 		}
 
-		tableRowValue, err := parseValue(value)
-		if err != nil {
-			return err
-		}
-
 		if !sqlMappingColumn.IsKey {
-			executeParams.TableRows = append(executeParams.TableRows, raw_sql_tpl.TableRow{
+			executeParams.TableRows = append(executeParams.TableRows, &raw_sql_tpl.TableRow{
 				Column: sqlMappingColumn.Name,
-				Value:  tableRowValue,
+				Value:  value,
 			})
 		}
 
 		if sqlMappingColumn.IsKey {
-			executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+			executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 				Column:   sqlMappingColumn.Name,
 				Operator: "=",
-				Value:    tableRowValue,
+				Value:    value,
 			})
 		}
 	}
@@ -294,14 +277,14 @@ func Query[T any](executor SqlExecutor, tableName string, e T, pageNo int, pageS
 
 	executeParams := raw_sql_tpl.QueryExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 		Limit:      limit,
 		Offset:     offset,
 	}
 
 	countParams := raw_sql_tpl.CountExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for fieldName, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -342,21 +325,16 @@ func Query[T any](executor SqlExecutor, tableName string, e T, pageNo int, pageS
 			continue
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return nil, 0, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: conditionOp,
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 
-		countParams.Conditions = append(countParams.Conditions, raw_sql_tpl.Condition{
+		countParams.Conditions = append(countParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: conditionOp,
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -403,7 +381,7 @@ func QueryByKeys[T any](executor SqlExecutor, tableName string, e T) (map[string
 
 	executeParams := raw_sql_tpl.QueryExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 		Limit:      0,
 		Offset:     0,
 	}
@@ -420,15 +398,10 @@ func QueryByKeys[T any](executor SqlExecutor, tableName string, e T) (map[string
 			conditionValue = sqlMappingColumn.ValueFieldValue.Interface()
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return nil, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: "=",
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -469,7 +442,7 @@ func Count[T any](executor SqlExecutor, tableName string, e T, callback Conditio
 
 	executeParams := raw_sql_tpl.CountExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for fieldName, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -501,15 +474,10 @@ func Count[T any](executor SqlExecutor, tableName string, e T, callback Conditio
 			conditionOp = retConditionOp
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return 0, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: conditionOp,
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -546,7 +514,7 @@ func CheckExist[T any](executor SqlExecutor, tableName string, e T, callback Con
 
 	executeParams := raw_sql_tpl.CountExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for fieldName, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -578,15 +546,10 @@ func CheckExist[T any](executor SqlExecutor, tableName string, e T, callback Con
 			conditionOp = retConditionOp
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return false, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: conditionOp,
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -623,7 +586,7 @@ func CheckExistByKey[T any](executor SqlExecutor, tableName string, e T) (bool,
 
 	executeParams := raw_sql_tpl.CountExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for _, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -638,15 +601,10 @@ func CheckExistByKey[T any](executor SqlExecutor, tableName string, e T) (bool,
 			conditionValue = sqlMappingColumn.ValueFieldValue.Interface()
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return false, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: "=",
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -683,7 +641,7 @@ func CheckHasOnlyOne[T any](executor SqlExecutor, tableName string, e T, callbac
 
 	executeParams := raw_sql_tpl.CountExecuteParams{
 		TableName:  tableName,
-		Conditions: make([]raw_sql_tpl.Condition, 0),
+		Conditions: make([]*raw_sql_tpl.Condition, 0),
 	}
 
 	for fieldName, sqlMappingColumn := range sqlMapping.ColumnMap {
@@ -715,15 +673,10 @@ func CheckHasOnlyOne[T any](executor SqlExecutor, tableName string, e T, callbac
 			conditionOp = retConditionOp
 		}
 
-		tableRowValue, err := parseValue(conditionValue)
-		if err != nil {
-			return false, err
-		}
-
-		executeParams.Conditions = append(executeParams.Conditions, raw_sql_tpl.Condition{
+		executeParams.Conditions = append(executeParams.Conditions, &raw_sql_tpl.Condition{
 			Column:   sqlMappingColumn.Name,
 			Operator: conditionOp,
-			Value:    tableRowValue,
+			Value:    conditionValue,
 		})
 	}
 
@@ -773,36 +726,3 @@ func ExecuteSql(executor SqlExecutor, name string, executeParams map[string]any)
 
 	return tableRows, nil
 }
-
-func parseValue(value any) (string, error) {
-	switch v := value.(type) {
-	case string:
-		return "'" + v + "'", nil
-	case bool:
-		return strconv.FormatBool(v), nil
-	case time.Time:
-		return "'" + v.Format(timeWriteFormat) + "'", nil
-	case int:
-		return strconv.Itoa(v), nil
-	case int8:
-		return strconv.FormatInt(int64(v), 10), nil
-	case int16:
-		return strconv.FormatInt(int64(v), 10), nil
-	case int32:
-		return strconv.FormatInt(int64(v), 10), nil
-	case int64:
-		return strconv.FormatInt(v, 10), nil
-	case uint:
-		return strconv.FormatUint(uint64(v), 10), nil
-	case uint8:
-		return strconv.FormatUint(uint64(v), 10), nil
-	case uint16:
-		return strconv.FormatUint(uint64(v), 10), nil
-	case uint32:
-		return strconv.FormatUint(uint64(v), 10), nil
-	case uint64:
-		return strconv.FormatUint(v, 10), nil
-	default:
-		return "", errors.New("不支持的类型")
-	}
-}

+ 44 - 48
test/sdk_test.go

@@ -8,7 +8,6 @@ import (
 	"git.sxidc.com/service-supports/ds-sdk/sdk/tag"
 	"github.com/iancoleman/strcase"
 	"math/rand"
-	"strconv"
 	"sync"
 	"testing"
 	"time"
@@ -47,34 +46,33 @@ func TestBasic(t *testing.T) {
 	className := strutils.SimpleUUID()
 	studentNum := rand.Int31n(100)
 	now := time.Now()
-	nowStr := now.Format(time.DateTime + ".000000 +08:00")
 
 	insertExecuteParams, err := raw_sql_tpl.InsertExecuteParams{
 		TableName: tableName,
-		TableRows: []raw_sql_tpl.TableRow{
+		TableRows: []*raw_sql_tpl.TableRow{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + className + "'",
+				Value:  className,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(studentNum), 10),
+				Value:  studentNum,
 			},
 			{
 				Column: "graduated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "created_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "last_updated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 		},
 	}.Map()
@@ -164,35 +162,34 @@ func TestRawSqlTemplate(t *testing.T) {
 	newStudentNum := rand.Int31n(100)
 
 	now := time.Now()
-	nowStr := now.Format(time.DateTime + ".000000 +08:00")
 	exceptedNowStr := now.Format("2006-01-02T15:04:05.000000+08:00")
 
 	insertExecuteParams, err := raw_sql_tpl.InsertExecuteParams{
 		TableName: tableName,
-		TableRows: []raw_sql_tpl.TableRow{
+		TableRows: []*raw_sql_tpl.TableRow{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + className + "'",
+				Value:  className,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(studentNum), 10),
+				Value:  studentNum,
 			},
 			{
 				Column: "graduated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "created_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "last_updated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 		},
 	}.Map()
@@ -202,10 +199,10 @@ func TestRawSqlTemplate(t *testing.T) {
 
 	deleteExecuteParams, err := raw_sql_tpl.DeleteExecuteParams{
 		TableName: tableName,
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 		},
 	}.Map()
@@ -215,20 +212,20 @@ func TestRawSqlTemplate(t *testing.T) {
 
 	updateExecuteParams, err := raw_sql_tpl.UpdateExecuteParams{
 		TableName: tableName,
-		TableRows: []raw_sql_tpl.TableRow{
+		TableRows: []*raw_sql_tpl.TableRow{
 			{
 				Column: "name",
-				Value:  "'" + newClassName + "'",
+				Value:  newClassName,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(newStudentNum), 10),
+				Value:  newStudentNum,
 			},
 		},
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 		},
 	}.Map()
@@ -239,18 +236,18 @@ func TestRawSqlTemplate(t *testing.T) {
 	queryExecuteParams, err := raw_sql_tpl.QueryExecuteParams{
 		TableName:     tableName,
 		SelectColumns: []string{"id", "name", "student_num as student_num_alias", "graduated_time", "created_time", "last_updated_time"},
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + className + "'",
+				Value:  className,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(studentNum), 10),
+				Value:  studentNum,
 			},
 		},
 		Limit:  1,
@@ -263,18 +260,18 @@ func TestRawSqlTemplate(t *testing.T) {
 	newQueryExecuteParams, err := raw_sql_tpl.QueryExecuteParams{
 		TableName:     tableName,
 		SelectColumns: []string{"id", "name", "student_num as student_num_alias", "graduated_time", "created_time", "last_updated_time"},
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + newClassName + "'",
+				Value:  newClassName,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(newStudentNum), 10),
+				Value:  newStudentNum,
 			},
 		},
 		Limit:  0,
@@ -286,18 +283,18 @@ func TestRawSqlTemplate(t *testing.T) {
 
 	countExecuteParams, err := raw_sql_tpl.CountExecuteParams{
 		TableName: tableName,
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + className + "'",
+				Value:  className,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(studentNum), 10),
+				Value:  studentNum,
 			},
 		},
 	}.Map()
@@ -307,18 +304,18 @@ func TestRawSqlTemplate(t *testing.T) {
 
 	newCountExecuteParams, err := raw_sql_tpl.CountExecuteParams{
 		TableName: tableName,
-		Conditions: []raw_sql_tpl.Condition{
+		Conditions: []*raw_sql_tpl.Condition{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + newClassName + "'",
+				Value:  newClassName,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(newStudentNum), 10),
+				Value:  newStudentNum,
 			},
 		},
 	}.Map()
@@ -507,34 +504,33 @@ func TestSql(t *testing.T) {
 	newClassName := strutils.SimpleUUID()
 	newStudentNum := rand.Int31n(100)
 	now := time.Now()
-	nowStr := now.Format(time.DateTime + ".000000 +08:00")
 
 	insertExecuteParams, err := raw_sql_tpl.InsertExecuteParams{
 		TableName: tableName,
-		TableRows: []raw_sql_tpl.TableRow{
+		TableRows: []*raw_sql_tpl.TableRow{
 			{
 				Column: "id",
-				Value:  "'" + classID + "'",
+				Value:  classID,
 			},
 			{
 				Column: "name",
-				Value:  "'" + className + "'",
+				Value:  className,
 			},
 			{
 				Column: "student_num",
-				Value:  strconv.FormatInt(int64(studentNum), 10),
+				Value:  studentNum,
 			},
 			{
 				Column: "graduated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "created_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 			{
 				Column: "last_updated_time",
-				Value:  "'" + nowStr + "'",
+				Value:  now,
 			},
 		},
 	}.Map()