Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

update clickhouse

Carl-Gerhard Lindesvärd1b8e3d31dba7
diff --git a/packages/db/package.json b/packages/db/package.json
index a6ab07d0f..4e96ad0c8 100644
--- a/packages/db/package.json
+++ b/packages/db/package.json
@@ -13,7 +13,7 @@
},
"dependencies": {
"@clerk/nextjs": "^4.29.7",
- "@clickhouse/client": "^0.2.9",
+ "@clickhouse/client": "^1.0.1",
"@openpanel/common": "workspace:*",
"@openpanel/constants": "workspace:*",
"@openpanel/redis": "workspace:*",
diff --git a/packages/db/src/clickhouse-client.ts b/packages/db/src/clickhouse-client.ts
index 0bb69c2b2..9a08bccff 100644
--- a/packages/db/src/clickhouse-client.ts
+++ b/packages/db/src/clickhouse-client.ts
@@ -1,33 +1,30 @@
+import type { ResponseJSON } from '@clickhouse/client';
import { createClient } from '@clickhouse/client';
export const ch = createClient({
- host: process.env.CLICKHOUSE_URL,
+ url: process.env.CLICKHOUSE_URL,
username: process.env.CLICKHOUSE_USER,
password: process.env.CLICKHOUSE_PASSWORD,
database: process.env.CLICKHOUSE_DB,
- max_open_connections: 100,
+ max_open_connections: 10,
+ keep_alive: {
+ enabled: true,
+ },
});
-interface ClickhouseJsonResponse<T> {
- data: T[];
- rows: number;
- statistics: { elapsed: number; rows_read: number; bytes_read: number };
- meta: { name: string; type: string }[];
-}
-
export async function chQueryWithMeta<T extends Record<string, any>>(
query: string
-): Promise<ClickhouseJsonResponse<T>> {
+): Promise<ResponseJSON<T>> {
const res = await ch.query({
query,
});
- const json = await res.json<ClickhouseJsonResponse<T>>();
+ const json = await res.json<T>();
return {
...json,
data: json.data.map((item) => {
const keys = Object.keys(item);
return keys.reduce((acc, key) => {
- const meta = json.meta.find((m) => m.name === key);
+ const meta = json.meta?.find((m) => m.name === key);
return {
...acc,
[key]:
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fb0a4b12e..eefa7ebbf 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -813,8 +813,8 @@ importers:
specifier: ^4.29.7
'@clickhouse/client':
- specifier: ^0.2.9
- version: 0.2.9
+ specifier: ^1.0.1
+ version: 1.0.1
'@openpanel/common':
specifier: workspace:*
version: link:../common
@@ -2902,6 +2902,10 @@ packages:
resolution: {integrity: sha512-ecXcegMbT4HYNWtGcfyidW6lNVRqPogbFMY5kfjJmz4IXJ4WZbQMwj2IQgemwFwE7jyia2OEwPIVfw1sNfDHRA==}
dev: false
+ /@clickhouse/[email protected]:
+ resolution: {integrity: sha512-3L6e0foP6VOktScoi6XWMjJyOpKCWgLUYgPVxP2c7gm6Kotq+iRmmmXtXTSg7B7uozcLZycTtPfIw2d80SYsYw==}
+ dev: false
+
/@clickhouse/[email protected]:
resolution: {integrity: sha512-KqQlO9vZNSLyhMWG9+0/VXqcUZrNk1Hybr9icgI/nLCoX8RD19BJsakZJj38IQvQxNUTxvcItm/kyu/gD/9LXA==}
engines: {node: '>=16'}
@@ -2909,6 +2913,13 @@ packages:
'@clickhouse/client-common': 0.2.9
dev: false
+ /@clickhouse/[email protected]:
+ resolution: {integrity: sha512-fluUNnE2R7COJ6rn6DorYfi4D+AQn3t2qeBtEq37bQV3pD4EbKrBfKAwJ13e1lmMWdQ2B9bJUTMqGsRIDdWhJw==}
+ engines: {node: '>=16'}
+ dependencies:
+ '@clickhouse/client-common': 1.0.1
+ dev: false
+
resolution: {integrity: sha512-Txumi3td7J4A/xTTwlssKieHKTGl3j4A1tglBx72auZ49YK7ePY6XZricgIg9mnZT4xPfA+UPCUdnhRuEFDL+w==}
requiresBuild: true