MCPcopy Create free account
hub / github.com/douglance/devsql / load

Function load

crates/devsql/src/providers/source_files.rs:11–56  ·  view source on GitHub ↗

Create and populate the `source_files` table.

(conn: &Connection, repo_path: &Path)

Source from the content-addressed store, hash-verified

9
10/// Create and populate the `source_files` table.
11pub fn load(conn: &Connection, repo_path: &Path) -> Result<()> {
12 conn.execute_batch(
13 "CREATE TABLE IF NOT EXISTS source_files (
14 path TEXT PRIMARY KEY,
15 name TEXT,
16 extension TEXT,
17 directory TEXT,
18 size_bytes INTEGER,
19 line_count INTEGER,
20 modified_at TEXT,
21 language TEXT
22 )",
23 )?;
24
25 let files = walk_source_files(repo_path);
26
27 conn.execute_batch("BEGIN")?;
28
29 let mut stmt = conn.prepare(
30 "INSERT OR IGNORE INTO source_files
31 (path, name, extension, directory, size_bytes, line_count, modified_at, language)
32 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
33 )?;
34
35 for file_info in &files {
36 let abs_path = repo_path.join(&file_info.path);
37 let line_count = count_lines(&abs_path);
38 let language = detect_language(&file_info.extension);
39
40 stmt.execute(params![
41 file_info.path,
42 file_info.name,
43 file_info.extension,
44 file_info.directory,
45 file_info.size as i64,
46 line_count as i64,
47 file_info.modified_at,
48 language,
49 ])?;
50 }
51
52 drop(stmt);
53 conn.execute_batch("COMMIT")?;
54
55 Ok(())
56}
57
58/// Count lines in a file using a buffered reader without holding the entire
59/// file contents in memory.

Callers

nothing calls this directly

Calls 4

walk_source_filesFunction · 0.85
count_linesFunction · 0.85
detect_languageFunction · 0.85
executeMethod · 0.45

Tested by

no test coverage detected