Macro diesel::sql_function [] [src]

macro_rules! sql_function {
    ($fn_name:ident, $struct_name:ident, ($($arg_name:ident: $arg_type:ty),*) -> $return_type:ty) => { ... };
    ($fn_name:ident, $struct_name:ident, ($($arg_name:ident: $arg_type:ty),*) -> $return_type:ty,
    $docs: expr) => { ... };
    ($fn_name:ident, $struct_name:ident, ($($arg_name:ident: $arg_type:ty),*)) => { ... };
}

Declare a sql function for use in your code. Useful if you have your own SQL functions that you'd like to use. You can optionally provide a doc string as well. $struct_name should just be any unique name. You will not need to reference it in your code, but it is required due to the fact that concat_idents! is useless.

This will generate a rust function with the same name to construct the expression, and a helper type which represents the return type of that function. The function will automatically convert its arguments to expressions.

Example

sql_function!(canon_crate_name, canon_crate_name_t, (a: types::VarChar) -> types::VarChar);

let target_name = "diesel";
crates.filter(canon_crate_name(name).eq(canon_crate_name(target_name)));
// This will generate the following SQL
// SELECT * FROM crates WHERE canon_crate_name(crates.name) = canon_crate_name($1)