import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.1/mod.ts";
import {
ClickHouseSettings,
createClient,
DataFormat,
QueryParams,
} from "npm:@clickhouse/client-web@0.2.5";
/**
* @param parse_into Name of the method that should be used to parse the results.
*
* @param format Format of the resulting dataset. Wrap the format name with `"` in the
* argument editor.
*
* @param clickhouse_settings ClickHouse settings that can be applied on query level.
*
* @param query_params Parameters for query binding.
*
* @param query_params AbortSignal instance to cancel a query in progress.
*/
type Clickhouse = {
host: string;
username: string;
password: string;
};
export async function main(
auth: Clickhouse,
query: string,
parse_into: "json" | "text" = "json",
format?: DataFormat,
clickhouse_settings?: ClickHouseSettings,
query_params?: Record<string, unknown>,
abort_signal?: AbortSignal,
) {
const client = createClient(removeObjectEmptyFields(auth));
const params = removeObjectEmptyFields({
query,
format,
clickhouse_settings,
query_params,
abort_signal,
}) as QueryParams;
const result = await client.query(params);
await client.close();
return await result[parse_into]();
}
Submitted by pieter jongsma557 387 days ago