mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-31 11:42:41 +08:00
support table edit
This commit is contained in:
@ -18,14 +18,20 @@ public class MysqlSqlBuilder implements SqlBuilder {
|
||||
|
||||
// append column
|
||||
for (TableColumn column : table.getColumnList()) {
|
||||
if(StringUtils.isBlank(column.getName())|| StringUtils.isBlank(column.getColumnType())){
|
||||
continue;
|
||||
}
|
||||
MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(column.getColumnType());
|
||||
script.append("\t").append(typeEnum.buildCreateColumnSql(column)).append(",\n");
|
||||
}
|
||||
|
||||
// append primary key and index
|
||||
for (TableIndex tableIndex : table.getIndexList()) {
|
||||
if(StringUtils.isBlank(tableIndex.getName())|| StringUtils.isBlank(tableIndex.getType())){
|
||||
continue;
|
||||
}
|
||||
MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType());
|
||||
script.append("\t").append("ADD ").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n");
|
||||
script.append("\t").append("").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n");
|
||||
}
|
||||
|
||||
script = new StringBuilder(script.substring(0, script.length() - 2));
|
||||
@ -84,7 +90,7 @@ public class MysqlSqlBuilder implements SqlBuilder {
|
||||
|
||||
// append modify index
|
||||
for (TableIndex tableIndex : newTable.getIndexList()) {
|
||||
if (StringUtils.isNotBlank(tableIndex.getEditStatus())) {
|
||||
if (StringUtils.isNotBlank(tableIndex.getEditStatus()) && StringUtils.isNotBlank(tableIndex.getType())) {
|
||||
MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType());
|
||||
script.append("\t").append(mysqlIndexTypeEnum.buildModifyIndex(tableIndex)).append(",\n");
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ public enum MysqlIndexTypeEnum {
|
||||
|
||||
PRIMARY_KEY("Primary", "PRIMARY KEY"),
|
||||
|
||||
NORMAL("Normal", "KEY"),
|
||||
NORMAL("Normal", "INDEX"),
|
||||
|
||||
UNIQUE("Unique", "UNIQUE KEY"),
|
||||
UNIQUE("Unique", "UNIQUE INDEX"),
|
||||
|
||||
FULLTEXT("Fulltext", "FULLTEXT KEY"),
|
||||
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
|
||||
|
||||
SPATIAL("Spatial", "SPATIAL KEY");
|
||||
SPATIAL("Spatial", "SPATIAL INDEX");
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -72,7 +72,9 @@ public enum MysqlIndexTypeEnum {
|
||||
StringBuilder script = new StringBuilder();
|
||||
script.append("(");
|
||||
for (TableIndexColumn column : tableIndex.getColumnList()) {
|
||||
script.append("`").append(column.getColumnName()).append("`").append(",");
|
||||
if(StringUtils.isNotBlank(column.getColumnName())) {
|
||||
script.append("`").append(column.getColumnName()).append("`").append(",");
|
||||
}
|
||||
}
|
||||
script.deleteCharAt(script.length() - 1);
|
||||
script.append(")");
|
||||
@ -104,6 +106,6 @@ public enum MysqlIndexTypeEnum {
|
||||
if (MysqlIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
|
||||
return StringUtils.join("DROP PRIMARY KEY");
|
||||
}
|
||||
return StringUtils.join("DROP KEY `", tableIndex.getOldName());
|
||||
return StringUtils.join("DROP INDEX `", tableIndex.getOldName());
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package ai.chat2db.server.web.api.controller.rdb.request;
|
||||
import java.util.List;
|
||||
|
||||
import ai.chat2db.spi.enums.IndexTypeEnum;
|
||||
import ai.chat2db.server.web.api.controller.rdb.vo.ColumnVO;
|
||||
|
||||
import ai.chat2db.spi.model.TableIndexColumn;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -41,5 +41,9 @@ public class IndexRequest {
|
||||
/**
|
||||
* 索引包含的列
|
||||
*/
|
||||
private List<ColumnVO> columnList;
|
||||
private List<TableIndexColumn> columnList;
|
||||
|
||||
|
||||
private String editStatus;
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ai.chat2db.server.web.api.controller.rdb.request;
|
||||
import java.util.List;
|
||||
|
||||
import ai.chat2db.spi.model.TableColumn;
|
||||
import ai.chat2db.spi.model.TableIndex;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -36,5 +37,19 @@ public class TableRequest {
|
||||
/**
|
||||
* 索引
|
||||
*/
|
||||
private List<IndexRequest> indexList;
|
||||
private List<TableIndex> indexList;
|
||||
|
||||
|
||||
private String engine;
|
||||
|
||||
|
||||
private String charset;
|
||||
|
||||
|
||||
private String collate;
|
||||
|
||||
private Long incrementValue;
|
||||
|
||||
private String partition;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user