mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-30 03:03:13 +08:00
将字段默认值选项改为后端传递。
This commit is contained in:
@ -503,22 +503,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
|
|||||||
)}
|
)}
|
||||||
{editingConfig?.supportDefaultValue && (
|
{editingConfig?.supportDefaultValue && (
|
||||||
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
|
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
|
||||||
<CustomSelect
|
<CustomSelect options={databaseSupportField.defaultValues} />
|
||||||
options={[
|
|
||||||
{
|
|
||||||
label: 'EMPTY_STRING',
|
|
||||||
value: 'EMPTY_STRING',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'NULL',
|
|
||||||
value: 'NULL',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'CURRENT_TIMESTAMP',
|
|
||||||
value: 'CURRENT_TIMESTAMP',
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
{editingConfig?.supportCharset && (
|
{editingConfig?.supportCharset && (
|
||||||
|
@ -54,6 +54,7 @@ export interface IDatabaseSupportField {
|
|||||||
charsets: IOption[];
|
charsets: IOption[];
|
||||||
collations: IOption[];
|
collations: IOption[];
|
||||||
indexTypes: IOption[];
|
indexTypes: IOption[];
|
||||||
|
defaultValues: IOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo((props: IProps) => {
|
export default memo((props: IProps) => {
|
||||||
@ -93,6 +94,7 @@ export default memo((props: IProps) => {
|
|||||||
charsets: [],
|
charsets: [],
|
||||||
collations: [],
|
collations: [],
|
||||||
indexTypes: [],
|
indexTypes: [],
|
||||||
|
defaultValues: [],
|
||||||
});
|
});
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
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({
|
setDatabaseSupportField({
|
||||||
columnTypes,
|
columnTypes,
|
||||||
charsets,
|
charsets,
|
||||||
collations,
|
collations,
|
||||||
indexTypes,
|
indexTypes,
|
||||||
|
defaultValues,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ export interface IDatabaseSupportField {
|
|||||||
charsets: ICharset[];
|
charsets: ICharset[];
|
||||||
collations: ICollation[];
|
collations: ICollation[];
|
||||||
indexTypes: IIndexTypes[];
|
indexTypes: IIndexTypes[];
|
||||||
|
defaultValues: IDefaultValue[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 字段所对应的 字符集*/
|
/** 字段所对应的 字符集*/
|
||||||
@ -84,3 +85,8 @@ export interface IColumnTypes {
|
|||||||
supportValue: boolean; // 是否支持值
|
supportValue: boolean; // 是否支持值
|
||||||
supportUnit: boolean; // 是否支持单位
|
supportUnit: boolean; // 是否支持单位
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 不同数据库支持不同的默认值 */
|
||||||
|
export interface IDefaultValue {
|
||||||
|
defaultValue: string; // 默认值
|
||||||
|
}
|
||||||
|
@ -8,10 +8,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
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.*;
|
||||||
import ai.chat2db.plugin.mysql.type.MysqlCollationEnum;
|
|
||||||
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
|
|
||||||
import ai.chat2db.plugin.mysql.type.MysqlIndexTypeEnum;
|
|
||||||
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;
|
||||||
@ -287,6 +284,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
|||||||
.charsets(MysqlCharsetEnum.getCharsets())
|
.charsets(MysqlCharsetEnum.getCharsets())
|
||||||
.collations(MysqlCollationEnum.getCollations())
|
.collations(MysqlCollationEnum.getCollations())
|
||||||
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
|
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
|
||||||
|
.defaultValues(MysqlDefaultValueEnum.getDefaultValues())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import ai.chat2db.plugin.oracle.builder.OracleSqlBuilder;
|
import ai.chat2db.plugin.oracle.builder.OracleSqlBuilder;
|
||||||
import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum;
|
import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum;
|
||||||
|
import ai.chat2db.plugin.oracle.type.OracleDefaultValueEnum;
|
||||||
import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum;
|
import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum;
|
||||||
import ai.chat2db.spi.MetaData;
|
import ai.chat2db.spi.MetaData;
|
||||||
import ai.chat2db.spi.SqlBuilder;
|
import ai.chat2db.spi.SqlBuilder;
|
||||||
@ -290,6 +291,7 @@ public class OracleMetaData extends DefaultMetaService implements MetaData {
|
|||||||
.charsets(Lists.newArrayList())
|
.charsets(Lists.newArrayList())
|
||||||
.collations(Lists.newArrayList())
|
.collations(Lists.newArrayList())
|
||||||
.indexTypes(OracleIndexTypeEnum.getIndexTypes())
|
.indexTypes(OracleIndexTypeEnum.getIndexTypes())
|
||||||
|
.defaultValues(OracleDefaultValueEnum.getDefaultValues())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package ai.chat2db.spi.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DefaultValue {
|
||||||
|
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
}
|
@ -19,4 +19,6 @@ public class TableMeta {
|
|||||||
|
|
||||||
|
|
||||||
private List<IndexType> indexTypes;
|
private List<IndexType> indexTypes;
|
||||||
|
|
||||||
|
private List<DefaultValue> defaultValues;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user