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