rudof_lib 0.2.20-rc.1

RDF data shapes implementation in Rust
use crate::{
    Result, Rudof,
    api::query::QueryOperations,
    formats::{InputSpec, QueryType},
};

/// Builder for `load_query` operation.
///
/// Provides a fluent interface for configuring and executing query loading
/// operations.
pub struct LoadQueryBuilder<'a> {
    rudof: &'a mut Rudof,
    query: &'a InputSpec,
    query_type: Option<&'a QueryType>,
}

impl<'a> LoadQueryBuilder<'a> {
    /// Creates a new builder instance.
    ///
    /// This is called internally by `Rudof::load_query()` and should not
    /// be constructed directly.
    pub(crate) fn new(rudof: &'a mut Rudof, query: &'a InputSpec) -> Self {
        Self {
            rudof,
            query,
            query_type: None,
        }
    }

    /// Sets the query type (e.g. SELECT).
    ///
    /// If not set, Rudof will attempt to auto-detect the query type.
    pub fn with_query_type(mut self, query_type: &'a QueryType) -> Self {
        self.query_type = Some(query_type);
        self
    }

    /// Executes the query loading operation.
    pub fn execute(self) -> Result<()> {
        <Rudof as QueryOperations>::load_query(self.rudof, self.query, self.query_type)
    }
}