Table of contents
const ClickHouse = require("@apla/clickhouse");
import { table, AnyPrintable, RowsArray } from "../../src";
With a DB connector
const db = new ClickHouse({
host: "localhost",
port: 8124,
user: "default",
password: "",
dataObjects: true,
});
const runS = async (q: string): Promise<any[]> =>
db.querying(q).then((it: any) => it.data);
We can implement a version that is aware of the types
const run = <T extends AnyPrintable>(it: T): Promise<RowsArray<T>> =>
runS(it.stringify());
Then, with some tables
const t1 = table(["x", "y"], "t1");
await runS(`DROP TABLE IF EXISTS t1`);
await runS(`CREATE TABLE IF NOT EXISTS t1(x Int64, y Int64) ENGINE = Memory`);
await runS(`INSERT INTO t1 VALUES(1,2)`);
We can run queries
const value = await run(t1.selectStar());
value;
[{ "x": "1", "y": "2" }]
Typescript knows the identifiers
value.map((it) => it.x);
//@ts-expect-error
value.map((it) => it.u);
This document used eval-md