MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / handle_query

Function handle_query

gql-cli/src/cli/gqlcli.rs:261–318  ·  view source on GitHub ↗

Handle the query command (one-off query execution)

(
    path: PathBuf,
    query: String,
    user: Option<String>,
    password: Option<String>,
    format: OutputFormat,
    explain: bool,
    ast: bool,
)

Source from the content-addressed store, hash-verified

259
260/// Handle the query command (one-off query execution)
261pub fn handle_query(
262 path: PathBuf,
263 query: String,
264 user: Option<String>,
265 password: Option<String>,
266 format: OutputFormat,
267 explain: bool,
268 ast: bool,
269) -> Result<(), Box<dyn std::error::Error>> {
270 // Check if database exists
271 if !path.exists() {
272 return Err(format!(
273 "Database not found at {:?}. Run 'cargo run -- install' first.",
274 path
275 )
276 .into());
277 }
278
279 // Load database
280 let coordinator = load_database(&path)?;
281
282 // Authenticate if credentials provided, otherwise use anonymous session
283 let session_id = if let (Some(u), Some(p)) = (user, password) {
284 authenticate(&coordinator, &u, &p)?
285 } else {
286 // Create anonymous session (limited permissions)
287 coordinator.create_simple_session("anonymous")?
288 };
289
290 // Show AST if requested
291 if ast {
292 println!(
293 "{}",
294 "AST display feature not available in CLI-only mode".yellow()
295 );
296 println!("{}", "AST is an internal implementation detail".yellow());
297 return Ok(());
298 }
299
300 // Show execution plan if requested
301 if explain {
302 println!("{}", "Query execution plan not yet implemented".yellow());
303 return Ok(());
304 }
305
306 // Execute query
307 match coordinator.process_query(&query, &session_id) {
308 Ok(result) => {
309 let output = ResultFormatter::format(&result, format);
310 println!("{}", output);
311 Ok(())
312 }
313 Err(e) => {
314 eprintln!("{}", format!("Error: {}", e).red());
315 Err(e.into())
316 }
317 }
318}

Callers 1

mainFunction · 0.85

Calls 5

load_databaseFunction · 0.85
authenticateFunction · 0.85
create_simple_sessionMethod · 0.80
process_queryMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected