write a select query for clickhouse in typescript

index.ts
import {Client} from 'clickhouse';

const client = new Client({host: 'localhost'});

const selectQuery = `
  SELECT *
  FROM my_database.my_table
  WHERE created_at > toDate('2021-01-01')`;

client.query(selectQuery).toPromise()
  .then(data => console.log(data))
  .catch(error => console.error(error));
305 chars
13 lines

In the above code, we import the Client class from the clickhouse library and create a new instance with the host details. We then define our SQL select query in selectQuery and call the query() method provided by the Client class. The toPromise() method is used to convert the observable result to a promise, which resolves with the query results. Finally, we log the query results if successful or log any errors if not.

gistlibby LogSnag