---
source: diesel_derives/src/tests/mod.rs
expression: out
info:
input: "sql_function! {\n fn lower(input : Text) -> Text;\n}\n"
---
#[allow(non_camel_case_types)]
pub fn lower<input>(input: input) -> lower::HelperType<input>
where
input: diesel::expression::AsExpression<Text>,
{
lower::lower {
input: input.as_expression(),
param_input: diesel::internal::sql_functions::FunctionParameter {
name: stringify!(input),
},
}
}
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lower {
use diesel::{self, QueryResult};
use diesel::expression::{
AsExpression, Expression, SelectableExpression, AppearsOnTable, ValidGrouping,
};
use diesel::query_builder::{QueryFragment, AstPass};
use diesel::sql_types::*;
use diesel::internal::sql_functions::*;
use super::*;
#[derive(Debug, Clone, Copy, diesel::query_builder::QueryId)]
#[derive(diesel::sql_types::DieselNumericOps)]
pub struct lower<input> {
pub(super) input: input,
pub(super) param_input: FunctionParameter<false>,
}
///The return type of [`lower()`](fn@lower)
pub type HelperType<input> = lower<<input as AsExpression<Text>>::Expression>;
impl<input> Expression for lower<input>
where
(input): Expression,
{
type SqlType = Text;
}
impl<input, __DieselInternal> SelectableExpression<__DieselInternal> for lower<input>
where
input: SelectableExpression<__DieselInternal>,
Self: AppearsOnTable<__DieselInternal>,
{}
impl<input, __DieselInternal> AppearsOnTable<__DieselInternal> for lower<input>
where
input: AppearsOnTable<__DieselInternal>,
Self: Expression,
{}
impl<input, __DieselInternal> FunctionFragment<__DieselInternal> for lower<input>
where
__DieselInternal: diesel::backend::Backend,
FunctionParameter<
false,
>: QueryFragment<
__DieselInternal,
<__DieselInternal as diesel::backend::SqlDialect>::SqlFunctionParameterNotation,
>,
input: QueryFragment<__DieselInternal>,
{
const FUNCTION_NAME: &'static str = "lower";
#[allow(unused_assignments)]
fn walk_arguments<'__b>(
&'__b self,
mut out: AstPass<'_, '__b, __DieselInternal>,
) -> QueryResult<()> {
let mut needs_comma = false;
if !self.input.is_noop(out.backend())? {
if needs_comma {
out.push_sql(", ");
}
self.param_input.walk_ast(out.reborrow())?;
self.input.walk_ast(out.reborrow())?;
needs_comma = true;
}
Ok(())
}
}
impl<input, __DieselInternal> QueryFragment<__DieselInternal> for lower<input>
where
__DieselInternal: diesel::backend::Backend,
FunctionParameter<
false,
>: QueryFragment<
__DieselInternal,
<__DieselInternal as diesel::backend::SqlDialect>::SqlFunctionParameterNotation,
>,
input: QueryFragment<__DieselInternal>,
{
fn walk_ast<'__b>(
&'__b self,
mut out: AstPass<'_, '__b, __DieselInternal>,
) -> QueryResult<()> {
out.push_sql(<Self as FunctionFragment<__DieselInternal>>::FUNCTION_NAME);
out.push_sql("(");
self.walk_arguments(out.reborrow())?;
out.push_sql(")");
Ok(())
}
}
#[derive(ValidGrouping)]
pub struct __Derived<input>(input);
impl<input, __DieselInternal> ValidGrouping<__DieselInternal> for lower<input>
where
__Derived<input>: ValidGrouping<__DieselInternal>,
{
type IsAggregate = <__Derived<
input,
> as ValidGrouping<__DieselInternal>>::IsAggregate;
}
#[allow(dead_code)]
/// Registers an implementation for this function on the given connection.
///
/// This function must be called for every `SqliteConnection` before
/// this SQL function can be used on SQLite. The implementation must be
/// deterministic (returns the same result given the same arguments). If
/// the function is nondeterministic, call
/// [`register_nondeterministic_impl`](self::register_nondeterministic_impl)
/// instead, or [`register_impl_with_behavior`](self::register_impl_with_behavior)
/// for full control over the SQLite behavior flags.
pub fn register_impl<F, Ret, input>(
conn: &mut diesel::sqlite::SqliteConnection,
f: F,
) -> diesel::result::QueryResult<()>
where
F: Fn(input) -> Ret + ::core::panic::UnwindSafe + Send + 'static,
(
input,
): diesel::deserialize::FromSqlRow<(Text,), diesel::sqlite::Sqlite>
+ diesel::deserialize::StaticallySizedRow<(Text,), diesel::sqlite::Sqlite>,
Ret: diesel::serialize::ToSql<Text, diesel::sqlite::Sqlite>,
{
register_impl_with_behavior(
conn,
diesel::sqlite::SqliteFunctionBehavior::DETERMINISTIC,
f,
)
}
#[allow(dead_code)]
/// Registers a nondeterministic implementation for this function on the
/// given connection.
///
/// This function must be called for every `SqliteConnection` before
/// this SQL function can be used on SQLite.
/// `register_nondeterministic_impl` should only be used if your
/// function can return different results with the same arguments (e.g.
/// `random`). If your function is deterministic, you should call
/// [`register_impl`](self::register_impl) instead. For full control over
/// the SQLite behavior flags, use
/// [`register_impl_with_behavior`](self::register_impl_with_behavior).
pub fn register_nondeterministic_impl<F, Ret, input>(
conn: &mut diesel::sqlite::SqliteConnection,
f: F,
) -> diesel::result::QueryResult<()>
where
F: FnMut(input) -> Ret + ::core::panic::UnwindSafe + Send + 'static,
(
input,
): diesel::deserialize::FromSqlRow<(Text,), diesel::sqlite::Sqlite>
+ diesel::deserialize::StaticallySizedRow<(Text,), diesel::sqlite::Sqlite>,
Ret: diesel::serialize::ToSql<Text, diesel::sqlite::Sqlite>,
{
register_impl_with_behavior(
conn,
diesel::sqlite::SqliteFunctionBehavior::empty(),
f,
)
}
#[allow(dead_code)]
/// Registers an implementation for this function on the given connection,
/// with explicit control over the SQLite behavior flags.
///
/// This function must be called for every `SqliteConnection` before
/// this SQL function can be used on SQLite. Prefer
/// [`register_impl`](self::register_impl) (deterministic) or
/// [`register_nondeterministic_impl`](self::register_nondeterministic_impl)
/// unless you need to set behavior flags explicitly. See
/// [`SqliteFunctionBehavior`] for the available flags.
pub fn register_impl_with_behavior<F, Ret, input>(
conn: &mut diesel::sqlite::SqliteConnection,
behavior: diesel::sqlite::SqliteFunctionBehavior,
mut f: F,
) -> diesel::result::QueryResult<()>
where
F: FnMut(input) -> Ret + ::core::panic::UnwindSafe + Send + 'static,
(
input,
): diesel::deserialize::FromSqlRow<(Text,), diesel::sqlite::Sqlite>
+ diesel::deserialize::StaticallySizedRow<(Text,), diesel::sqlite::Sqlite>,
Ret: diesel::serialize::ToSql<Text, diesel::sqlite::Sqlite>,
{
conn.register_sql_function::<
(Text,),
Text,
_,
_,
_,
>("lower", behavior, move |(input,)| f(input))
}
}