Skip to main content

rag_rat_core/query/
mod.rs

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