Skip to content

Commit a0187de

Browse files
tmlx1990yanxin
authored andcommitted
将字段默认值选项改为后端传递。
1 parent 811bb2b commit a0187de

9 files changed

Lines changed: 93 additions & 20 deletions

File tree

chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -503,22 +503,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
503503
)}
504504
{editingConfig?.supportDefaultValue && (
505505
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
506-
<CustomSelect
507-
options={[
508-
{
509-
label: 'EMPTY_STRING',
510-
value: 'EMPTY_STRING',
511-
},
512-
{
513-
label: 'NULL',
514-
value: 'NULL',
515-
},
516-
{
517-
label: 'CURRENT_TIMESTAMP',
518-
value: 'CURRENT_TIMESTAMP',
519-
}
520-
]}
521-
/>
506+
<CustomSelect options={databaseSupportField.defaultValues} />
522507
</Form.Item>
523508
)}
524509
{editingConfig?.supportCharset && (

chat2db-client/src/blocks/DatabaseTableEditor/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface IDatabaseSupportField {
5454
charsets: IOption[];
5555
collations: IOption[];
5656
indexTypes: IOption[];
57+
defaultValues: IOption[];
5758
}
5859

5960
export default memo((props: IProps) => {
@@ -93,6 +94,7 @@ export default memo((props: IProps) => {
9394
charsets: [],
9495
collations: [],
9596
indexTypes: [],
97+
defaultValues: [],
9698
});
9799
const [isLoading, setIsLoading] = useState<boolean>(false);
98100

@@ -148,11 +150,20 @@ export default memo((props: IProps) => {
148150
};
149151
}) || [];
150152

153+
const defaultValues =
154+
res?.defaultValues?.map((i) => {
155+
return {
156+
value: i.defaultValue,
157+
label: i.defaultValue,
158+
};
159+
}) || [];
160+
151161
setDatabaseSupportField({
152162
columnTypes,
153163
charsets,
154164
collations,
155165
indexTypes,
166+
defaultValues,
156167
});
157168
});
158169
}

chat2db-client/src/typings/database.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface IDatabaseSupportField {
5151
charsets: ICharset[];
5252
collations: ICollation[];
5353
indexTypes: IIndexTypes[];
54+
defaultValues: IDefaultValue[];
5455
}
5556

5657
/** 字段所对应的 字符集*/
@@ -84,3 +85,8 @@ export interface IColumnTypes {
8485
supportValue: boolean; // 是否支持值
8586
supportUnit: boolean; // 是否支持单位
8687
}
88+
89+
/** 不同数据库支持不同的默认值 */
90+
export interface IDefaultValue {
91+
defaultValue: string; // 默认值
92+
}

chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import java.util.stream.Stream;
99

1010
import ai.chat2db.plugin.mysql.builder.MysqlSqlBuilder;
11-
import ai.chat2db.plugin.mysql.type.MysqlCharsetEnum;
12-
import ai.chat2db.plugin.mysql.type.MysqlCollationEnum;
13-
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
14-
import ai.chat2db.plugin.mysql.type.MysqlIndexTypeEnum;
11+
import ai.chat2db.plugin.mysql.type.*;
1512
import ai.chat2db.spi.MetaData;
1613
import ai.chat2db.spi.SqlBuilder;
1714
import ai.chat2db.spi.jdbc.DefaultMetaService;
@@ -287,6 +284,7 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab
287284
.charsets(MysqlCharsetEnum.getCharsets())
288285
.collations(MysqlCollationEnum.getCollations())
289286
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
287+
.defaultValues(MysqlDefaultValueEnum.getDefaultValues())
290288
.build();
291289
}
292290

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ai.chat2db.plugin.mysql.type;
2+
3+
import ai.chat2db.spi.model.DefaultValue;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
public enum MysqlDefaultValueEnum {
9+
10+
EMPTY_STRING("EMPTY_STRING"),
11+
NULL("NULL"),
12+
CURRENT_TIMESTAMP("CURRENT_TIMESTAMP"),
13+
;
14+
private DefaultValue defaultValue;
15+
16+
MysqlDefaultValueEnum(String defaultValue) {
17+
this.defaultValue = new DefaultValue(defaultValue);
18+
}
19+
20+
21+
public DefaultValue getDefaultValue() {
22+
return defaultValue;
23+
}
24+
25+
public static List<DefaultValue> getDefaultValues() {
26+
return Arrays.stream(MysqlDefaultValueEnum.values()).map(MysqlDefaultValueEnum::getDefaultValue).collect(java.util.stream.Collectors.toList());
27+
}
28+
29+
}

chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import ai.chat2db.plugin.oracle.builder.OracleSqlBuilder;
1010
import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum;
11+
import ai.chat2db.plugin.oracle.type.OracleDefaultValueEnum;
1112
import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum;
1213
import ai.chat2db.spi.MetaData;
1314
import ai.chat2db.spi.SqlBuilder;
@@ -290,6 +291,7 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab
290291
.charsets(Lists.newArrayList())
291292
.collations(Lists.newArrayList())
292293
.indexTypes(OracleIndexTypeEnum.getIndexTypes())
294+
.defaultValues(OracleDefaultValueEnum.getDefaultValues())
293295
.build();
294296
}
295297

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ai.chat2db.plugin.oracle.type;
2+
3+
import ai.chat2db.spi.model.DefaultValue;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
public enum OracleDefaultValueEnum {
9+
10+
EMPTY_STRING("EMPTY_STRING"),
11+
NULL("NULL"),
12+
;
13+
private DefaultValue defaultValue;
14+
15+
OracleDefaultValueEnum(String defaultValue) {
16+
this.defaultValue = new DefaultValue(defaultValue);
17+
}
18+
19+
20+
public DefaultValue getDefaultValue() {
21+
return defaultValue;
22+
}
23+
24+
public static List<DefaultValue> getDefaultValues() {
25+
return Arrays.stream(OracleDefaultValueEnum.values()).map(OracleDefaultValueEnum::getDefaultValue).collect(java.util.stream.Collectors.toList());
26+
}
27+
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ai.chat2db.spi.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
6+
@Data
7+
@AllArgsConstructor
8+
public class DefaultValue {
9+
10+
private String defaultValue;
11+
12+
}

chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableMeta.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public class TableMeta {
1919

2020

2121
private List<IndexType> indexTypes;
22+
23+
private List<DefaultValue> defaultValues;
2224
}

0 commit comments

Comments
 (0)