diesel/query_builder/
collected_query.rs1use super::{AstPass, MoveableBindCollector, Query, QueryFragment, QueryId};
2use crate::backend::{Backend, DieselReserveSpecialization};
3use crate::result::QueryResult;
4use crate::sql_types::Untyped;
5
6#[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)]
7#[must_use = "Queries are only executed when calling `load`, `get_result` or similar."]
8#[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(
10 feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
11)]
12pub struct CollectedQuery<T> {
13 sql: String,
14 safe_to_cache_prepared: bool,
15 bind_data: T,
16}
17
18impl<T> CollectedQuery<T> {
19 pub fn new(sql: String, safe_to_cache_prepared: bool, bind_data: T) -> Self {
21 Self {
22 sql,
23 safe_to_cache_prepared,
24 bind_data,
25 }
26 }
27}
28
29impl<DB, T> QueryFragment<DB> for CollectedQuery<T>
30where
31 DB: Backend + DieselReserveSpecialization,
32 for<'a> <DB as Backend>::BindCollector<'a>: MoveableBindCollector<DB, BindData = T>,
33{
34 fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
35 if !self.safe_to_cache_prepared {
36 pass.unsafe_to_cache_prepared();
37 }
38 pass.push_sql(&self.sql);
39 pass.push_bind_collector_data::<T>(&self.bind_data)
40 }
41}
42
43impl<T> QueryId for CollectedQuery<T> {
44 type QueryId = ();
45
46 const HAS_STATIC_QUERY_ID: bool = false;
47}
48
49impl<T> Query for CollectedQuery<T> {
50 type SqlType = Untyped;
51}