25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat: split data type into type+length columns with SearchableSelect, add Shiki SQL highlighting
t8y262b4905e5422
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vueindex 9bd99f65ff..5f9d5ba557 100644--- a/apps/desktop/src/components/structure/TableStructureEditor.vue+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue@@ -28,24 +28,44 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { SearchableSelect } from "@/components/ui/searchable-select";import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";import { useConnectionStore } from "@/stores/connectionStore";+import { useTheme } from "@/composables/useTheme";import { useToast } from "@/composables/useToast";+import { type SqlHighlighter, createShikiSqlHighlighter } from "@/lib/sqlHighlighter";import { type EditableStructureColumn, type EditableStructureIndex } from "@/lib/tableStructureEditorSql";import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities";import {buildStructureTargetLabel,+ combineDataType,createColumnDrafts,createIndexDrafts,+ DATA_TYPE_OPTIONS,+ splitDataType,toColumnNames,} from "@/lib/tableStructureEditorState";import type { ForeignKeyInfo, TriggerInfo } from "@/types/database";import * as api from "@/lib/api";const { t } = useI18n();+const { isDark } = useTheme();const store = useConnectionStore();const { toast } = useToast();+const sqlHighlighter = ref<SqlHighlighter>();+onMounted(async () => {+ sqlHighlighter.value = await createShikiSqlHighlighter({+ appearance: () => (isDark.value ? "dark" : "light"),+ });+});++const highlightedSql = computed(() => {+ if (!pendingStatements.value.length) return "";+ const sql = pendingStatements.value.join("\n");+ return sqlHighlighter.value?.(sql) ?? sql;+});+const props = defineProps<{connectionId: string;database: string;@@ -93,6 +113,7 @@ function onIndexColResize(e: MouseEvent, col: number) {const connection = computed(() => (props.connectionId ? store.getConfig(props.connectionId) : undefined));const databaseType = computed(() => connection.value?.db_type);const structureCapabilities = computed(() => getTableStructureCapabilities(databaseType.value));+const dataTypeOptions = computed(() => DATA_TYPE_OPTIONS[databaseType.value ?? ""] ?? []);const indexTypesByDb: Record<string, string[]> = {postgres: ["BTREE", "HASH", "GIST", "SPGIST", "GIN", "BRIN"],@@ -476,9 +497,12 @@ watch(<th class="min-w-32 border-b border-r px-1.5 py-1.5 text-left">{{ t("structureEditor.columnName") }}</th>- <th class="min-w-36 border-b border-r px-1.5 py-1.5 text-left">+ <th class="min-w-28 border-b border-r px-1.5 py-1.5 text-left">{{ t("structureEditor.dataType") }}</th>+ <th class="min-w-20 border-b border-r px-1.5 py-1.5 text-left">+ {{ t("structureEditor.length") }}+ </th><th class="w-16 whitespace-nowrap border-b border-r px-1.5 py-1.5 text-left">{{ t("structureEditor.nullable") }}</th>@@ -515,11 +539,32 @@ watch(:disabled="isColumnNameDisabled(column)"/></td>+ <td class="border-b border-r px-1.5 py-1">+ <SearchableSelect+ v-if="!isColumnTypeDisabled(column)"+ :model-value="splitDataType(column.dataType).baseType"+ :options="dataTypeOptions"+ :placeholder="t('structureEditor.typePlaceholder')"+ :search-placeholder="t('structureEditor.typePlaceholder')"+ :empty-text="t('structureEditor.noMatchingType')"+ :loading-text="t('common.loading')"+ :allow-custom="true"+ trigger-class="h-6 min-w-24 font-mono text-[11px]"+ @update:model-value="(v: string) => column.dataType = combineDataType(v, splitDataType(column.dataType).params)"+ />+ <Input+ v-else+ :model-value="splitDataType(column.dataType).baseType"+ class="h-6 min-w-24 font-mono text-[11px]"+ disabled+ />+ </td><td class="border-b border-r px-1.5 py-1"><Input- v-model="column.dataType"- class="h-6 min-w-32 font-mono text-[11px]"+ :model-value="splitDataType(column.dataType).params"+ class="h-6 min-w-16 font-mono text-[11px]":disabled="isColumnTypeDisabled(column)"+ @update:model-value="column.dataType = combineDataType(splitDataType(column.dataType).baseType, String($event))"/></td><td class="border-b border-r px-1.5 py-1">@@ -891,8 +936,7 @@ watch(<prev-if="pendingStatements.length"class="whitespace-pre-wrap break-words rounded-md bg-muted/40 p-2 font-mono text-[11px] leading-4"- >{{ pendingStatements.join("\n") }}</pre- >+ v-html="highlightedSql" /><div v-else class="flex h-full items-center justify-center text-sm text-muted-foreground">{{ t("structureEditor.noChanges") }}</div>diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex 752a7aa9c5..1e7f216c48 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -888,6 +888,9 @@ export default {addIndex: "Add Index",columnName: "Column",dataType: "Type",+ typePlaceholder: "Select or type...",+ noMatchingType: "No matching type",+ length: "Length",nullable: "Nullable",primaryKey: "Primary Key",defaultValue: "Default",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex a24df3dd29..ba8fd02224 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -785,6 +785,9 @@ export default {addIndex: "Agregar índice",columnName: "Columna",dataType: "Tipo",+ typePlaceholder: "Seleccionar o escribir...",+ noMatchingType: "Sin coincidencias",+ length: "Longitud",nullable: "Admite nulos",primaryKey: "Clave primaria",defaultValue: "Valor por defecto",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 4a448540ed..6b9e060c7d 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -869,6 +869,9 @@ export default {addIndex: "新增索引",columnName: "字段名",dataType: "类型",+ length: "长度",+ typePlaceholder: "选择或输入...",+ noMatchingType: "无匹配类型",nullable: "可为空",primaryKey: "主键",defaultValue: "默认值",diff --git a/apps/desktop/src/lib/sqlHighlighter.ts b/apps/desktop/src/lib/sqlHighlighter.tsnew file mode 100644index 0000000000..3a9b32171f--- /dev/null+++ b/apps/desktop/src/lib/sqlHighlighter.ts@@ -0,0 +1,55 @@+import type { AppThemeAppearance } from "@/lib/appTheme";++export type SqlHighlighter = (content: string, appearance?: AppThemeAppearance) => string;++interface ShikiSqlHighlighterOptions {+ appearance: () => AppThemeAppearance;+}++const SHIKI_THEMES = {+ dark: "github-dark",+ light: "github-light",+} as const;++type ShikiHighlighter = Awaited<ReturnType<typeof import("shiki/core").createHighlighterCore>>;++let highlighterPromise: Promise<ShikiHighlighter> | undefined;++export async function createShikiSqlHighlighter(+ options: ShikiSqlHighlighterOptions,+): Promise<SqlHighlighter> {+ const highlighter = await getShikiSqlHighlighter();+ return (content, appearance = options.appearance()) =>+ highlighter.codeToHtml(content, {+ lang: "sql",+ structure: "inline",+ theme: SHIKI_THEMES[appearance],+ });+}++function getShikiSqlHighlighter(): Promise<ShikiHighlighter> {+ highlighterPromise ??= loadShikiSqlHighlighter();+ return highlighterPromise;+}++async function loadShikiSqlHighlighter(): Promise<ShikiHighlighter> {+ const [+ { createHighlighterCore },+ { createJavaScriptRegexEngine },+ githubDark,+ githubLight,+ sql,+ ] = await Promise.all([+ import("shiki/core"),+ import("shiki/engine/javascript"),+ import("shiki/themes/github-dark.mjs"),+ import("shiki/themes/github-light.mjs"),+ import("shiki/langs/sql.mjs"),+ ]);++ return createHighlighterCore({+ engine: createJavaScriptRegexEngine(),+ langs: [sql.default],+ themes: [githubDark.default, githubLight.default],+ });+}diff --git a/apps/desktop/src/lib/tableStructureEditorState.ts b/apps/desktop/src/lib/tableStructureEditorState.tsindex 011b9707dc..0b538decaf 100644--- a/apps/desktop/src/lib/tableStructureEditorState.ts+++ b/apps/desktop/src/lib/tableStructureEditorState.ts@@ -1,6 +1,79 @@import type { ColumnInfo, IndexInfo } from "../types/database.ts";import type { EditableStructureColumn, EditableStructureIndex } from "./tableStructureEditorSql.ts";+export const DATA_TYPE_OPTIONS: Record<string, string[]> = {+ mysql: [+ "tinyint", "smallint", "mediumint", "int", "integer", "bigint",+ "float", "double", "double precision", "real",+ "decimal", "numeric",+ "bit", "boolean", "bool", "serial",+ "char", "varchar", "tinytext", "text", "mediumtext", "longtext",+ "binary", "varbinary", "tinyblob", "blob", "mediumblob", "longblob",+ "enum", "set",+ "date", "datetime", "timestamp", "time", "year",+ "json",+ "geometry", "point", "linestring", "polygon", "multipoint", "multilinestring", "multipolygon", "geometrycollection",+ ],+ postgres: [+ "smallint", "int2", "integer", "int", "int4", "bigint", "int8",+ "smallserial", "serial", "bigserial",+ "decimal", "numeric", "real", "float", "float4", "double precision", "float8", "money",+ "boolean", "bool",+ "char", "character", "varchar", "character varying", "text",+ "bytea",+ "date", "time", "time without time zone", "time with time zone", "timetz", "timestamp", "timestamp without time zone", "timestamp with time zone", "timestamptz", "interval",+ "uuid",+ "json", "jsonb", "xml",+ "bit", "bit varying", "varbit",+ "tsvector", "tsquery",+ "cidr", "inet", "macaddr", "macaddr8",+ "point", "line", "lseg", "box", "path", "polygon", "circle",+ "int4range", "int8range", "numrange", "tsrange", "tstzrange", "daterange",+ "oid",+ ],+ sqlite: [+ "integer", "real", "text", "blob", "numeric",+ ],+ sqlserver: [+ "bit",+ "tinyint", "smallint", "int", "integer", "bigint",+ "decimal", "numeric", "float", "real", "money", "smallmoney",+ "char", "nchar", "varchar", "nvarchar", "text", "ntext",+ "date", "time", "datetime", "datetime2", "smalldatetime", "datetimeoffset", "timestamp",+ "binary", "varbinary", "image",+ "uniqueidentifier", "xml", "sql_variant", "hierarchyid",+ "geography", "geometry",+ ],+ oracle: [+ "number", "integer", "float", "binary_float", "binary_double",+ "char", "nchar", "varchar2", "nvarchar2",+ "clob", "nclob", "long",+ "date", "timestamp", "timestamp with time zone", "timestamp with local time zone",+ "interval year to month", "interval day to second",+ "raw", "long raw", "blob", "bfile",+ "boolean", "json", "vector",+ "rowid", "urowid",+ "xmltype", "sdo_geometry",+ ],+ clickhouse: [+ "Int8", "Int16", "Int32", "Int64", "Int128", "Int256",+ "UInt8", "UInt16", "UInt32", "UInt64", "UInt128", "UInt256",+ "Float16", "Float32", "Float64",+ "Decimal", "Decimal32", "Decimal64", "Decimal128", "Decimal256",+ "Bool",+ "String", "FixedString",+ "Date", "Date32", "DateTime", "DateTime64",+ "UUID",+ "IPv4", "IPv6",+ "Enum8", "Enum16",+ "Array", "Map", "Tuple", "Nested",+ "Nullable", "LowCardinality",+ "SimpleAggregateFunction", "AggregateFunction",+ "Point", "Ring", "Polygon", "MultiPolygon",+ "JSON",+ ],+};+export function createColumnDrafts(columns: ColumnInfo[]): EditableStructureColumn[] {return columns.map((column, index) => ({id: `existing:${column.name}`,@@ -36,6 +109,23 @@ export function toColumnNames(columns: string[]): string {return columns.join(", ");}+export function splitDataType(raw: string): { baseType: string; params: string } {+ const trimmed = raw.trim();+ const parenIdx = trimmed.indexOf("(");+ if (parenIdx === -1) return { baseType: trimmed, params: "" };+ const baseType = trimmed.slice(0, parenIdx).trim();+ const params = trimmed.slice(parenIdx + 1, trimmed.lastIndexOf(")")).trim();+ return { baseType, params };+}++export function combineDataType(baseType: string, params: string): string {+ const type = baseType.trim();+ const p = params.trim();+ if (!type) return "";+ if (!p) return type;+ return `${type}(${p})`;+}+export function buildStructureTargetLabel(connectionName: string | undefined,database: string | undefined,