rag_rat_core/query/
mod.rs1pub mod clusters;
2pub mod graph;
3pub mod graph_meta;
4pub mod grep_augment;
5pub mod impact;
6pub mod memory;
7pub mod repo_brief;
8pub mod symbol;
9
10use rusqlite::{Connection, OptionalExtension};
11use serde::Serialize;
12
13pub(crate) fn round_score(value: f64) -> f64 {
16 (value * 10_000.0).round() / 10_000.0
17}
18
19#[derive(Debug, Serialize)]
20pub struct ReadChunk {
21 pub chunk_id: i64,
22 pub path: String,
23 pub language: String,
24 pub kind: String,
25 pub start_line: i64,
26 pub end_line: i64,
27 pub symbol_path: Option<String>,
28 pub text: String,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub graph: Option<graph_meta::GraphEvidence>,
31 #[serde(skip_serializing_if = "Vec::is_empty")]
32 pub memories: Vec<memory::RepoMemory>,
33}
34
35pub fn read_chunk(conn: &Connection, chunk_id: i64) -> anyhow::Result<Option<ReadChunk>> {
36 Ok(conn
37 .query_row(
38 "
39 SELECT chunks.id, files.path, files.language, files.kind,
40 chunks.start_line, chunks.end_line, chunks.symbol_path, chunks.text
41 FROM chunks
42 JOIN files ON files.id = chunks.file_id
43 WHERE chunks.id = ?1
44 ",
45 [chunk_id],
46 |row| {
47 Ok(ReadChunk {
48 chunk_id: row.get(0)?,
49 path: row.get(1)?,
50 language: row.get(2)?,
51 kind: row.get(3)?,
52 start_line: row.get(4)?,
53 end_line: row.get(5)?,
54 symbol_path: row.get(6)?,
55 text: row.get(7)?,
56 graph: None,
57 memories: Vec::new(),
58 })
59 },
60 )
61 .optional()?)
62}