Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(grid): pad short timestamp fractions

李子凡2c5f926bd897
diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
index 742414768c..1673c450ec 100644
--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
@@ -31,6 +31,36 @@ describe("dataGridCellDisplayText", () => {
}),
).toBeUndefined();
});
+
+ it.each([
+ ["2026-08-28 12:34:56.1", "2026-08-28 12:34:56.100"],
+ ["2026-08-28 12:34:56.12+08:00", "2026-08-28 12:34:56.120+08:00"],
+ ])("pads short timestamp fractions for display", (value, expected) => {
+ expect(
+ dataGridCellDisplayText({
+ value,
+ databaseType: "mysql",
+ columnInfo: { data_type: "timestamp" },
+ }),
+ ).toBe(expected);
+ });
+
+ it("leaves full-precision and non-timestamp values unchanged", () => {
+ expect(
+ dataGridCellDisplayText({
+ value: "2026-08-28 12:34:56.1234",
+ databaseType: "mysql",
+ columnInfo: { data_type: "timestamp(6)" },
+ }),
+ ).toBeUndefined();
+ expect(
+ dataGridCellDisplayText({
+ value: "2026-08-28 12:34:56.1",
+ databaseType: "mysql",
+ columnInfo: { data_type: "varchar(64)" },
+ }),
+ ).toBeUndefined();
+ });
});
describe("coerceDataGridCellValue", () => {
diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
index f5518bbb05..c41580ffa6 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
@@ -93,12 +93,22 @@ export function dataGridCellDisplayText(options: { value: GridCellValue; databas
if (Array.isArray(options.value) && options.databaseType === "postgres" && isPostgresArrayColumn(options.columnInfo, options.value)) {
return formatPostgresArrayText(options.value);
}
+ if (typeof options.value === "string") {
+ const timestampDisplay = normalizeTimestampFractionDisplayText(options.value, options.columnInfo?.data_type);
+ if (timestampDisplay !== options.value) return timestampDisplay;
+ }
if (typeof options.value === "string" && isOracleDateColumn(options.databaseType, options.columnInfo)) {
return formatOracleDateDisplayText(options.value);
}
return undefined;
}
+function normalizeTimestampFractionDisplayText(value: string, dataType: string | undefined): string {
+ if (!/^timestamp(?:\s*\([^)]*\))?(?:\s+(?:with|without)\s+time\s+zone)?$/i.test(dataType?.trim() ?? "")) return value;
+ const match = value.match(/^(\d{4}[-/]\d{1,2}[-/]\d{1,2}[ T]\d{1,2}:\d{1,2}:\d{1,2})\.(\d{1,2})(Z|[+-]\d{2}:?\d{2})?$/);
+ return match ? `${match[1]}.${match[2].padEnd(3, "0")}${match[3] ?? ""}` : value;
+}
+
function coercePostgresArrayValue(options: CoerceDataGridCellValueOptions): unknown[] | undefined {
if (options.databaseType !== "postgres") return undefined;
if (!isPostgresArrayColumn(options.columnInfo, options.oldValue)) return undefined;