From 098554df84521e9dab1b661f50e43225664fc4e0 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sun, 11 Oct 2020 21:43:48 -0700 Subject: [PATCH] Add docs for sql function without arguments Add v1.4 upgrade comment to the CHANGELOG nodes --- CHANGELOG.md | 4 ++++ diesel_derives/src/lib.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bae7049b83..b22007a6ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -213,6 +213,10 @@ Key points: NonAggregate` no longer implies `(OtherType, T): NonAggregate`. - With `feature = "unstable"`, `(T, OtherType): NonAggregate` is still implied. +- In diesel v1.4 sql functions without arguments used the `no_arg_sql_function!` macro, + which has since been deprecated. The new `sql_function!` macro supports functions without + arguments. + [2-0-migration]: FIXME write a migration guide ## [1.4.5] - 2020-06-09 diff --git a/diesel_derives/src/lib.rs b/diesel_derives/src/lib.rs index 6f766f4ca1..bab21703cb 100644 --- a/diesel_derives/src/lib.rs +++ b/diesel_derives/src/lib.rs @@ -863,6 +863,25 @@ pub fn derive_valid_grouping(input: TokenStream) -> TokenStream { /// # } /// ``` /// +/// # SQL Functions without Arguments +/// +/// A common example is ordering a query using the `RANDOM()` sql function, +/// which can be implemented using `sql_function!` like this: +/// +/// ```rust +/// # extern crate diesel; +/// # use diesel::*; +/// # +/// # table! { crates { id -> Integer, name -> VarChar, } } +/// # +/// sql_function!(fn random() -> Text); +/// +/// # fn main() { +/// # use self::crates::dsl::*; +/// crates.order(random()); +/// # } +/// ``` +/// /// # Use with SQLite /// /// On most backends, the implementation of the function is defined in a