Skip to content

Commit

Permalink
fix query when table not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Lefebvre committed Nov 21, 2023
1 parent 378765f commit 8f2d577
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/clickhouse/makeQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ export interface Query<T> {
}

export async function makeQuery<T = unknown>(query: string) {
const response = await client.query({ query })
const data: Query<T> = await response.json();
prometheus.query.inc();
prometheus.bytes_read.inc(data.statistics.bytes_read);
prometheus.rows_read.inc(data.statistics.rows_read);
prometheus.elapsed.inc(data.statistics.elapsed);
logger.info({ query, statistics: data.statistics, rows: data.rows });
return data;
try {
const response = await client.query({ query })
const data: Query<T> = await response.json();
prometheus.query.inc();
prometheus.bytes_read.inc(data.statistics.bytes_read);
prometheus.rows_read.inc(data.statistics.rows_read);
prometheus.elapsed.inc(data.statistics.elapsed);
logger.info({ query, statistics: data.statistics, rows: data.rows });
return data;
} catch (e: any) {

console.error(e.message)
return { data: [] }
}

}
2 changes: 2 additions & 0 deletions src/fetch/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const timestampExamplesArrayFilter = ["greater_or_equals_by_timestamp", "greater
const blockExamplesArrayFilter = ["greater_or_equals_by_block", "greater_by_block", "less_or_equals_by_block", "less_by_block"];
const amountExamplesArrayFilter = ["amount_greater_or_equals", "amount_greater", "amount_less_or_equals", "amount_less"];



const chains = await supportedChainsQuery();
const supply_example = (await makeQuery(await getTotalSupply(new URLSearchParams({ limit: "2" }), true))).data;
const contract_example = (await makeQuery(await getContracts(new URLSearchParams({ limit: "2" }), true))).data;
Expand Down
1 change: 0 additions & 1 deletion src/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
addTimestampBlockFilter,
getHolders,
getTransfers,
getApprovals,
addAmountFilter,
} from "./queries.js";

Expand Down

0 comments on commit 8f2d577

Please sign in to comment.