update clickhouse
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
16b391797d
commit
1b8e3d31db
@@ -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:*",
|
||||
|
||||
@@ -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]:
|
||||
|
||||
15
pnpm-lock.yaml
generated
15
pnpm-lock.yaml
generated
@@ -813,8 +813,8 @@ importers:
|
||||
specifier: ^4.29.7
|
||||
version: 4.29.7(next@14.2.1)(react-dom@18.2.0)(react@18.2.0)
|
||||
'@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/client-common@1.0.1:
|
||||
resolution: {integrity: sha512-3L6e0foP6VOktScoi6XWMjJyOpKCWgLUYgPVxP2c7gm6Kotq+iRmmmXtXTSg7B7uozcLZycTtPfIw2d80SYsYw==}
|
||||
dev: false
|
||||
|
||||
/@clickhouse/client@0.2.9:
|
||||
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/client@1.0.1:
|
||||
resolution: {integrity: sha512-fluUNnE2R7COJ6rn6DorYfi4D+AQn3t2qeBtEq37bQV3pD4EbKrBfKAwJ13e1lmMWdQ2B9bJUTMqGsRIDdWhJw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@clickhouse/client-common': 1.0.1
|
||||
dev: false
|
||||
|
||||
/@emnapi/runtime@0.45.0:
|
||||
resolution: {integrity: sha512-Txumi3td7J4A/xTTwlssKieHKTGl3j4A1tglBx72auZ49YK7ePY6XZricgIg9mnZT4xPfA+UPCUdnhRuEFDL+w==}
|
||||
requiresBuild: true
|
||||
|
||||
Reference in New Issue
Block a user