You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
900 B
TypeScript
32 lines
900 B
TypeScript
import { createClient as createClickhouseClient } from "@clickhouse/client";
|
|
import type { DataFormat } from "@clickhouse/client";
|
|
import { Env } from "@humanwhocodes/env";
|
|
|
|
const env = new Env();
|
|
|
|
const { CLICKHOUSE_USER, CLICKHOUSE_PASS } = env.required;
|
|
const CLICKHOUSE_HOST = env.get("CLICKHOUSE_HOST", "http://localhost:8123");
|
|
|
|
export const clickhouse = createClickhouseClient({
|
|
host: CLICKHOUSE_HOST,
|
|
username: CLICKHOUSE_USER,
|
|
password: CLICKHOUSE_PASS,
|
|
});
|
|
|
|
export async function query<T>(
|
|
queryString: string,
|
|
format: DataFormat = "JSONEachRow"
|
|
): Promise<Array<T>> {
|
|
return await (
|
|
await clickhouse.query({
|
|
query: queryString,
|
|
format,
|
|
clickhouse_settings: {
|
|
output_format_json_quote_64bit_integers: 0,
|
|
//output_format_json_quote_64bit_floats: false,
|
|
//output_format_json_quote_64bit_decimals: false,
|
|
},
|
|
})
|
|
).json();
|
|
}
|