(args: &Args, sql: &str)
| 31 | } |
| 32 | |
| 33 | fn 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 | |
| 66 | fn show_tables() -> Result<()> { |
| 67 | println!("\nAvailable tables:\n"); |
no test coverage detected