Spaces:
Sleeping
Sleeping
Download apps/api/src/lib/clickhouse-client.ts from s-eto-hub/firecrawl-api: direct link, hf CLI and curl.
- Browser
- Download file 824 Bytes
-
https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/lib/clickhouse-client.ts
- Command line
-
hf download hf://spaces/s-eto-hub/firecrawl-api/apps/api/src/lib/clickhouse-client.ts
-
curl -L -o clickhouse-client.ts https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/lib/clickhouse-client.ts
824 Bytes
| import { createClient } from "@clickhouse/client"; | |
| import { config } from "../config"; | |
| import { logger } from "./logger"; | |
| const client = config.CLICKHOUSE_ANALYTICS_URL | |
| ? createClient({ | |
| url: config.CLICKHOUSE_ANALYTICS_URL, | |
| database: config.CLICKHOUSE_ANALYTICS_DATABASE ?? "default", | |
| clickhouse_settings: { | |
| async_insert: 1, | |
| wait_for_async_insert: 0, | |
| }, | |
| }) | |
| : null; | |
| export async function chInsert( | |
| table: string, | |
| rows: Record<string, unknown>[], | |
| ): Promise<void> { | |
| if (!client || rows.length === 0) return; | |
| try { | |
| await client.insert({ | |
| table, | |
| values: rows, | |
| format: "JSONEachRow", | |
| }); | |
| } catch (error: any) { | |
| logger.error("ClickHouse insert failed", { | |
| table, | |
| rowCount: rows.length, | |
| error: error?.message, | |
| }); | |
| } | |
| } | |