将字段默认值选项改为后端传递。

This commit is contained in:
tmlx1990
2023-11-13 18:23:41 +08:00
committed by yanxin
parent 811bb2be03
commit a0187de02d
9 changed files with 93 additions and 20 deletions

View File

@ -503,22 +503,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
)}
{editingConfig?.supportDefaultValue && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
<CustomSelect
options={[
{
label: 'EMPTY_STRING',
value: 'EMPTY_STRING',
},
{
label: 'NULL',
value: 'NULL',
},
{
label: 'CURRENT_TIMESTAMP',
value: 'CURRENT_TIMESTAMP',
}
]}
/>
<CustomSelect options={databaseSupportField.defaultValues} />
</Form.Item>
)}
{editingConfig?.supportCharset && (

View File

@ -54,6 +54,7 @@ export interface IDatabaseSupportField {
charsets: IOption[];
collations: IOption[];
indexTypes: IOption[];
defaultValues: IOption[];
}
export default memo((props: IProps) => {
@ -93,6 +94,7 @@ export default memo((props: IProps) => {
charsets: [],
collations: [],
indexTypes: [],
defaultValues: [],
});
const [isLoading, setIsLoading] = useState<boolean>(false);
@ -148,11 +150,20 @@ export default memo((props: IProps) => {
};
}) || [];
const defaultValues =
res?.defaultValues?.map((i) => {
return {
value: i.defaultValue,
label: i.defaultValue,
};
}) || [];
setDatabaseSupportField({
columnTypes,
charsets,
collations,
indexTypes,
defaultValues,
});
});
}

View File

@ -51,6 +51,7 @@ export interface IDatabaseSupportField {
charsets: ICharset[];
collations: ICollation[];
indexTypes: IIndexTypes[];
defaultValues: IDefaultValue[];
}
/** 字段所对应的 字符集*/
@ -84,3 +85,8 @@ export interface IColumnTypes {
supportValue: boolean; // 是否支持值
supportUnit: boolean; // 是否支持单位
}
/** 不同数据库支持不同的默认值 */
export interface IDefaultValue {
defaultValue: string; // 默认值
}

View File

@ -8,10 +8,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
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.plugin.mysql.type.MysqlIndexTypeEnum;
import ai.chat2db.plugin.mysql.type.*;
import ai.chat2db.spi.MetaData;
import ai.chat2db.spi.SqlBuilder;
import ai.chat2db.spi.jdbc.DefaultMetaService;
@ -287,6 +284,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
.charsets(MysqlCharsetEnum.getCharsets())
.collations(MysqlCollationEnum.getCollations())
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
.defaultValues(MysqlDefaultValueEnum.getDefaultValues())
.build();
}

View File

@ -0,0 +1,29 @@
package ai.chat2db.plugin.mysql.type;
import ai.chat2db.spi.model.DefaultValue;
import java.util.Arrays;
import java.util.List;
public enum MysqlDefaultValueEnum {
EMPTY_STRING("EMPTY_STRING"),
NULL("NULL"),
CURRENT_TIMESTAMP("CURRENT_TIMESTAMP"),
;
private DefaultValue defaultValue;
MysqlDefaultValueEnum(String defaultValue) {
this.defaultValue = new DefaultValue(defaultValue);
}
public DefaultValue getDefaultValue() {
return defaultValue;
}
public static List<DefaultValue> getDefaultValues() {
return Arrays.stream(MysqlDefaultValueEnum.values()).map(MysqlDefaultValueEnum::getDefaultValue).collect(java.util.stream.Collectors.toList());
}
}

View File

@ -8,6 +8,7 @@ import java.util.stream.Collectors;
import ai.chat2db.plugin.oracle.builder.OracleSqlBuilder;
import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum;
import ai.chat2db.plugin.oracle.type.OracleDefaultValueEnum;
import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum;
import ai.chat2db.spi.MetaData;
import ai.chat2db.spi.SqlBuilder;
@ -290,6 +291,7 @@ public class OracleMetaData extends DefaultMetaService implements MetaData {
.charsets(Lists.newArrayList())
.collations(Lists.newArrayList())
.indexTypes(OracleIndexTypeEnum.getIndexTypes())
.defaultValues(OracleDefaultValueEnum.getDefaultValues())
.build();
}

View File

@ -0,0 +1,28 @@
package ai.chat2db.plugin.oracle.type;
import ai.chat2db.spi.model.DefaultValue;
import java.util.Arrays;
import java.util.List;
public enum OracleDefaultValueEnum {
EMPTY_STRING("EMPTY_STRING"),
NULL("NULL"),
;
private DefaultValue defaultValue;
OracleDefaultValueEnum(String defaultValue) {
this.defaultValue = new DefaultValue(defaultValue);
}
public DefaultValue getDefaultValue() {
return defaultValue;
}
public static List<DefaultValue> getDefaultValues() {
return Arrays.stream(OracleDefaultValueEnum.values()).map(OracleDefaultValueEnum::getDefaultValue).collect(java.util.stream.Collectors.toList());
}
}

View File

@ -0,0 +1,12 @@
package ai.chat2db.spi.model;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class DefaultValue {
private String defaultValue;
}

View File

@ -19,4 +19,6 @@ public class TableMeta {
private List<IndexType> indexTypes;
private List<DefaultValue> defaultValues;
}