use oxigraph::sparql::SparqlEvaluator;
use crate::{Error, Model, Result};
pub type QueryResults<'a> = oxigraph::sparql::QueryResults<'a>;
#[derive(Clone, Debug)]
pub struct Query {
text: String,
}
impl Query {
#[must_use]
pub fn new(text: impl Into<String>) -> Self {
Self { text: text.into() }
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.text
}
pub fn execute<'a>(&self, model: &'a Model) -> Result<QueryResults<'a>> {
SparqlEvaluator::new()
.parse_query(&self.text)
.map_err(|error| Error::SparqlParse(error.to_string()))?
.on_store(model.store())
.execute()
.map_err(|error| Error::SparqlEvaluation(error.to_string()))
}
}