mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 02:32:33 +08:00
Supports fuzzy query of table names, not case sensitive.
Automatically add pagination parameters when users query SQL without pagination parameters. Sort the database schema and prioritize the user-defined ones.
This commit is contained in:
@ -5,6 +5,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import ai.chat2db.plugin.mysql.builder.MysqlSqlBuilder;
|
||||
import ai.chat2db.plugin.mysql.type.MysqlCharsetEnum;
|
||||
@ -17,9 +18,21 @@ import ai.chat2db.spi.jdbc.DefaultMetaService;
|
||||
import ai.chat2db.spi.model.*;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import static ai.chat2db.spi.util.SortUtils.sortDatabase;
|
||||
|
||||
public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
|
||||
private List<String> systemDatabases = Arrays.asList("information_schema", "performance_schema", "mysql", "sys");
|
||||
@Override
|
||||
public List<Database> databases(Connection connection) {
|
||||
List<Database> databases = SQLExecutor.getInstance().databases(connection);
|
||||
return sortDatabase(databases,systemDatabases,connection);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName,
|
||||
@NotEmpty String tableName) {
|
||||
|
@ -104,4 +104,22 @@ public class MysqlSqlBuilder implements SqlBuilder {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String pageLimit(String sql, int offset, int pageNo, int pageSize) {
|
||||
StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
|
||||
sqlBuilder.append(sql);
|
||||
if (offset == 0) {
|
||||
sqlBuilder.append("\n LIMIT ");
|
||||
sqlBuilder.append(pageSize);
|
||||
} else {
|
||||
sqlBuilder.append("\n LIMIT ");
|
||||
sqlBuilder.append(offset);
|
||||
sqlBuilder.append(",");
|
||||
sqlBuilder.append(pageSize);
|
||||
}
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user