Skip to main content

diesel/query_builder/
collected_query.rs

1use super::{AstPass, MoveableBindCollector, Query, QueryFragment, QueryId};
2use crate::backend::{Backend, DieselReserveSpecialization};
3use crate::result::QueryResult;
4use crate::sql_types::Untyped;
5use alloc::string::String;
6
7#[derive(#[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for CollectedQuery<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "CollectedQuery", "sql", &self.sql, "safe_to_cache_prepared",
            &self.safe_to_cache_prepared, "bind_data", &&self.bind_data)
    }
}Debug)]
8#[must_use = "Queries are only executed when calling `load`, `get_result` or similar."]
9/// A SQL query variant with already collected bind data which can be moved
10#[must_use =
"Queries are only executed when calling `load`, `get_result` or similar."]
#[doc =
" A SQL query variant with already collected bind data which can be moved"]
#[non_exhaustive]
pub struct CollectedQuery<T> {
    sql: String,
    safe_to_cache_prepared: bool,
    bind_data: T,
}#[diesel_derives::__diesel_public_if(
11    feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
12)]
13pub struct CollectedQuery<T> {
14    sql: String,
15    safe_to_cache_prepared: bool,
16    bind_data: T,
17}
18
19impl<T> CollectedQuery<T> {
20    /// Builds a [CollectedQuery] with movable bind data
21    pub fn new(sql: String, safe_to_cache_prepared: bool, bind_data: T) -> Self {
22        Self {
23            sql,
24            safe_to_cache_prepared,
25            bind_data,
26        }
27    }
28}
29
30impl<DB, T> QueryFragment<DB> for CollectedQuery<T>
31where
32    DB: Backend + DieselReserveSpecialization,
33    for<'a> <DB as Backend>::BindCollector<'a>: MoveableBindCollector<DB, BindData = T>,
34{
35    fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
36        if !self.safe_to_cache_prepared {
37            pass.unsafe_to_cache_prepared();
38        }
39        pass.push_sql(&self.sql);
40        pass.push_bind_collector_data::<T>(&self.bind_data)
41    }
42}
43
44impl<T> QueryId for CollectedQuery<T> {
45    type QueryId = ();
46
47    const HAS_STATIC_QUERY_ID: bool = false;
48}
49
50impl<T> Query for CollectedQuery<T> {
51    type SqlType = Untyped;
52}