Skip to content

Commit 0eb82f4

Browse files
committed
Small refactor in query.go regexp
Signed-off-by: Carlos Martín <[email protected]>
1 parent 5d5f2a4 commit 0eb82f4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

server/handler/query.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,15 @@ func columnsInfo(rows *sql.Rows) ([]string, []string, error) {
157157
return names, typesStr, nil
158158
}
159159

160+
var noCommentsRegexp = regexp.MustCompile(`\/\*(?s:.)*?\*\/`)
161+
160162
// addLimit adds LIMIT to the query if it's a SELECT, avoiding '; limit'
161163
func addLimit(query string, limit int) string {
162164
if limit <= 0 {
163165
return query
164166
}
165167

166-
re := regexp.MustCompile(`\/\*(?s:.)*?\*\/`)
167-
noComments := re.ReplaceAllLiteralString(query, "")
168+
noComments := noCommentsRegexp.ReplaceAllLiteralString(query, "")
168169

169170
query = strings.TrimRight(strings.TrimSpace(noComments), ";")
170171
if strings.HasPrefix(strings.ToUpper(query), "SELECT") {

0 commit comments

Comments
 (0)