diff --git a/chat2db-client/src/components/CreateDatabase/index.tsx b/chat2db-client/src/components/CreateDatabase/index.tsx index 665d5b57f..bc532d862 100644 --- a/chat2db-client/src/components/CreateDatabase/index.tsx +++ b/chat2db-client/src/components/CreateDatabase/index.tsx @@ -1,7 +1,7 @@ import React, { useCallback, forwardRef, ForwardedRef, useImperativeHandle, useMemo, useState, useEffect } from 'react'; import styles from './index.less'; import classnames from 'classnames'; -import { Form, Input, Modal } from 'antd'; +import {Form, Input, Modal, Select} from 'antd'; import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor'; import { v4 as uuid } from 'uuid'; import sqlService from '@/service/sql'; @@ -15,6 +15,11 @@ interface IProps { executedCallback?: () => void; } +interface IOption { + label: string; + value: string | number | null; +} + export type CreateType = 'database' | 'schema'; export interface ICreateDatabaseRef { @@ -27,8 +32,14 @@ export interface ICreateDatabase { comment?: string; } +export interface IDatabaseCharsetList { + charsets: IOption[]; +} + // 创建database不支持注释的数据库 const noCommentDatabase = [DatabaseTypeCode.MYSQL]; +// 支持charset的数据库 +const supportCharset = [DatabaseTypeCode.MYSQL]; export default forwardRef((props: IProps, ref: ForwardedRef) => { const { className, curWorkspaceParams, executedCallback } = props; @@ -41,6 +52,9 @@ export default forwardRef((props: IProps, ref: ForwardedRef) ); const [confirmLoading, setConfirmLoading] = useState(false); const [createType, setCreateType] = useState('database'); + const [databaseCharsetList, setDatabaseCharsetList] = useState({ + charsets: [], + }); useEffect(() => { if (!open) { @@ -50,6 +64,33 @@ export default forwardRef((props: IProps, ref: ForwardedRef) } }, [open]); + useEffect(() => { + if (curWorkspaceParams.databaseType && databaseCharsetList.charsets.length === 0) { + getDatabaseCharsetList(); + } + }, [curWorkspaceParams]) + + const initialOption = { + label: '', + value: '', + }; + const getDatabaseCharsetList = () => { + sqlService + .getDatabaseCharsetList(curWorkspaceParams) + .then((res) => { + const charsets = [initialOption, + ...(res?.charsets?.map((i) => { + return { + label: i.charsetName, + value: i.charsetName, + }; + }) || [])]; + setDatabaseCharsetList({ + charsets, + }); + }); + } + const config = useMemo(() => { return createType === 'database' ? { @@ -143,6 +184,15 @@ export default forwardRef((props: IProps, ref: ForwardedRef) + + diff --git a/chat2db-client/src/i18n/en-us/common.ts b/chat2db-client/src/i18n/en-us/common.ts index 2216f71e9..f092d1b4f 100644 --- a/chat2db-client/src/i18n/en-us/common.ts +++ b/chat2db-client/src/i18n/en-us/common.ts @@ -100,6 +100,7 @@ export default { 'common.Button.addSchema': 'Add schema', 'common.label.comment': 'Comment', 'common.label.name': 'Name', + 'common.label.charset': 'Charset', 'common.title.create': 'Create', 'common.title.executiveLogging': 'Executive logging', 'common.text.executionTime': 'Affected in {1} ms', diff --git a/chat2db-client/src/i18n/zh-cn/common.ts b/chat2db-client/src/i18n/zh-cn/common.ts index 3d59bf3c6..a46f2fbec 100644 --- a/chat2db-client/src/i18n/zh-cn/common.ts +++ b/chat2db-client/src/i18n/zh-cn/common.ts @@ -99,6 +99,7 @@ export default { 'common.Button.addSchema': '添加Schema', 'common.label.comment': '备注', 'common.label.name': '名称', + 'common.label.charset': '字符集', 'common.title.create': '创建', 'common.title.executiveLogging': '执行记录', 'common.text.executionTime': '{1}ms 执行完毕', diff --git a/chat2db-client/src/service/sql.ts b/chat2db-client/src/service/sql.ts index 8754246fa..6a1c903a2 100644 --- a/chat2db-client/src/service/sql.ts +++ b/chat2db-client/src/service/sql.ts @@ -301,6 +301,14 @@ const getCreateSchemaSql = createRequest<{ schemaName?: string; }, {sql:string}>('/api/rdb/schema/create_schema_sql', { method: 'post' }); +const getDatabaseCharsetList = createRequest<{ + dataSourceId: number; + databaseName: string; +}, IDatabaseSupportField>( + '/api/rdb/table/table_charset', + { method: 'get' }, +); + export default { getCreateSchemaSql, getCreateDatabaseSql, @@ -339,4 +347,5 @@ export default { // exportResultTable getAllTableList, getAllFieldByTable, + getDatabaseCharsetList, }; diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java index 40a291955..30189959e 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java @@ -297,4 +297,11 @@ public String getMetaDataName(String... names) { public ValueHandler getValueHandler() { return new MysqlValueHandler(); } + + @Override + public TableMeta getTableCharset(String databaseName, String schemaName, String tableName) { + return TableMeta.builder() + .charsets(MysqlCharsetEnum.getCharsets()) + .build(); + } } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java index 93f245af2..45555bbe4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java @@ -129,4 +129,6 @@ public interface TableService { * @return */ DataResult checkTableVector(TableVectorParam param); + + TableMeta queryTableCharset(TypeQueryParam param); } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java index 5fd24c465..60e3de509 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java @@ -577,4 +577,20 @@ public DataResult checkTableVector(TableVectorParam param) { } return DataResult.of(false); } + + @Override + public TableMeta queryTableCharset(TypeQueryParam param) { + MetaData metaSchema = Chat2DBContext.getMetaData(); + TableMeta tableMeta = metaSchema.getTableCharset(null, null, null); + if (tableMeta != null) { + //filter primary key + List indexTypes = tableMeta.getIndexTypes(); + if (CollectionUtils.isNotEmpty(indexTypes)) { + List types = indexTypes.stream().filter(indexType -> !"Primary".equals(indexType.getTypeName())).collect(Collectors.toList()); + tableMeta.setIndexTypes(types); + } + } + return tableMeta; + } + } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java index 131a6bf6c..4148a449f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java @@ -250,4 +250,17 @@ public ActionResult delete(@Valid @RequestBody TableDeleteRequest request) { DropParam dropParam = rdbWebConverter.tableDelete2dropParam(request); return tableService.drop(dropParam); } + + /** + * 数据库支持的字符集 + * @param request + * @return + */ + @GetMapping("/table_charset") + public DataResult tableCharset(@Valid TypeQueryRequest request) { + TypeQueryParam typeQueryParam = TypeQueryParam.builder().dataSourceId(request.getDataSourceId()).build(); + TableMeta tableMeta = tableService.queryTableCharset(typeQueryParam); + return DataResult.of(tableMeta); + } + } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java index 02fab4057..af1aed623 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java @@ -214,4 +214,5 @@ List indexes(Connection connection, @NotEmpty String databaseName, S */ ValueHandler getValueHandler(); + TableMeta getTableCharset(String databaseName, String schemaName, String tableName); } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java index 624814080..6065f027a 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java @@ -136,4 +136,9 @@ public String getMetaDataName(String... names) { public ValueHandler getValueHandler() { return new DefaultValueHandler(); } + + @Override + public TableMeta getTableCharset(String databaseName, String schemaName, String tableName) { + return null; + } } \ No newline at end of file