From 44891edaab225d18a974ee6befb6a31a12b416a4 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Mon, 23 Sep 2024 15:04:21 -0400 Subject: [PATCH] fix where statement --- index.ts | 7 +++++++ src/usage.ts | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 441f950..fab3690 100644 --- a/index.ts +++ b/index.ts @@ -11,6 +11,13 @@ import { APIErrorResponse } from "./src/utils.js"; import { usageOperationsToEndpointsMap, type EndpointReturnTypes, type UsageEndpoints } from "./src/types/api.js"; import { paths } from './src/types/zod.gen.js'; +await client.ping().then((result) => { + if (!result.success) { + logger.error(`Failed to connect to ClickHouse: ${result.error.message}`); + process.exit(1); + } +}); + async function AntelopeTransactionsAPI() { const app = new Hono(); diff --git a/src/usage.ts b/src/usage.ts index 46fed06..ddcca14 100644 --- a/src/usage.ts +++ b/src/usage.ts @@ -26,7 +26,8 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use for (let key in query_params) { if (["limit", "offset", "order_by", "order_direction", "skip", "first"].includes(key)) continue; // skip pagination params const value = (query_params as any)[key]; - where.push(`${key} = {${key}: ${typeof value === "number" ? "int" : "String"}}`); + let isNumber = !isNaN(Number(value)); + where.push(`"${key}" = {${key}: ${isNumber ? "int" : "String"}}`); } if (where.length) query.push(`WHERE ${where.join(" AND ")}`); @@ -48,4 +49,4 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use } catch (err) { return APIErrorResponse(ctx, 500, "bad_database_response", err); } -} +} \ No newline at end of file