Skip to content

Commit

Permalink
add where as object
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Sep 23, 2024
1 parent 6788729 commit 8a45136
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/clickhouse/makeQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function makeQuery<T = unknown>(query: string, query_params: ValidQ

const response = await client.query({ query, query_params, format: "JSON" });
const data: ResponseJSON<T> = await response.json();
if (data.meta) delete data.meta;

prometheus.query.inc();
if (data.statistics) {
Expand All @@ -20,6 +21,5 @@ export async function makeQuery<T = unknown>(query: string, query_params: ValidQ
}

logger.trace({ statistics: data.statistics, rows: data.rows, rows_before_limit_at_least: data.rows_before_limit_at_least });

return data;
}
36 changes: 18 additions & 18 deletions src/types/zod.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type UsageActionsByTransactionQueryParamsSchema = z.infer<typeof usageAct
/**
* @description The request has succeeded.
*/
export const usageActionsByTransaction200Schema = z.object({ "data": z.array(z.lazy(() => modelsActionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageActionsByTransaction200Schema = z.object({ "data": z.array(z.lazy(() => modelsActionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageActionsByTransaction200Schema = z.infer<typeof usageActionsByTransaction200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -43,7 +43,7 @@ export type UsageActionsByTransactionErrorSchema = z.infer<typeof usageActionsBy
/**
* @description The request has succeeded.
*/
export const usageActionsByTransactionQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsActionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageActionsByTransactionQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsActionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageActionsByTransactionQueryResponseSchema = z.infer<typeof usageActionsByTransactionQueryResponseSchema>;


Expand All @@ -55,7 +55,7 @@ export type UsageAuthorizationsQueryParamsSchema = z.infer<typeof usageAuthoriza
/**
* @description The request has succeeded.
*/
export const usageAuthorizations200Schema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageAuthorizations200Schema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageAuthorizations200Schema = z.infer<typeof usageAuthorizations200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -65,7 +65,7 @@ export type UsageAuthorizationsErrorSchema = z.infer<typeof usageAuthorizationsE
/**
* @description The request has succeeded.
*/
export const usageAuthorizationsQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageAuthorizationsQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageAuthorizationsQueryResponseSchema = z.infer<typeof usageAuthorizationsQueryResponseSchema>;


Expand All @@ -77,7 +77,7 @@ export type UsageBlocksByDateQueryParamsSchema = z.infer<typeof usageBlocksByDat
/**
* @description The request has succeeded.
*/
export const usageBlocksByDate200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByDate200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByDate200Schema = z.infer<typeof usageBlocksByDate200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -87,7 +87,7 @@ export type UsageBlocksByDateErrorSchema = z.infer<typeof usageBlocksByDateError
/**
* @description The request has succeeded.
*/
export const usageBlocksByDateQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByDateQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByDateQueryResponseSchema = z.infer<typeof usageBlocksByDateQueryResponseSchema>;


Expand All @@ -96,7 +96,7 @@ export type UsageBlocksByHashPathParamsSchema = z.infer<typeof usageBlocksByHash
/**
* @description The request has succeeded.
*/
export const usageBlocksByHash200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByHash200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByHash200Schema = z.infer<typeof usageBlocksByHash200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -106,7 +106,7 @@ export type UsageBlocksByHashErrorSchema = z.infer<typeof usageBlocksByHashError
/**
* @description The request has succeeded.
*/
export const usageBlocksByHashQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByHashQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByHashQueryResponseSchema = z.infer<typeof usageBlocksByHashQueryResponseSchema>;


Expand All @@ -115,7 +115,7 @@ export type UsageBlocksByNumberPathParamsSchema = z.infer<typeof usageBlocksByNu
/**
* @description The request has succeeded.
*/
export const usageBlocksByNumber200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByNumber200Schema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByNumber200Schema = z.infer<typeof usageBlocksByNumber200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -125,7 +125,7 @@ export type UsageBlocksByNumberErrorSchema = z.infer<typeof usageBlocksByNumberE
/**
* @description The request has succeeded.
*/
export const usageBlocksByNumberQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageBlocksByNumberQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsBlocksSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageBlocksByNumberQueryResponseSchema = z.infer<typeof usageBlocksByNumberQueryResponseSchema>;


Expand All @@ -137,7 +137,7 @@ export type UsageDbOpsQueryParamsSchema = z.infer<typeof usageDbOpsQueryParamsSc
/**
* @description The request has succeeded.
*/
export const usageDbOps200Schema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageDbOps200Schema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageDbOps200Schema = z.infer<typeof usageDbOps200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -147,7 +147,7 @@ export type UsageDbOpsErrorSchema = z.infer<typeof usageDbOpsErrorSchema>;
/**
* @description The request has succeeded.
*/
export const usageDbOpsQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageDbOpsQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsAuthorizationsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageDbOpsQueryResponseSchema = z.infer<typeof usageDbOpsQueryResponseSchema>;

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ export type UsageTransactionsByBlockDateQueryParamsSchema = z.infer<typeof usage
/**
* @description The request has succeeded.
*/
export const usageTransactionsByBlockDate200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByBlockDate200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByBlockDate200Schema = z.infer<typeof usageTransactionsByBlockDate200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -217,7 +217,7 @@ export type UsageTransactionsByBlockDateErrorSchema = z.infer<typeof usageTransa
/**
* @description The request has succeeded.
*/
export const usageTransactionsByBlockDateQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByBlockDateQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByBlockDateQueryResponseSchema = z.infer<typeof usageTransactionsByBlockDateQueryResponseSchema>;


Expand All @@ -229,7 +229,7 @@ export type UsageTransactionsByBlockNumberQueryParamsSchema = z.infer<typeof usa
/**
* @description The request has succeeded.
*/
export const usageTransactionsByBlockNumber200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByBlockNumber200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByBlockNumber200Schema = z.infer<typeof usageTransactionsByBlockNumber200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -239,7 +239,7 @@ export type UsageTransactionsByBlockNumberErrorSchema = z.infer<typeof usageTran
/**
* @description The request has succeeded.
*/
export const usageTransactionsByBlockNumberQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByBlockNumberQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByBlockNumberQueryResponseSchema = z.infer<typeof usageTransactionsByBlockNumberQueryResponseSchema>;


Expand All @@ -248,7 +248,7 @@ export type UsageTransactionsByHashPathParamsSchema = z.infer<typeof usageTransa
/**
* @description The request has succeeded.
*/
export const usageTransactionsByHash200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByHash200Schema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByHash200Schema = z.infer<typeof usageTransactionsByHash200Schema>;
/**
* @description An unexpected error response.
Expand All @@ -258,7 +258,7 @@ export type UsageTransactionsByHashErrorSchema = z.infer<typeof usageTransaction
/**
* @description The request has succeeded.
*/
export const usageTransactionsByHashQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number(), "meta": z.array(z.object({ "name": z.coerce.string(), "type": z.coerce.string() })) });
export const usageTransactionsByHashQueryResponseSchema = z.object({ "data": z.array(z.lazy(() => modelsTransactionsSchema)), "statistics": z.object({ "elapsed": z.coerce.number(), "rows_read": z.coerce.number(), "bytes_read": z.coerce.number() }), "rows": z.coerce.number(), "rows_before_limit_at_least": z.coerce.number() });
export type UsageTransactionsByHashQueryResponseSchema = z.infer<typeof usageTransactionsByHashQueryResponseSchema>;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use
if (["limit", "offset", "order_by", "order_direction", "skip", "first"].includes(key)) continue; // skip pagination params
const value = (query_params as any)[key];
let isNumber = !isNaN(Number(value));
// where.push(`${key} = {${key}: ${isNumber ? "int" : "String"}}`);
where.push(`${key}='${value}'`);
where.push(`${key} = {${key}: ${isNumber ? "int" : "String"}}`);;
}
if (where.length) query.push(`WHERE ${where.join(" AND ")}`);

Expand All @@ -46,10 +45,7 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use
if (query_params.offset) query.push("OFFSET {offset: int}");

try {
const result = await makeQuery<UsageElementReturnType>(query.join(" "), { ...query_params });
// Remove the `meta` key from the response
if (result.meta) delete result.meta;
return ctx.json(result);
return ctx.json(await makeQuery<UsageElementReturnType>(query.join(" "), { ...query_params }));
} catch (err) {
return APIErrorResponse(ctx, 500, "bad_database_response", err);
}
Expand Down
Loading

0 comments on commit 8a45136

Please sign in to comment.