Skip to main content

Module query

Module query 

Source
Expand description

SQL query builders for analytics.

All functions accept a &frankensqlite::Connection and an AnalyticsFilter, keeping the SQL and bucketing logic in one place for both CLI and ftui.

Functions§

build_where_parts
Build SQL WHERE clause fragments and bind-parameter values from an AnalyticsFilter’s dimensional (non-time) filters.
query_breakdown
Run a breakdown query: aggregate one metric by a chosen dimension.
query_cost_timeseries
query_session_scatter
Query per-session (message_count, api_tokens_total) points for Explorer scatter plots.
query_status
Run the analytics status query — returns table health, coverage, and drift.
query_tokens_timeseries
Run the token/usage timeseries query with the given bucketing granularity.
query_tools
query_unpriced_models
Query token_usage for model names that have estimated_cost_usd IS NULL, grouped by model_name with total token counts. Returns the top limit unpriced models sorted by total_tokens descending.
table_exists
Check whether a table exists in the database.