Skip to main content

Module query

Module query 

Expand description

Shared prepare → query_map → collect → format!()-wrapped errors boilerplate. Without this helper every analysis would copy-paste the same 7-line pattern with only the SQL constant, params, and mapper closure varying, and the error-message format would drift across analyses.

Usage:

use crate::analyses::query::query_map_collect;
let rows: Vec<MyRow> = query_map_collect(
    db, &sql, duckdb::params![opts.min_revs, row_limit], "my-analysis",
    |r| Ok(MyRow { x: r.get(0)?, y: r.get(1)? }),
)?;

Constants§

HUMAN_ALIASES_CTE
CTE body: every (raw_name, raw_email) alias row that is NOT bot-classified, alongside the canonical it resolves to.

Functions§

clamped_now_anchor
SQL expression for the repository’s window anchor — the “now” that every trailing-window and time-decay term is measured against — clamped so a single future-dated commit cannot become “now” for the whole analysis.
explain_if_requested
Emit the DuckDB EXPLAIN plan for sql + params to stderr if opts.explain is on. No-op otherwise. Shared so every analysis can add --explain support in one line instead of copying the if opts.explain { db.explain_sql(...)?; eprintln!(...); } block.
query_map_collect
Prepare + query_map + collect, with uniform CodeLoreError::Analysis error context at each step. label is interpolated into the error messages so debug output identifies which analysis failed.
wall_clock_utc_literal
The current UTC instant as a YYYY-MM-DD HH:MM:SS string — the exact UTC-naive frame and format commit dates are stored in (facts::ingest::consumer’s timestamp formatter), for embedding as a DuckDB TIMESTAMP literal.