npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hypequery/clickhouse

v1.3.0

Published

ClickHouse typescript query builder

Readme

GitHub license npm version GitHub stars

Overview

hypequery is a typescript-first query builder for ClickHouse designed specifically for building type-safe analytics dashboards. Unlike generic SQL query builders, hypequery understands your ClickHouse schema and provides full type checking, making it ideal for data-intensive applications.

Features

  • 🎯 Type-Safe: Full TypeScript support with types from your ClickHouse schema
  • 🚀 Performant: Built for real-time analytics with optimized query generation
  • 🔍 Cross Filtering: Powerful cross-filtering capabilities for interactive dashboards
  • 🛠️ Developer Friendly: Fluent API design for an intuitive development experience
  • 📱 Platform Agnostic: Works in both Node.js and browser environments
  • 🔄 Schema Generation: CLI tool to generate TypeScript types from your ClickHouse schema

Installation

This library requires one of the following ClickHouse clients as a peer dependency:

For Node.js environments

npm install @hypequery/clickhouse

For browser/universal environments

npm install @hypequery/clickhouse @clickhouse/client-web

Note: The library supports multiple client selection strategies:

  • Manual injection: Explicitly provide a client instance (required for browser environments)
  • Auto-detection: Automatically selects the client for Node.js environments

Quick Start

Node.js Environments

import { createQueryBuilder } from '@hypequery/clickhouse';
import type { IntrospectedSchema } from './generated-schema';

// Initialize the query builder
const db = createQueryBuilder<IntrospectedSchema>({
  host: 'your-clickhouse-host',
  username: 'default',
  password: 'your-password',
  database: 'default'
});

// Build and execute a query
const results = await db
  .table('trips')
  .select(['pickup_datetime', 'dropoff_datetime', 'total_amount'])
  .where('total_amount', '>', 50)
  .orderBy('pickup_datetime', 'DESC')
  .limit(10)
  .execute();

Browser Environments

import { createQueryBuilder } from '@hypequery/clickhouse';
import { createClient } from '@clickhouse/client-web';
import type { IntrospectedSchema } from './generated-schema';

// Create the ClickHouse client explicitly
const client = createClient({
  host: 'your-clickhouse-host',
  username: 'default',
  password: '',
  database: 'default'
});

// Initialize the query builder with the client
const db = createQueryBuilder<IntrospectedSchema>({
  client // Explicitly provide the client
});

// Build and execute a query
const results = await db
  .table('trips')
  .select(['pickup_datetime', 'dropoff_datetime', 'total_amount'])
  .where('total_amount', '>', 50)
  .orderBy('pickup_datetime', 'DESC')
  .limit(10)
  .execute();

Schema Generation

hypequery provides a CLI tool to generate TypeScript types from your ClickHouse schema:

# Install globally (optional)
npm install -g @hypequery/clickhouse

# Generate schema types
npx hypequery-generate-types --host your-clickhouse-host --database your-database

This creates a generated-schema.ts file that you can import in your application:

import { createQueryBuilder } from '@hypequery/clickhouse';
import type { IntrospectedSchema } from './generated-schema';

const db = createQueryBuilder<IntrospectedSchema>({
  // connection details
});

Core Features

Type-Safe Queries

hypequery provides full TypeScript support, ensuring your queries are type-safe:

// Column names are type-checked
const query = db.table('trips')
  .select(['pickup_datetime', 'total_amount']) 
  .where('total_amount', 'gt', 50)
  .execute();

// Type error if column doesn't exist
db.table('trips').select(['non_existent_column']); // TypeScript error

Cross Filtering

Implement interactive dashboards with cross-filtering support:

import { CrossFilter } from '@hypequery/clickhouse';

// Create a filter
const filter = new CrossFilter()
  .add({
    column: 'pickup_datetime',
    operator: 'gte',
    value: '2024-01-01'
  })
  .add({
    column: 'total_amount',
    operator: 'gt',
    value: 20
  });

// Apply to multiple queries
const query1 = db.table('trips')
  .applyCrossFilters(filter)
  .execute();

const query2 = db.table('drivers')
  .applyCrossFilters(filter)
  .execute();

Advanced Queries

hypequery supports complex queries including joins, aggregations, and subqueries:

// Aggregations
const stats = await db.table('trips')
  .avg('total_amount')
  .max('trip_distance')
  .count('trip_id')
  .where('pickup_datetime', 'gte', '2024-01-01')
  .execute();

// Joins
const tripsWithDrivers = await db.table('trips')
  .select(['trips.trip_id', 'trips.total_amount', 'drivers.name'])
  .join('drivers', 'trips.driver_id', 'drivers.id')
  .execute();

Benefits:

  • ✅ Works in all environments (Node.js, browser, bundlers)
  • ✅ Explicit control over client configuration
  • ✅ Required for browser environments (require() doesn't work in browsers)
  • ✅ Synchronous API throughout

2. Auto-Detection with Fallback (Node.js Environments Only)

const db = createQueryBuilder<IntrospectedSchema>({
  host: 'your-clickhouse-host',
  username: 'default',
  password: '',
  database: 'default'
});

Versioning and Release Channels

hypequery follows semantic versioning and provides multiple release channels:

  • Latest: Stable releases (npm install @hypequery/clickhouse)
  • Beta: Pre-release versions (npm install @hypequery/clickhouse@beta)

Documentation

For detailed documentation and examples, visit our documentation site.

Troubleshooting

Common Issues

  • Connection Errors: Ensure your ClickHouse server is running and accessible
  • CORS Issues: Use a proxy server for browser environments
  • Type Errors: Make sure to regenerate your schema types after schema changes
  • Client Not Found: Make sure you have installed at least one of the required peer dependencies:
    • @clickhouse/client (for Node.js environments)
    • @clickhouse/client-web (for browser/universal environments)
  • Browser Auto-Detection: Auto-detection doesn't work in browsers because require() calls don't work. Use manual injection instead.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Support