Skip to content

Commit a067fd3

Browse files
committed
[dev] tests for new rules
1 parent 17a8752 commit a067fd3

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

sql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ func GetSQL(data Filter, config *SQLConfig) (string, []interface{}, error) {
7474
case "greater":
7575
return fmt.Sprintf("%s > ?", data.Field), []interface{}{data.Condition.Value}, nil
7676
case "beginsWith":
77-
search := "concat(?, '%')"
77+
search := "CONCAT(?, '%')"
7878
return fmt.Sprintf("%s LIKE %s", data.Field, search), []interface{}{data.Condition.Value}, nil
7979
case "notBeginsWith":
80-
search := "concat(?, '%')"
80+
search := "CONCAT(?, '%')"
8181
return fmt.Sprintf("%s NOT LIKE %s", data.Field, search), []interface{}{data.Condition.Value}, nil
8282
case "endsWith":
83-
search := "concat('%', ?)"
83+
search := "CONCAT('%', ?)"
8484
return fmt.Sprintf("%s LIKE %s", data.Field, search), []interface{}{data.Condition.Value}, nil
8585
case "notEndsWith":
86-
search := "concat('%', ?)"
86+
search := "CONCAT('%', ?)"
8787
return fmt.Sprintf("%s NOT LIKE %s", data.Field, search), []interface{}{data.Condition.Value}, nil
8888
}
8989

sql_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ var cases = [][]string{
5353
"INSTR(a, ?) < 0",
5454
"1",
5555
},
56+
[]string{
57+
`{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"beginsWith", "filter":"1" }}]}`,
58+
"a LIKE CONCAT(?, '%')",
59+
"1",
60+
},
61+
[]string{
62+
`{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notBeginsWith", "filter":"1" }}]}`,
63+
"a NOT LIKE CONCAT(?, '%')",
64+
"1",
65+
},
66+
[]string{
67+
`{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"endsWith", "filter":"1" }}]}`,
68+
"a LIKE CONCAT('%', ?)",
69+
"1",
70+
},
71+
[]string{
72+
`{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notEndsWith", "filter":"1" }}]}`,
73+
"a NOT LIKE CONCAT('%', ?)",
74+
"1",
75+
},
5676
[]string{
5777
aAndB,
5878
"( a < ? AND b > ? )",

0 commit comments

Comments
 (0)