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): count influxdb points across field columns

Conastin160e57bbf4db
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 66838b679b..e16f9d6466 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -135,6 +135,7 @@ import {
shouldIncludeSyntheticRowId,
} from "@/lib/table/tableEditing";
import { buildDataGridConditionalUpdateSql, buildDataGridContextFilterCondition, buildDataGridCountSql, buildHiveTablePropertiesSql, type DataGridContextFilterMode } from "@/lib/dataGrid/dataGridSql";
+import { sumGridCountValues } from "@/lib/dataGrid/dataGridCountValue";
import {
buildVisibleTransposeRows,
averageTransposeRecordWidth,
@@ -4166,7 +4167,8 @@ async function lastPage() {
if (!sql || generation !== manualTotalRowCountGeneration) return;
const result = await api.executeQuery(props.connectionId, props.executionDatabase ?? props.database ?? "", sql, countTarget.schema, undefined, dataGridCountQueryOptions(connectionStore.getConfig(props.connectionId), settingsStore.editorSettings.globalQueryTimeoutSecs));
if (generation !== manualTotalRowCountGeneration) return;
- const total = Number(result.rows?.[0]?.[0] ?? 0);
+ // InfluxQL aggregates return one count per field column with a leading time cell.
+ const total = sumGridCountValues(result.rows?.[0]) ?? 0;
if (!Number.isFinite(total) || total < 0) return;
manualTotalRowCount.value = total;
jumpToCountedLastPage(total);
@@ -4238,7 +4240,8 @@ async function calculateTotalRowCount() {
if (!countTarget?.sql || generation !== manualTotalRowCountGeneration) return;
const result = await api.executeQuery(props.connectionId, props.executionDatabase ?? props.database ?? "", countTarget.sql, countTarget.schema, undefined, dataGridCountQueryOptions(connectionStore.getConfig(props.connectionId), settingsStore.editorSettings.globalQueryTimeoutSecs));
if (generation !== manualTotalRowCountGeneration) return;
- const total = Number(result.rows?.[0]?.[0] ?? 0);
+ // InfluxQL returns zero rows when nothing matches instead of a count of 0.
+ const total = sumGridCountValues(result.rows?.[0]) ?? 0;
if (Number.isFinite(total) && total >= 0) {
manualTotalRowCount.value = total;
}
@@ -9890,8 +9893,8 @@ async function previewConditionalBulkEditMatchCount() {
whereInput,
});
const result = await api.executeQuery(props.connectionId, props.executionDatabase ?? props.database ?? "", sql, undefined, undefined, dataGridCountQueryOptions(connectionStore.getConfig(props.connectionId), settingsStore.editorSettings.globalQueryTimeoutSecs));
- const count = Number(result.rows?.[0]?.[0] ?? 0);
- if (!Number.isFinite(count) || count < 0) throw new Error("Invalid row count returned by the database");
+ const count = sumGridCountValues(result.rows?.[0]);
+ if (count === undefined || count < 0) throw new Error("Invalid row count returned by the database");
if (requestId !== conditionalBulkEditMatchCountRequestId) return;
conditionalBulkEditMatchCount.value = count;
} catch (error: any) {
diff --git a/apps/desktop/src/lib/dataGrid/dataGridCountValue.ts b/apps/desktop/src/lib/dataGrid/dataGridCountValue.ts
new file mode 100644
index 0000000000..f699f2ee22
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/dataGridCountValue.ts
@@ -0,0 +1,10 @@
+import type { CellValue } from "@/lib/dataGrid/cellValue";
+
+export function sumGridCountValues(row: readonly CellValue[] | undefined): number | undefined {
+ let total: number | undefined;
+ for (const value of row ?? []) {
+ if (typeof value === "number" && Number.isFinite(value)) total = (total ?? 0) + value;
+ else if (typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value))) total = (total ?? 0) + Number(value);
+ }
+ return total;
+}
diff --git a/packages/app-tests/dataGridCountValue.test.ts b/packages/app-tests/dataGridCountValue.test.ts
new file mode 100644
index 0000000000..077637b800
--- /dev/null
+++ b/packages/app-tests/dataGridCountValue.test.ts
@@ -0,0 +1,20 @@
+import { strict as assert } from "node:assert";
+import { test } from "vitest";
+import { sumGridCountValues } from "../../apps/desktop/src/lib/dataGrid/dataGridCountValue.ts";
+
+test("sums the per-field counts of an influxql aggregate row", () => {
+ // InfluxQL prefixes aggregate rows with the bucket time and returns one
+ // count per field; the total is the sum of the count columns.
+ assert.equal(sumGridCountValues(["1970-01-01T00:00:00Z", 65052, 62484, 2568]), 130104);
+});
+
+test("reads plain count rows unchanged", () => {
+ assert.equal(sumGridCountValues([42]), 42);
+ assert.equal(sumGridCountValues(["42"]), 42);
+});
+
+test("returns undefined for rows without a count", () => {
+ assert.equal(sumGridCountValues(undefined), undefined);
+ assert.equal(sumGridCountValues([]), undefined);
+ assert.equal(sumGridCountValues([null, ""]), undefined);
+});