Files
knox/internal/db/queries/entries.sql
T
david f80424d707 Merge commit '52c4d1f' into feat/remote-node
# Conflicts:
#	internal/db/db.go
2026-11-03 23:00:20 -08:00

37 lines
1.6 KiB
SQL

-- Pilot queries for sqlc: the read paths behind the MCP tools.
--
-- These are the highest-traffic reads and deliberately include the hardest
-- case (FTS5 MATCH + bm25 ranking) so the pilot proves whether sqlc can cover
-- the search path, not just the easy table scans.
-- name: GetEntry :one
SELECT fingerprint, source_id, COALESCE(source_path,'') AS source_path,
COALESCE(project,'') AS project, COALESCE(content_type,'') AS content_type,
COALESCE(title,'') AS title, COALESCE(summary,'') AS summary,
COALESCE(first_seen,'') AS first_seen, COALESCE(last_seen,'') AS last_seen,
COALESCE(created_at,'') AS created_at, ref_count,
COALESCE(last_confidence,0.5) AS last_confidence
FROM entries
WHERE fingerprint = ?;
-- name: ListRecentEntries :many
SELECT fingerprint, source_id, COALESCE(source_path,'') AS source_path,
COALESCE(project,'') AS project, COALESCE(content_type,'') AS content_type,
COALESCE(title,'') AS title, COALESCE(summary,'') AS summary,
COALESCE(first_seen,'') AS first_seen, COALESCE(last_seen,'') AS last_seen,
COALESCE(created_at,'') AS created_at, ref_count,
COALESCE(last_confidence,0.5) AS last_confidence
FROM entries
ORDER BY COALESCE(NULLIF(created_at,''), last_seen) DESC
LIMIT ?;
-- NOTE: the FTS5 search path is deliberately absent. sqlc ignores
-- `CREATE VIRTUAL TABLE ... USING fts5`, so `entries_fts` and the bm25()/MATCH
-- operators are invisible to it. Search stays hand-written in db.go.
-- name: CountObservations :one
SELECT COUNT(*) FROM observations;
-- name: CountEntries :one
SELECT COUNT(*) FROM entries;