MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / handle_db_command

Function handle_db_command

crates/opencode-cli/src/main.rs:2249–2287  ·  view source on GitHub ↗
(
    action: Option<DbCommands>,
    query: Option<String>,
    format: DbOutputFormat,
)

Source from the content-addressed store, hash-verified

2247}
2248
2249async fn handle_db_command(
2250 action: Option<DbCommands>,
2251 query: Option<String>,
2252 format: DbOutputFormat,
2253) -> anyhow::Result<()> {
2254 if matches!(action, Some(DbCommands::Path)) {
2255 println!("{}", local_database_path().display());
2256 return Ok(());
2257 }
2258
2259 let db_path = local_database_path();
2260 if let Some(query) = query {
2261 let mut args = vec![db_path.display().to_string()];
2262 match format {
2263 DbOutputFormat::Json => args.push("-json".to_string()),
2264 DbOutputFormat::Tsv => args.push("-tabs".to_string()),
2265 }
2266 args.push(query);
2267
2268 let output = ProcessCommand::new("sqlite3")
2269 .args(&args)
2270 .output()
2271 .map_err(|e| anyhow::anyhow!("Failed to run sqlite3: {}", e))?;
2272 if output.status.success() {
2273 print!("{}", String::from_utf8_lossy(&output.stdout));
2274 return Ok(());
2275 }
2276 anyhow::bail!("{}", String::from_utf8_lossy(&output.stderr));
2277 }
2278
2279 let status = ProcessCommand::new("sqlite3")
2280 .arg(db_path)
2281 .status()
2282 .map_err(|e| anyhow::anyhow!("Failed to run sqlite3 interactive shell: {}", e))?;
2283 if !status.success() {
2284 anyhow::bail!("sqlite3 exited with status {}", status);
2285 }
2286 Ok(())
2287}
2288
2289async fn handle_stats_command(
2290 days: Option<i64>,

Callers 1

mainFunction · 0.85

Calls 5

local_database_pathFunction · 0.85
newFunction · 0.85
outputMethod · 0.80
successMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected