能把sql字符串进行美化,压缩格式化的包?
更多评论
这样?
``` go
func CompressSQL(sqlStatement string) string {
// Remove leading and trailing white spaces
sqlStatement = strings.TrimSpace(sqlStatement)
// Replace multiple spaces and newlines with a single space
sqlStatement = regexp.MustCompile(`\s+`).ReplaceAllString(sqlStatement, " ")
// Remove comments starting with '--' or '/*' and ending with '*/'
sqlStatement = regexp.MustCompile(`--.*$|/\*.*?\*/`).ReplaceAllString(sqlStatement, "")
// Remove unnecessary spaces around parentheses
sqlStatement = regexp.MustCompile(`\s*([(),])\s*`).ReplaceAllString(sqlStatement, "$1")
return sqlStatement
}
```
#2