Merge pull request #50 from kingcanfish/fix/numeric-precision-display

fix: resolve PostgreSQL/MySQL/SQL Server NUMERIC/DECIMAL display issues
This commit is contained in:
skyler
2026-05-02 10:36:27 +08:00
committed by GitHub
13 changed files with 62 additions and 20 deletions
+18 -10
View File
@@ -69,7 +69,14 @@ const columnTypeMap = computed(() => {
const map = new Map<string, string>();
if (props.tableMeta?.columns) {
for (const col of props.tableMeta.columns) {
map.set(col.name, shortTypeName(col.data_type));
const typeName = shortTypeName(col.data_type);
// Add precision for numeric/decimal types
if (col.numeric_precision != null && ["numeric", "decimal"].includes(col.data_type.toLowerCase())) {
const scale = col.numeric_scale ?? 0;
map.set(col.name, `${typeName}(${col.numeric_precision},${scale})`);
} else {
map.set(col.name, typeName);
}
}
}
return map;
@@ -103,15 +110,16 @@ function shortTypeName(t: string): string {
}
function typeColorClass(t: string): string {
const s = t.toLowerCase();
if (["int", "int2", "int4", "int8", "smallint", "bigint", "integer", "serial", "bigserial", "tinyint", "mediumint"].includes(s)) return "text-blue-500";
if (["float4", "float8", "double", "decimal", "numeric", "real", "float", "money"].includes(s)) return "text-cyan-500";
if (["varchar", "text", "char", "character varying", "character", "string", "nvarchar", "nchar", "ntext", "longtext", "mediumtext", "tinytext", "clob"].includes(s)) return "text-green-500";
if (["bool", "boolean", "bit"].includes(s)) return "text-orange-500";
if (["timestamp", "timestamptz", "datetime", "date", "time", "timetz", "datetime2", "smalldatetime"].includes(s)) return "text-purple-500";
if (["json", "jsonb", "xml", "array"].includes(s)) return "text-pink-500";
if (["uuid", "uniqueidentifier"].includes(s)) return "text-amber-500";
if (["bytea", "blob", "binary", "varbinary", "image"].includes(s)) return "text-red-400";
// Strip precision/scale suffix like (20,6)
const base = t.replace(/\(.*\)$/, "").toLowerCase();
if (["int", "int2", "int4", "int8", "smallint", "bigint", "integer", "serial", "bigserial", "tinyint", "mediumint"].includes(base)) return "text-blue-500";
if (["float4", "float8", "double", "decimal", "numeric", "real", "float", "money"].includes(base)) return "text-cyan-500";
if (["varchar", "text", "char", "character varying", "character", "string", "nvarchar", "nchar", "ntext", "longtext", "mediumtext", "tinytext", "clob"].includes(base)) return "text-green-500";
if (["bool", "boolean", "bit"].includes(base)) return "text-orange-500";
if (["timestamp", "timestamptz", "datetime", "date", "time", "timetz", "datetime2", "smalldatetime"].includes(base)) return "text-purple-500";
if (["json", "jsonb", "xml", "array"].includes(base)) return "text-pink-500";
if (["uuid", "uniqueidentifier"].includes(base)) return "text-amber-500";
if (["bytea", "blob", "binary", "varbinary", "image"].includes(base)) return "text-red-400";
return "text-muted-foreground";
}
const contextCell = ref<{ rowId: number; rowIndex: number; col: number } | null>(null);
+2
View File
@@ -41,6 +41,8 @@ export interface ColumnInfo {
is_primary_key: boolean;
extra: string | null;
comment?: string | null;
numeric_precision?: number | null;
numeric_scale?: number | null;
}
export interface IndexInfo {