This commit is contained in:
SwallowGG
2023-09-22 14:15:16 +08:00
parent de447e0de3
commit d7e811f4b4
17 changed files with 275 additions and 45 deletions

View File

@ -2,25 +2,26 @@ package ai.chat2db.plugin.mysql;
import java.sql.Connection; import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import ai.chat2db.plugin.mysql.builder.MysqlSqlBuilder; import ai.chat2db.plugin.mysql.builder.MysqlSqlBuilder;
import ai.chat2db.plugin.mysql.type.MysqlCharsetEnum;
import ai.chat2db.plugin.mysql.type.MysqlCollationEnum;
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
import ai.chat2db.spi.MetaData; import ai.chat2db.spi.MetaData;
import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.SqlBuilder;
import ai.chat2db.spi.jdbc.DefaultMetaService; import ai.chat2db.spi.jdbc.DefaultMetaService;
import ai.chat2db.spi.model.Function; import ai.chat2db.spi.model.*;
import ai.chat2db.spi.model.Procedure;
import ai.chat2db.spi.model.Table;
import ai.chat2db.spi.model.Trigger;
import ai.chat2db.spi.sql.SQLExecutor; import ai.chat2db.spi.sql.SQLExecutor;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
public class MysqlMetaData extends DefaultMetaService implements MetaData { public class MysqlMetaData extends DefaultMetaService implements MetaData {
@Override @Override
public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName, public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName,
@NotEmpty String tableName) { @NotEmpty String tableName) {
String sql = "SHOW CREATE TABLE " + format(databaseName) + "." String sql = "SHOW CREATE TABLE " + format(databaseName) + "."
+ format(tableName); + format(tableName);
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
if (resultSet.next()) { if (resultSet.next()) {
return resultSet.getString("Create Table"); return resultSet.getString("Create Table");
@ -34,14 +35,14 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
} }
private static String ROUTINES_SQL private static String ROUTINES_SQL
= =
"SELECT SPECIFIC_NAME, ROUTINE_COMMENT, ROUTINE_DEFINITION FROM information_schema.routines WHERE " "SELECT SPECIFIC_NAME, ROUTINE_COMMENT, ROUTINE_DEFINITION FROM information_schema.routines WHERE "
+ "routine_type = '%s' AND ROUTINE_SCHEMA ='%s' AND " + "routine_type = '%s' AND ROUTINE_SCHEMA ='%s' AND "
+ "routine_name = '%s';"; + "routine_name = '%s';";
@Override @Override
public Function function(Connection connection, @NotEmpty String databaseName, String schemaName, public Function function(Connection connection, @NotEmpty String databaseName, String schemaName,
String functionName) { String functionName) {
String sql = String.format(ROUTINES_SQL, "FUNCTION", databaseName, functionName); String sql = String.format(ROUTINES_SQL, "FUNCTION", databaseName, functionName);
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
@ -60,11 +61,11 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
} }
private static String TRIGGER_SQL private static String TRIGGER_SQL
= "SELECT TRIGGER_NAME,EVENT_MANIPULATION, ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS where " = "SELECT TRIGGER_NAME,EVENT_MANIPULATION, ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS where "
+ "TRIGGER_SCHEMA = '%s' AND TRIGGER_NAME = '%s';"; + "TRIGGER_SCHEMA = '%s' AND TRIGGER_NAME = '%s';";
private static String TRIGGER_SQL_LIST private static String TRIGGER_SQL_LIST
= "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS where TRIGGER_SCHEMA = '%s';"; = "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS where TRIGGER_SCHEMA = '%s';";
@Override @Override
public List<Trigger> triggers(Connection connection, String databaseName, String schemaName) { public List<Trigger> triggers(Connection connection, String databaseName, String schemaName) {
@ -84,7 +85,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
@Override @Override
public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName, public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName,
String triggerName) { String triggerName) {
String sql = String.format(TRIGGER_SQL, databaseName, triggerName); String sql = String.format(TRIGGER_SQL, databaseName, triggerName);
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
@ -101,7 +102,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
@Override @Override
public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName, public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName,
String procedureName) { String procedureName) {
String sql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName); String sql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName);
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
Procedure procedure = new Procedure(); Procedure procedure = new Procedure();
@ -118,8 +119,8 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
} }
private static String VIEW_SQL private static String VIEW_SQL
= "SELECT TABLE_SCHEMA AS DatabaseName, TABLE_NAME AS ViewName, VIEW_DEFINITION AS definition, CHECK_OPTION, " = "SELECT TABLE_SCHEMA AS DatabaseName, TABLE_NAME AS ViewName, VIEW_DEFINITION AS definition, CHECK_OPTION, "
+ "IS_UPDATABLE FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s';"; + "IS_UPDATABLE FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s';";
@Override @Override
public Table view(Connection connection, String databaseName, String schemaName, String viewName) { public Table view(Connection connection, String databaseName, String schemaName, String viewName) {
@ -135,8 +136,18 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
return table; return table;
}); });
} }
@Override @Override
public SqlBuilder getSqlBuilder() { public SqlBuilder getSqlBuilder() {
return new MysqlSqlBuilder(); return new MysqlSqlBuilder();
} }
@Override
public TableMeta getTableMeta(String databaseName, String schemaName, String tableName) {
return TableMeta.builder()
.columnTypes(MysqlColumnTypeEnum.getTypes())
.charsets(MysqlCharsetEnum.getCharsets())
.collations(MysqlCollationEnum.getCollations())
.build();
}
} }

View File

@ -25,7 +25,7 @@ public class MysqlSqlBuilder implements SqlBuilder {
// append primary key and index // append primary key and index
for (TableIndex tableIndex : table.getIndexList()) { for (TableIndex tableIndex : table.getIndexList()) {
MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType()); MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType());
script.append("\t").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n"); script.append("\t").append("ADD ").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n");
} }
script = new StringBuilder(script.substring(0, script.length() - 2)); script = new StringBuilder(script.substring(0, script.length() - 2));

View File

@ -0,0 +1,67 @@
package ai.chat2db.plugin.mysql.type;
import ai.chat2db.spi.model.Charset;
import org.checkerframework.checker.units.qual.C;
import java.util.Arrays;
import java.util.List;
public enum MysqlCharsetEnum {
UTF8("utf8", "utf8_general_ci"),
BIG5("big5", "big5_chinese_ci"),
DEC8("dec8", "dec8_swedish_ci"),
CP850("cp850", "cp850_general_ci"),
HP8("hp8", "hp8_english_ci"),
KOI8R("koi8r", "koi8r_general_ci"),
LATIN1("latin1", "latin1_swedish_ci"),
LATIN2("latin2", "latin2_general_ci"),
SWE7("swe7", "swe7_swedish_ci"),
ASCII("ascii", "ascii_general_ci"),
UJIS("ujis", "ujis_japanese_ci"),
SJIS("sjis", "sjis_japanese_ci"),
HEBREW("hebrew", "hebrew_general_ci"),
TIS620("tis620", "tis620_thai_ci"),
EUCKR("euckr", "euckr_korean_ci"),
KOI8U("koi8u", "koi8u_general_ci"),
GB2312("gb2312", "gb2312_chinese_ci"),
GREEK("greek", "greek_general_ci"),
CP1250("cp1250", "cp1250_general_ci"),
GBK("gbk", "gbk_chinese_ci"),
LATIN5("latin5", "latin5_turkish_ci"),
ARMSCII8("armscii8", "armscii8_general_ci"),
UCS2("ucs2", "ucs2_general_ci"),
CP866("cp866", "cp866_general_ci"),
KEYBCS2("keybcs2", "keybcs2_general_ci"),
MACCE("macce", "macce_general_ci"),
MACROMAN("macroman", "macroman_general_ci"),
CP852("cp852", "cp852_general_ci"),
LATIN7("latin7", "latin7_general_ci"),
UTF8MB4("utf8mb4", "utf8mb4_general_ci"),
CP1251("cp1251", "cp1251_general_ci"),
UTF16("utf16", "utf16_general_ci"),
UTF16LE("utf16le", "utf16le_general_ci"),
CP1256("cp1256", "cp1256_general_ci"),
CP1257("cp1257", "cp1257_general_ci"),
UTF32("utf32", "utf32_general_ci"),
BINARY("binary", "binary"),
GEOSTD8("geostd8", "geostd8_general_ci"),
CP932("cp932", "cp932_japanese_ci"),
EUCJPMS("eucjpms", "eucjpms_japanese_ci"),
GB18030("gb18030", "gb18030_chinese_ci");
private Charset charset;
MysqlCharsetEnum(String charsetName, String defaultCollationName) {
this.charset = new Charset(charsetName, defaultCollationName);
}
public Charset getCharset() {
return charset;
}
public static List<Charset> getCharsets() {
return Arrays.stream(MysqlCharsetEnum.values()).map(MysqlCharsetEnum::getCharset).collect(java.util.stream.Collectors.toList());
}
}

View File

@ -0,0 +1,69 @@
package ai.chat2db.plugin.mysql.type;
import ai.chat2db.spi.model.Collation;
import java.util.Arrays;
import java.util.List;
public enum MysqlCollationEnum {
UTF8_GENERAL_CI("utf8_general_ci"),
UTF8MB4_GENERAL_CI("utf8mb4_general_ci"),
BIG5_CHINESE_CI("big5_chinese_ci"),
DEC8_SWEDISH_CI("dec8_swedish_ci"),
HP8_ENGLISH_CI("hp8_english_ci"),
KOI8R_GENERAL_CI("koi8r_general_ci"),
LATIN1_SWEDISH_CI("latin1_swedish_ci"),
LATIN2_GENERAL_CI("latin2_general_ci"),
SWE7_SWEDISH_CI("swe7_swedish_ci"),
ASCII_GENERAL_CI("ascii_general_ci"),
UJIS_JAPANESE_CI("ujis_japanese_ci"),
SJIS_JAPANESE_CI("sjis_japanese_ci"),
HEBREW_GENERAL_CI("hebrew_general_ci"),
TIS620_THAI_CI("tis620_thai_ci"),
EUCKR_KOREAN_CI("euckr_korean_ci"),
KOI8U_GENERAL_CI("koi8u_general_ci"),
GB2312_CHINESE_CI("gb2312_chinese_ci"),
GREEK_GENERAL_CI("greek_general_ci"),
CP1250_GENERAL_CI("cp1250_general_ci"),
GBK_CHINESE_CI("gbk_chinese_ci"),
LATIN5_TURKISH_CI("latin5_turkish_ci"),
ARMSCII8_GENERAL_CI("armscii8_general_ci"),
CP1250_CZECH_CS("cp1250_czech_cs"),
UCS2_GENERAL_CI("ucs2_general_ci"),
CP866_GENERAL_CI("cp866_general_ci"),
KEYBCS2_GENERAL_CI("keybcs2_general_ci"),
MACCE_GENERAL_CI("macce_general_ci"),
MACROMAN_GENERAL_CI("macroman_general_ci"),
CP852_GENERAL_CI("cp852_general_ci"),
LATIN7_GENERAL_CI("latin7_general_ci"),
CP1251_GENERAL_CI("cp1251_general_ci"),
UTF16_GENERAL_CI("utf16_general_ci"),
UTF16LE_GENERAL_CI("utf16le_general_ci"),
CP1256_GENERAL_CI("cp1256_general_ci"),
CP1257_GENERAL_CI("cp1257_general_ci"),
UTF32_GENERAL_CI("utf32_general_ci"),
BINARY("binary"),
GEOSTD8_GENERAL_CI("geostd8_general_ci"),
CP932_JAPANESE_CI("cp932_japanese_ci"),
EUCJPMS_JAPANESE_CI("eucjpms_japanese_ci"),
GB18030_CHINESE_CI("gb18030_chinese_ci"),
;
private Collation collation;
MysqlCollationEnum(String collationName) {
this.collation = new Collation(collationName);
}
public Collation getCollation() {
return collation;
}
public static List<Collation> getCollations() {
return Arrays.asList(MysqlCollationEnum.values()).stream().map(MysqlCollationEnum::getCollation).collect(java.util.stream.Collectors.toList());
}
}

View File

@ -8,6 +8,7 @@ import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
public enum MysqlColumnTypeEnum implements ColumnBuilder { public enum MysqlColumnTypeEnum implements ColumnBuilder {
@ -131,7 +132,7 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
static { static {
for (MysqlColumnTypeEnum value : MysqlColumnTypeEnum.values()) { for (MysqlColumnTypeEnum value : MysqlColumnTypeEnum.values()) {
COLUMN_TYPE_MAP.put(value.getColumnType().getDataTypeName(), value); COLUMN_TYPE_MAP.put(value.getColumnType().getTypeName(), value);
} }
} }
@ -238,7 +239,7 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
} }
private String buildDataType(TableColumn column, MysqlColumnTypeEnum type) { private String buildDataType(TableColumn column, MysqlColumnTypeEnum type) {
String columnType = type.columnType.getDataTypeName(); String columnType = type.columnType.getTypeName();
if (Arrays.asList(BINARY, VARBINARY, VARCHAR, CHAR).contains(type)) { if (Arrays.asList(BINARY, VARBINARY, VARCHAR, CHAR).contains(type)) {
return StringUtils.join(columnType, "(", column.getColumnSize(), ")"); return StringUtils.join(columnType, "(", column.getColumnSize(), ")");
} }
@ -298,5 +299,11 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
return StringUtils.join(dataTypeName, middle); return StringUtils.join(dataTypeName, middle);
} }
public static List<ColumnType> getTypes(){
return Arrays.stream(MysqlColumnTypeEnum.values()).map(columnTypeEnum ->
columnTypeEnum.getColumnType()
).toList();
}
} }

View File

@ -91,11 +91,11 @@ public enum MysqlIndexTypeEnum {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) { if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex); return buildDropIndex(tableIndex);
} }
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) { if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex)); return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
} }
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) { if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("MODIFY ", buildIndexScript(tableIndex)); return StringUtils.join("ADD ", buildIndexScript(tableIndex));
} }
return ""; return "";
} }

View File

@ -98,4 +98,11 @@ public interface TableService {
* @return * @return
*/ */
List<Type> queryTypes(TypeQueryParam param); List<Type> queryTypes(TypeQueryParam param);
/**
*
* @param param
* @return
*/
TableMeta queryTableMeta(TypeQueryParam param);
} }

View File

@ -159,4 +159,10 @@ public class TableServiceImpl implements TableService {
MetaData metaSchema = Chat2DBContext.getMetaData(); MetaData metaSchema = Chat2DBContext.getMetaData();
return metaSchema.types(Chat2DBContext.getConnection()); return metaSchema.types(Chat2DBContext.getConnection());
} }
@Override
public TableMeta queryTableMeta(TypeQueryParam param) {
MetaData metaSchema = Chat2DBContext.getMetaData();
return metaSchema.getTableMeta(null, null, null);
}
} }

View File

@ -75,8 +75,8 @@ public class RdbDocController {
TableQueryParam param = rdbWebConverter.tableRequest2param(request); TableQueryParam param = rdbWebConverter.tableRequest2param(request);
for (TableVO tableVO: tableVOS) { for (TableVO tableVO: tableVOS) {
param.setTableName(tableVO.getName()); param.setTableName(tableVO.getName());
tableVO.setColumnList(rdbWebConverter.columnDto2vo(tableService.queryColumns(param))); tableVO.setColumnList(tableService.queryColumns(param));
tableVO.setIndexList(rdbWebConverter.indexDto2vo(tableService.queryIndexes(param))); tableVO.setIndexList(tableService.queryIndexes(param));
} }
Class<?> targetClass = ExportServiceFactory.get(exportType.getCode()); Class<?> targetClass = ExportServiceFactory.get(exportType.getCode());
Constructor<?> constructor = targetClass.getDeclaredConstructor(); Constructor<?> constructor = targetClass.getDeclaredConstructor();

View File

@ -1,7 +1,5 @@
package ai.chat2db.server.web.api.controller.rdb; package ai.chat2db.server.web.api.controller.rdb;
import java.util.List;
import ai.chat2db.server.domain.api.param.*; import ai.chat2db.server.domain.api.param.*;
import ai.chat2db.server.domain.api.service.DatabaseService; import ai.chat2db.server.domain.api.service.DatabaseService;
import ai.chat2db.server.domain.api.service.DlTemplateService; import ai.chat2db.server.domain.api.service.DlTemplateService;
@ -18,18 +16,13 @@ import ai.chat2db.server.web.api.controller.rdb.vo.ColumnVO;
import ai.chat2db.server.web.api.controller.rdb.vo.IndexVO; import ai.chat2db.server.web.api.controller.rdb.vo.IndexVO;
import ai.chat2db.server.web.api.controller.rdb.vo.SqlVO; import ai.chat2db.server.web.api.controller.rdb.vo.SqlVO;
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO; import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
import ai.chat2db.spi.model.Table; import ai.chat2db.spi.model.*;
import ai.chat2db.spi.model.TableColumn;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.Type;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ConnectionInfoAspect @ConnectionInfoAspect
@RequestMapping("/api/rdb/table") @RequestMapping("/api/rdb/table")
@ -66,7 +59,7 @@ public class TableController {
return WebPageResult.of(tableVOS, tableDTOPageResult.getTotal(), request.getPageNo(), return WebPageResult.of(tableVOS, tableDTOPageResult.getTotal(), request.getPageNo(),
request.getPageSize()); request.getPageSize());
} }
/** /**
* 查询当前DB下的表columns * 查询当前DB下的表columns
@ -167,7 +160,7 @@ public class TableController {
* @return * @return
*/ */
@PostMapping("/modify/sql") @PostMapping("/modify/sql")
public ListResult<SqlVO> modifySql(@Valid @RequestBody TableModifySqlRequest request) { public ListResult<SqlVO> modifySql(@Valid @RequestBody TableModifySqlRequest request) {
return tableService.buildSql( return tableService.buildSql(
rdbWebConverter.tableRequest2param(request.getOldTable()), rdbWebConverter.tableRequest2param(request.getOldTable()),
rdbWebConverter.tableRequest2param(request.getNewTable())) rdbWebConverter.tableRequest2param(request.getNewTable()))
@ -188,6 +181,14 @@ public class TableController {
return ListResult.of(types); return ListResult.of(types);
} }
@GetMapping("/table_meta")
public DataResult<TableMeta> tableMeta(@Valid TypeQueryRequest request) {
TypeQueryParam typeQueryParam = TypeQueryParam.builder().dataSourceId(request.getDataSourceId()).build();
TableMeta tableMeta = tableService.queryTableMeta(typeQueryParam);
return DataResult.of(tableMeta);
}
/** /**
* 删除表 * 删除表
* *

View File

@ -8,6 +8,9 @@ import ai.chat2db.server.web.api.controller.rdb.vo.ColumnVO;
import ai.chat2db.server.web.api.controller.rdb.vo.IndexVO; import ai.chat2db.server.web.api.controller.rdb.vo.IndexVO;
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO; import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
import ai.chat2db.server.web.api.util.StringUtils; import ai.chat2db.server.web.api.util.StringUtils;
import ai.chat2db.spi.model.TableColumn;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@ -82,13 +85,13 @@ public class DatabaseExportService {
val t = new TableParameter(); val t = new TableParameter();
t.setFieldName(item.getName() + "[" + StringUtils.isNull(item.getComment()) + "]"); t.setFieldName(item.getName() + "[" + StringUtils.isNull(item.getComment()) + "]");
List<TableParameter> colForTable = new LinkedList<>(); List<TableParameter> colForTable = new LinkedList<>();
for (ColumnVO info : item.getColumnList()) { for (TableColumn info : item.getColumnList()) {
val p = new TableParameter(); val p = new TableParameter();
p.setFieldName(info.getName()).setColumnDefault(info.getDefaultValue()) p.setFieldName(info.getName()).setColumnDefault(info.getDefaultValue())
.setColumnComment(info.getComment()) .setColumnComment(info.getComment())
.setColumnType(info.getColumnType()) .setColumnType(info.getColumnType())
.setLength(String.valueOf(info.getCharacterMaximumLength())).setIsNullAble(String.valueOf(info.getNullable())) .setLength(String.valueOf(info.getColumnSize())).setIsNullAble(String.valueOf(info.getNullable()))
.setDecimalPlaces(String.valueOf(info.getNumericPrecision())); .setDecimalPlaces(String.valueOf(info.getDecimalDigits()));
colForTable.add(p); colForTable.add(p);
} }
String key = databaseName + JOINER + t.getFieldName(); String key = databaseName + JOINER + t.getFieldName();
@ -108,11 +111,12 @@ public class DatabaseExportService {
} }
} }
private List<IndexInfo> vo2Info(List<IndexVO> indexList) { private List<IndexInfo> vo2Info(List<TableIndex> indexList) {
return indexList.stream().map(v -> { return indexList.stream().map(v -> {
IndexInfo info = new IndexInfo(); IndexInfo info = new IndexInfo();
info.setName(v.getName()); info.setName(v.getName());
info.setColumnName(v.getColumns()); List<TableIndexColumn> columnList = v.getColumnList();
info.setColumnName(columnList.stream().map(TableIndexColumn::getColumnName).collect(Collectors.joining(",")));
info.setIndexType(v.getType()); info.setIndexType(v.getType());
info.setComment(v.getComment()); info.setComment(v.getComment());
return info; return info;

View File

@ -187,4 +187,14 @@ public interface MetaData {
* @return * @return
*/ */
SqlBuilder getSqlBuilder(); SqlBuilder getSqlBuilder();
/**
*
* @param databaseName
* @param schemaName
* @param tableName
* @return
*/
TableMeta getTableMeta( String databaseName, String schemaName, String tableName);
} }

View File

@ -99,4 +99,9 @@ public class DefaultMetaService implements MetaData {
public SqlBuilder getSqlBuilder() { public SqlBuilder getSqlBuilder() {
return new DefaultSqlBuilder(); return new DefaultSqlBuilder();
} }
@Override
public TableMeta getTableMeta(String databaseName, String schemaName, String tableName) {
return null;
}
} }

View File

@ -0,0 +1,13 @@
package ai.chat2db.spi.model;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Charset {
private String charsetName;
private String defaultCollationName;
}

View File

@ -0,0 +1,11 @@
package ai.chat2db.spi.model;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Collation {
private String collationName;
}

View File

@ -7,7 +7,7 @@ import lombok.Data;
@AllArgsConstructor @AllArgsConstructor
public class ColumnType { public class ColumnType {
private String dataTypeName; private String typeName;
private boolean supportLength; private boolean supportLength;
private boolean supportScale; private boolean supportScale;
private boolean supportNullable; private boolean supportNullable;

View File

@ -0,0 +1,19 @@
package ai.chat2db.spi.model;
import lombok.Builder;
import lombok.Data;
import java.util.List;
@Data
@Builder
public class TableMeta {
private List<ColumnType> columnTypes;
private List<Charset> charsets;
private List<Collation> collations;
}