Skip to main content

diesel/expression/functions/
arguments.rs

1use crate::QueryResult;
2use crate::backend::sql_dialect::sql_function_parameter_notation::{
3    PositionalNotationOnly, PositionalOrNamedNotation,
4};
5use crate::backend::{Backend, SqlDialect};
6use crate::query_builder::{AstPass, QueryFragment, QueryId};
7
8/// Helper type to represent a parameter of a SQL function. Used to allow passing the parameter
9/// by name or by position, depending on the value of `NAMED` and the
10/// [`SqlDialect::SqlFunctionParameterNotation`] specialization type.
11#[derive(#[automatically_derived]impl<const NAMED : bool> ::core::fmt::Debug for
    FunctionParameter<NAMED> {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f,
            "FunctionParameter name", &&self.name)
    }
}Debug, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl<const NAMED : bool> diesel::query_builder::QueryId for
            FunctionParameter<NAMED> {
            type QueryId = FunctionParameter<NAMED>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, #[automatically_derived]impl<const NAMED : bool> ::core::marker::Copy for
    FunctionParameter<NAMED> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<const NAMED : bool>
    ::core::clone::TrivialClone for FunctionParameter<NAMED> {
}
#[automatically_derived]impl<const NAMED : bool> ::core::clone::Clone for
    FunctionParameter<NAMED> {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<&'static str>;
        *self
    }
}Clone)]
12pub struct FunctionParameter<const NAMED: bool> {
13    /// The name of the function parameter.
14    pub name: &'static str,
15}
16
17impl<DB> QueryFragment<DB, PositionalNotationOnly> for FunctionParameter<false>
18where
19    DB: Backend + SqlDialect<SqlFunctionParameterNotation = PositionalNotationOnly>,
20{
21    fn walk_ast<'b>(&'b self, _out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
22        Ok(())
23    }
24}
25
26impl<DB> QueryFragment<DB, PositionalOrNamedNotation> for FunctionParameter<false>
27where
28    DB: Backend + SqlDialect<SqlFunctionParameterNotation = PositionalOrNamedNotation>,
29{
30    fn walk_ast<'b>(&'b self, _out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
31        Ok(())
32    }
33}
34
35impl<DB> QueryFragment<DB, PositionalOrNamedNotation> for FunctionParameter<true>
36where
37    DB: Backend + SqlDialect<SqlFunctionParameterNotation = PositionalOrNamedNotation>,
38{
39    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
40        out.push_sql(self.name);
41        out.push_sql("=>");
42        Ok(())
43    }
44}