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

Function execute_query

crates/vcsql/src/main.rs:33–64  ·  view source on GitHub ↗
(args: &Args, sql: &str)

Source from the content-addressed store, hash-verified

31}
32
33fn execute_query(args: &Args, sql: &str) -> Result<()> {
34 let start = Instant::now();
35
36 let mut engine = SqlEngine::new()?;
37
38 for repo_path in &args.repo {
39 let mut repo = GitRepo::open(repo_path)
40 .with_context(|| format!("Failed to open repository: {}", repo_path.display()))?;
41
42 engine
43 .load_tables_for_query(sql, &mut repo)
44 .with_context(|| "Failed to load tables")?;
45 }
46
47 let result = engine
48 .execute(sql)
49 .with_context(|| "Query execution failed")?;
50
51 let mut stdout = io::stdout().lock();
52 format_output(&result, &args.format, args.no_header, &mut stdout)?;
53
54 if args.verbose {
55 let elapsed = start.elapsed();
56 eprintln!(
57 "\n{} row(s) in {:.3}s",
58 result.row_count(),
59 elapsed.as_secs_f64()
60 );
61 }
62
63 Ok(())
64}
65
66fn show_tables() -> Result<()> {
67 println!("\nAvailable tables:\n");

Callers 1

mainFunction · 0.85

Calls 4

format_outputFunction · 0.85
with_contextMethod · 0.80
load_tables_for_queryMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected