🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Add processResults
Bill Yang32be9f68b455
diff --git a/client/src/app/actions/getBrowsers.ts b/client/src/app/actions/getBrowsers.tsindex dd24ec463..6e65a4748 100644--- a/client/src/app/actions/getBrowsers.ts+++ b/client/src/app/actions/getBrowsers.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetBrowsersResponse = {browser: string;@@ -35,7 +35,7 @@ export async function getBrowsers({format: "JSONEachRow",});- const data: GetBrowsersResponse = await result.json();+ const data = await processResults<GetBrowsersResponse[number]>(result);return { data };} catch (error) {console.error("Error fetching browsers:", error);diff --git a/client/src/app/actions/getCountries.ts b/client/src/app/actions/getCountries.tsindex 10ef83828..abb1cb6c0 100644--- a/client/src/app/actions/getCountries.ts+++ b/client/src/app/actions/getCountries.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetCountriesResponse = {country: string;@@ -35,7 +35,7 @@ export async function getCountries({format: "JSONEachRow",});- const data: GetCountriesResponse = await result.json();+ const data = await processResults<GetCountriesResponse[number]>(result);return { data };} catch (error) {console.error("Error fetching countries:", error);diff --git a/client/src/app/actions/getDevices.ts b/client/src/app/actions/getDevices.tsindex db185984f..c2ce01efb 100644--- a/client/src/app/actions/getDevices.ts+++ b/client/src/app/actions/getDevices.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetDevicesResponse = {device_type: string;@@ -35,7 +35,7 @@ export async function getDevices({format: "JSONEachRow",});- const data: GetDevicesResponse = await result.json();+ const data = await processResults<GetDevicesResponse[number]>(result);return { data };} catch (error) {console.error("Error fetching devices:", error);diff --git a/client/src/app/actions/getOperatingSystems.ts b/client/src/app/actions/getOperatingSystems.tsindex 60d4a5cce..ac324f8e7 100644--- a/client/src/app/actions/getOperatingSystems.ts+++ b/client/src/app/actions/getOperatingSystems.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetOperatingSystemsResponse = {operating_system: string;@@ -35,7 +35,9 @@ export async function getOperatingSystems({format: "JSONEachRow",});- const data: GetOperatingSystemsResponse = await result.json();+ const data = await processResults<GetOperatingSystemsResponse[number]>(+ result+ );return { data };} catch (error) {console.error("Error fetching operating systems:", error);diff --git a/client/src/app/actions/getPages.ts b/client/src/app/actions/getPages.tsindex 698f07ae8..c98a0fbd2 100644--- a/client/src/app/actions/getPages.ts+++ b/client/src/app/actions/getPages.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetPagesResponse = {pathname: string;@@ -37,7 +37,7 @@ export async function getPages({format: "JSONEachRow",});- const data: GetPagesResponse = await result.json();+ const data = await processResults<GetPagesResponse[number]>(result);return { data };} catch (error) {console.error("Error fetching pages:", error);diff --git a/client/src/app/actions/getReferrers.ts b/client/src/app/actions/getReferrers.tsindex a632049f6..abb5936ce 100644--- a/client/src/app/actions/getReferrers.ts+++ b/client/src/app/actions/getReferrers.ts@@ -1,7 +1,7 @@"use server";import { clickhouse } from "@/lib/clickhouse";-import { getTimeStatement } from "./utils";+import { getTimeStatement, processResults } from "./utils";type GetReferrersResponse = {referrer: string;@@ -37,7 +37,7 @@ export async function getReferrers({format: "JSONEachRow",});- const data: GetReferrersResponse = await result.json();+ const data = await processResults<GetReferrersResponse[number]>(result);return { data };} catch (error) {console.error("Error fetching referrers:", error);diff --git a/client/src/app/actions/utils.ts b/client/src/app/actions/utils.tsindex 217432836..d649e11f6 100644--- a/client/src/app/actions/utils.ts+++ b/client/src/app/actions/utils.ts@@ -1,3 +1,5 @@+import { ResultSet } from "@clickhouse/client";+export function getTimeStatement(startDate: string,endDate: string,@@ -18,3 +20,17 @@ AND timestamp < if()`;}++export async function processResults<T>(+ results: ResultSet<"JSONEachRow">+): Promise<T[]> {+ const data: T[] = await results.json();+ for (const row of data) {+ for (const key in row) {+ if (!isNaN(Number(row[key]))) {+ row[key] = Number(row[key]) as any;+ }+ }+ }+ return data;+}