Merge pull request #921 from tmlx1990/fix920

Fix: 920 修改格式化SQL不能解析带注释的SQL的问题
This commit is contained in:
ji
2023-12-07 23:14:11 +08:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@ -97,6 +97,11 @@
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.manticore-projects.jsqlformatter</groupId>
<artifactId>jsqlformatter</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -3,7 +3,7 @@ package ai.chat2db.server.web.api.controller.sql;
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
import ai.chat2db.server.web.api.controller.sql.request.SqlFormatRequest;
import cn.hutool.db.sql.SqlFormatter;
import com.manticore.jsqlformatter.JSQLFormatter;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -19,18 +19,19 @@ public class SqlController {
/**
* SQL Format
*
* @param sqlFormatRequest
* @return
*/
@GetMapping("/format")
public DataResult<String> list(@Valid SqlFormatRequest sqlFormatRequest) {
String sql = sqlFormatRequest.getSql();
try {
sql = SqlFormatter.format(sql);
sql = JSQLFormatter.format(sql);
} catch (Exception e) {
// ignore
}
return DataResult.of(sql);
}
}