ggen_core/codegen_lib/queryable.rs
1//! Trait for query execution in code generation rules
2//!
3//! Abstracts the execution of queries (typically SPARQL SELECT) and binding extraction.
4
5use crate::codegen_lib::Result;
6use std::collections::HashMap;
7
8/// Trait for query execution
9///
10/// Abstracts the execution of queries and binding extraction.
11/// Implementors return bindings (variable name → value) for template rendering.
12pub trait Queryable: Send + Sync {
13 /// Execute the query and return a vector of binding maps
14 ///
15 /// Each map represents one result row from the query.
16 /// Keys are query variable names (e.g., "className", "fieldName").
17 /// Values are result strings (IRIs, literals, etc.).
18 fn execute(&self) -> Result<Vec<HashMap<String, String>>>;
19
20 /// Query name for logging/auditing
21 fn name(&self) -> &str;
22
23 /// Optional: query source for debugging
24 fn source(&self) -> Option<&str> {
25 None
26 }
27}