Agent skill
clickhouse
Rules when working with ClickHouse database in Gram for analytics and telemetry features
Install this agent skill to your Project
npx add-skill https://github.com/speakeasy-api/gram/tree/main/.agents/skills/clickhouse
SKILL.md
ClickHouse Queries (Telemetry Package)
The server/internal/telemetry package uses ClickHouse for high-performance analytics queries. Unlike PostgreSQL queries, ClickHouse queries are NOT auto-generated by SQLc (SQLc doesn't support ClickHouse). We use the squirrel query builder for dynamic query construction.
CRITICAL: The squirrel query builder is ONLY permitted for ClickHouse queries in the telemetry package. DO NOT use squirrel for PostgreSQL queries - all PostgreSQL queries MUST use SQLc-generated code. This is the only acceptable exception to our "no query builders" policy.
File Structure
queries.sql.go: Query implementations using squirrelpagination.go: Cursor pagination helpers (withPagination,withOrdering, etc.)README.md: Detailed documentation and patterns specific to ClickHouse
Adding ClickHouse Queries
When asked to add a new ClickHouse query to the telemetry package:
-
Create a params struct for query inputs
-
Build the query using squirrel (the
sqvar in queries.sql.go is pre-configured for ClickHouse):gotype GetMetricsParams struct { ProjectID string DeploymentID string // optional Limit int } func (q *Queries) GetMetrics(ctx context.Context, arg GetMetricsParams) ([]Metric, error) { sb := sq.Select("id", "value", "timestamp"). From("metrics"). Where("project_id = ?", arg.ProjectID) // Optional filters - explicit conditionals for clarity if arg.DeploymentID != "" { sb = sb.Where(squirrel.Eq{"deployment_id": arg.DeploymentID}) } sb = sb.Limit(uint64(arg.Limit)) query, args, err := sb.ToSql() if err != nil { return nil, fmt.Errorf("building query: %w", err) } rows, err := q.conn.Query(ctx, query, args...) // ... handle rows } -
Use pagination helpers from
pagination.go:withPagination(sb, cursor, sortOrder)- cursor paginationwithOrdering(sb, sortOrder, primaryCol, secondaryCol)- ORDER BY
Testing ClickHouse Queries
- Use
testenv.Launch()inTestMainfor infrastructure setup - Add
time.Sleep(100 * time.Millisecond)after inserts (ClickHouse eventual consistency) - Use table-driven tests with descriptive "it" prefix names
- Create helper functions for test data insertion
See server/internal/telemetry/README.md for comprehensive documentation.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
frontend
Rules and best practices when working on the dashboard and elements React frontend codebases
postgresql
Rules when working with PostgreSQL database in Gram
datadog
Use Datadog MCP tools to investigate logs, metrics, traces, and incidents for the Gram project. Activate when the user asks about errors, performance issues, incidents, latency, or wants to search telemetry data.
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
mise-tasks
Rules and best practices for writing and editing mise tasks.
gram-functions
A walkthrough of the Gram Functions feature in this codebase
Didn't find tool you were looking for?