Skip to content

Commit 6c635de

Browse files
committed
update uses inside Diesel to sql_function_v2
that should be almost always backwards compatible because the module was only pub(crate) anyway. It is not strictly backwards compatible because diesel-rs#3745 (comment)
1 parent 5ece64e commit 6c635de

33 files changed

+103
-95
lines changed

diesel/src/expression/count.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

3-
use super::functions::sql_function;
3+
use super::functions::sql_function_v2;
44
use super::{is_aggregate, AsExpression};
55
use super::{Expression, ValidGrouping};
66
use crate::backend::Backend;
@@ -9,7 +9,7 @@ use crate::result::QueryResult;
99
use crate::sql_types::{BigInt, DieselNumericOps, SingleValue, SqlType};
1010
use crate::{AppearsOnTable, SelectableExpression};
1111

12-
sql_function! {
12+
sql_function_v2! {
1313
/// Creates a SQL `COUNT` expression
1414
///
1515
/// As with most bare functions, this is not exported by default. You can import

diesel/src/expression/functions/aggregate_folding.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::expression::functions::sql_function;
1+
use crate::expression::functions::sql_function_v2;
22
use crate::sql_types::Foldable;
33

4-
sql_function! {
4+
sql_function_v2! {
55
/// Represents a SQL `SUM` function. This function can only take types which are
66
/// Foldable.
77
///
@@ -21,7 +21,7 @@ sql_function! {
2121
fn sum<ST: Foldable>(expr: ST) -> ST::Sum;
2222
}
2323

24-
sql_function! {
24+
sql_function_v2! {
2525
/// Represents a SQL `AVG` function. This function can only take types which are
2626
/// Foldable.
2727
///

diesel/src/expression/functions/aggregate_ordering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use self::private::SqlOrdAggregate;
2-
use crate::expression::functions::sql_function;
2+
use crate::expression::functions::sql_function_v2;
33

4-
sql_function! {
4+
sql_function_v2! {
55
/// Represents a SQL `MAX` function. This function can only take types which are
66
/// ordered.
77
///
@@ -20,7 +20,7 @@ sql_function! {
2020
fn max<ST: SqlOrdAggregate>(expr: ST) -> ST::Ret;
2121
}
2222

23-
sql_function! {
23+
sql_function_v2! {
2424
/// Represents a SQL `MIN` function. This function can only take types which are
2525
/// ordered.
2626
///

diesel/src/expression/functions/date_and_time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::backend::Backend;
22
use crate::expression::coerce::Coerce;
3-
use crate::expression::functions::sql_function;
3+
use crate::expression::functions::sql_function_v2;
44
use crate::expression::{AsExpression, Expression, ValidGrouping};
55
use crate::query_builder::*;
66
use crate::result::QueryResult;
@@ -27,7 +27,7 @@ impl_selectable_expression!(now);
2727

2828
operator_allowed!(now, Add, add);
2929
operator_allowed!(now, Sub, sub);
30-
sql_function! {
30+
sql_function_v2! {
3131
/// Represents the SQL `DATE` function. The argument should be a Timestamp
3232
/// expression, and the return value will be an expression of type Date.
3333
///

diesel/src/expression/functions/helper_types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use crate::expression::operators;
88
pub type not<Expr> = operators::Not<Grouped<Expr>>;
99

1010
/// The return type of [`max(expr)`](crate::dsl::max())
11-
pub type max<Expr> = super::aggregate_ordering::max::HelperType<SqlTypeOf<Expr>, Expr>;
11+
pub type max<Expr> = super::aggregate_ordering::max<SqlTypeOf<Expr>, Expr>;
1212

1313
/// The return type of [`min(expr)`](crate::dsl::min())
14-
pub type min<Expr> = super::aggregate_ordering::min::HelperType<SqlTypeOf<Expr>, Expr>;
14+
pub type min<Expr> = super::aggregate_ordering::min<SqlTypeOf<Expr>, Expr>;
1515

1616
/// The return type of [`sum(expr)`](crate::dsl::sum())
17-
pub type sum<Expr> = super::aggregate_folding::sum::HelperType<SqlTypeOf<Expr>, Expr>;
17+
pub type sum<Expr> = super::aggregate_folding::sum<SqlTypeOf<Expr>, Expr>;
1818

1919
/// The return type of [`avg(expr)`](crate::dsl::avg())
20-
pub type avg<Expr> = super::aggregate_folding::avg::HelperType<SqlTypeOf<Expr>, Expr>;
20+
pub type avg<Expr> = super::aggregate_folding::avg<SqlTypeOf<Expr>, Expr>;
2121

2222
/// The return type of [`exists(expr)`](crate::dsl::exists())
2323
pub type exists<Expr> = crate::expression::exists::Exists<Expr>;

diesel/src/expression/functions/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Helper macros to define custom sql functions
22
33
#[doc(inline)]
4-
pub use diesel_derives::sql_function_proc as sql_function;
4+
pub use diesel_derives::{sql_function_proc as sql_function, sql_function_v2};
55

66
#[macro_export]
77
#[doc(hidden)]
@@ -73,7 +73,7 @@ macro_rules! no_arg_sql_function_body {
7373
/// function.
7474
#[deprecated(
7575
since = "2.0.0",
76-
note = "Use `sql_function!` instead. See `CHANGELOG.md` for migration instructions"
76+
note = "Use `sql_function_v2!` instead. See `CHANGELOG.md` for migration instructions"
7777
)]
7878
#[cfg(all(feature = "with-deprecated", not(feature = "without-deprecated")))]
7979
macro_rules! no_arg_sql_function {

diesel/src/expression/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) mod dsl {
7070
pub use crate::pg::expression::dsl::*;
7171

7272
/// The return type of [`count(expr)`](crate::dsl::count())
73-
pub type count<Expr> = super::count::count::HelperType<SqlTypeOf<Expr>, Expr>;
73+
pub type count<Expr> = super::count::count<SqlTypeOf<Expr>, Expr>;
7474

7575
/// The return type of [`count_star()`](crate::dsl::count_star())
7676
pub type count_star = super::count::CountStar;
@@ -79,7 +79,7 @@ pub(crate) mod dsl {
7979
pub type count_distinct<Expr> = super::count::CountDistinct<SqlTypeOf<Expr>, Expr>;
8080

8181
/// The return type of [`date(expr)`](crate::dsl::date())
82-
pub type date<Expr> = super::functions::date_and_time::date::HelperType<Expr>;
82+
pub type date<Expr> = super::functions::date_and_time::date<Expr>;
8383

8484
#[cfg(feature = "mysql_backend")]
8585
pub use crate::mysql::query_builder::DuplicatedKeys;

diesel/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//! They live in [the `dsl` module](dsl).
5858
//! Diesel only supports a very small number of these functions.
5959
//! You can declare additional functions you want to use
60-
//! with [the `sql_function!` macro][`sql_function!`].
60+
//! with [the `sql_function_v2!` macro][`sql_function_v2!`].
6161
//!
6262
//! [`std::ops`]: //doc.rust-lang.org/stable/std/ops/index.html
6363
//!
@@ -639,7 +639,7 @@ pub mod prelude {
639639
};
640640

641641
#[doc(inline)]
642-
pub use crate::expression::functions::sql_function;
642+
pub use crate::expression::functions::{sql_function, sql_function_v2};
643643

644644
#[doc(inline)]
645645
pub use crate::expression::SelectableHelper;

diesel/src/pg/connection/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ mod tests {
489489
assert_eq!(2, connection.statement_cache.len());
490490
}
491491

492-
sql_function!(fn lower(x: VarChar) -> VarChar);
492+
sql_function_v2!(fn lower(x: VarChar) -> VarChar);
493493

494494
#[test]
495495
fn queries_with_identical_types_and_binds_but_different_sql_are_cached_separately() {

diesel/src/pg/expression/functions.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
//! PostgreSQL specific functions
22
33
use super::expression_methods::InetOrCidr;
4-
use crate::expression::functions::sql_function;
4+
use crate::expression::functions::sql_function_v2;
55
use crate::sql_types::*;
66

7-
sql_function! {
7+
sql_function_v2! {
88
/// Creates an abbreviated display format as text.
99
#[cfg(feature = "postgres_backend")]
1010
fn abbrev<T: InetOrCidr + SingleValue>(addr: T) -> Text;
1111
}
12-
sql_function! {
12+
sql_function_v2! {
1313
/// Computes the broadcast address for the address's network.
1414
#[cfg(feature = "postgres_backend")]
1515
fn broadcast<T: InetOrCidr + SingleValue>(addr: T) -> Inet;
1616
}
17-
sql_function! {
17+
sql_function_v2! {
1818
/// Returns the address's family: 4 for IPv4, 6 for IPv6.
1919
#[cfg(feature = "postgres_backend")]
2020
fn family<T: InetOrCidr + SingleValue>(addr: T) -> Integer;
2121
}
22-
sql_function! {
22+
sql_function_v2! {
2323
/// Returns the IP address as text, ignoring the netmask.
2424
#[cfg(feature = "postgres_backend")]
2525
fn host<T: InetOrCidr + SingleValue>(addr: T) -> Text;
2626
}
27-
sql_function! {
27+
sql_function_v2! {
2828
/// Computes the host mask for the address's network.
2929
#[cfg(feature = "postgres_backend")]
3030
fn hostmask<T: InetOrCidr + SingleValue>(addr: T) -> Inet;
3131
}
32-
sql_function! {
32+
sql_function_v2! {
3333
/// Computes the smallest network that includes both of the given networks.
3434
#[cfg(feature = "postgres_backend")]
3535
fn inet_merge<T: InetOrCidr + SingleValue, U: InetOrCidr + SingleValue>(a: T, b: U) -> Cidr;
3636
}
37-
sql_function! {
37+
sql_function_v2! {
3838
/// Tests whether the addresses belong to the same IP family.
3939
#[cfg(feature = "postgres_backend")]
4040
fn inet_same_family<T: InetOrCidr + SingleValue, U: InetOrCidr + SingleValue>(a: T, b: U) -> Bool;
4141
}
42-
sql_function! {
42+
sql_function_v2! {
4343
/// Returns the netmask length in bits.
4444
#[cfg(feature = "postgres_backend")]
4545
fn masklen<T: InetOrCidr + SingleValue>(addr: T) -> Integer;
4646
}
47-
sql_function! {
47+
sql_function_v2! {
4848
/// Computes the network mask for the address's network.
4949
#[cfg(feature = "postgres_backend")]
5050
fn netmask<T: InetOrCidr + SingleValue>(addr: T) -> Inet;
5151
}
52-
sql_function! {
52+
sql_function_v2! {
5353
/// Returns the network part of the address, zeroing out whatever is to the right of the
5454
/// netmask. (This is equivalent to casting the value to cidr.)
5555
#[cfg(feature = "postgres_backend")]
5656
fn network<T: InetOrCidr + SingleValue>(addr: T) -> Cidr;
5757
}
58-
sql_function! {
58+
sql_function_v2! {
5959
/// Sets the netmask length for an inet or cidr value.
6060
/// For inet, the address part does not changes. For cidr, address bits to the right of the new
6161
/// netmask are set to zero.

diesel/src/pg/metadata_lookup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ table! {
214214
joinable!(pg_type -> pg_namespace(typnamespace));
215215
allow_tables_to_appear_in_same_query!(pg_type, pg_namespace);
216216

217-
sql_function! { fn pg_my_temp_schema() -> Oid; }
217+
sql_function_v2! { fn pg_my_temp_schema() -> Oid; }

diesel/src/sqlite/connection/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ mod tests {
486486
}
487487

488488
use crate::sql_types::Text;
489-
sql_function!(fn fun_case(x: Text) -> Text);
489+
sql_function_v2!(fn fun_case(x: Text) -> Text);
490490

491491
#[test]
492492
fn register_custom_function() {
@@ -511,7 +511,7 @@ mod tests {
511511
assert_eq!("fOoBaR", mapped_string);
512512
}
513513

514-
sql_function!(fn my_add(x: Integer, y: Integer) -> Integer);
514+
sql_function_v2!(fn my_add(x: Integer, y: Integer) -> Integer);
515515

516516
#[test]
517517
fn register_multiarg_function() {
@@ -522,7 +522,7 @@ mod tests {
522522
assert_eq!(Ok(3), added);
523523
}
524524

525-
sql_function!(fn answer() -> Integer);
525+
sql_function_v2!(fn answer() -> Integer);
526526

527527
#[test]
528528
fn register_noarg_function() {
@@ -542,7 +542,7 @@ mod tests {
542542
assert_eq!(Ok(42), answer);
543543
}
544544

545-
sql_function!(fn add_counter(x: Integer) -> Integer);
545+
sql_function_v2!(fn add_counter(x: Integer) -> Integer);
546546

547547
#[test]
548548
fn register_nondeterministic_function() {
@@ -561,7 +561,7 @@ mod tests {
561561

562562
use crate::sqlite::SqliteAggregateFunction;
563563

564-
sql_function! {
564+
sql_function_v2! {
565565
#[aggregate]
566566
fn my_sum(expr: Integer) -> Integer;
567567
}
@@ -631,7 +631,7 @@ mod tests {
631631
assert_eq!(Ok(0), result);
632632
}
633633

634-
sql_function! {
634+
sql_function_v2! {
635635
#[aggregate]
636636
fn range_max(expr1: Integer, expr2: Integer, expr3: Integer) -> Nullable<Integer>;
637637
}

diesel/src/sqlite/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub use self::query_builder::SqliteQueryBuilder;
2020

2121
/// Trait for the implementation of a SQLite aggregate function
2222
///
23-
/// This trait is to be used in conjunction with the `sql_function!`
23+
/// This trait is to be used in conjunction with the `sql_function_v2!`
2424
/// macro for defining a custom SQLite aggregate function. See
25-
/// the documentation [there](super::prelude::sql_function!) for details.
25+
/// the documentation [there](super::prelude::sql_function_v2!) for details.
2626
pub trait SqliteAggregateFunction<Args>: Default {
2727
/// The result type of the SQLite aggregate function
2828
type Output;

diesel/src/sqlite/types/date_and_time/chrono.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ mod tests {
249249
use crate::sql_types::{Text, Time, Timestamp, TimestamptzSqlite};
250250
use crate::test_helpers::connection;
251251

252-
sql_function!(fn datetime(x: Text) -> Timestamp);
253-
sql_function!(fn time(x: Text) -> Time);
254-
sql_function!(fn date(x: Text) -> Date);
252+
sql_function_v2!(fn datetime(x: Text) -> Timestamp);
253+
sql_function_v2!(fn time(x: Text) -> Time);
254+
sql_function_v2!(fn date(x: Text) -> Date);
255255

256256
#[test]
257257
fn unix_epoch_encodes_correctly() {

diesel/src/sqlite/types/date_and_time/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ mod tests {
275275
use crate::sql_types::{Text, Time, Timestamp, TimestamptzSqlite};
276276
use crate::test_helpers::connection;
277277

278-
sql_function!(fn datetime(x: Text) -> Timestamp);
279-
sql_function!(fn time(x: Text) -> Time);
280-
sql_function!(fn date(x: Text) -> Date);
278+
sql_function_v2!(fn datetime(x: Text) -> Timestamp);
279+
sql_function_v2!(fn time(x: Text) -> Time);
280+
sql_function_v2!(fn date(x: Text) -> Date);
281281

282282
#[test]
283283
fn unix_epoch_encodes_correctly() {

diesel_cli/src/infer_schema_internals/information_schema.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl DefaultSchema for Pg {
3232
}
3333

3434
#[cfg(feature = "mysql")]
35-
sql_function!(fn database() -> VarChar);
35+
sql_function_v2!(fn database() -> VarChar);
3636

3737
#[cfg(feature = "mysql")]
3838
impl DefaultSchema for Mysql {

diesel_cli/src/infer_schema_internals/mysql.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::information_schema::DefaultSchema;
1010
use super::table_data::TableName;
1111
use crate::print_schema::ColumnSorting;
1212

13-
diesel::sql_function! {
13+
diesel::sql_function_v2! {
1414
#[sql_name = "NULLIF"]
1515
fn null_if_text(lhs: sql_types::Text, rhs: sql_types::Text) -> sql_types::Nullable<sql_types::Text>
1616
}

diesel_cli/src/infer_schema_internals/pg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn regclass(table: &TableName) -> Regclass<AsExprOf<String, sql_types::Text>> {
7171
))
7272
}
7373

74-
diesel::sql_function!(fn col_description(table: sql_types::Oid, column_number: sql_types::BigInt) -> sql_types::Nullable<sql_types::Text>);
74+
diesel::sql_function_v2!(fn col_description(table: sql_types::Oid, column_number: sql_types::BigInt) -> sql_types::Nullable<sql_types::Text>);
7575

7676
pub fn get_table_data(
7777
conn: &mut PgConnection,
@@ -140,7 +140,7 @@ where
140140
}
141141
}
142142

143-
sql_function!(fn obj_description(oid: sql_types::Oid, catalog: sql_types::Text) -> Nullable<Text>);
143+
sql_function_v2!(fn obj_description(oid: sql_types::Oid, catalog: sql_types::Text) -> Nullable<Text>);
144144

145145
pub fn get_table_comment(
146146
conn: &mut PgConnection,
@@ -167,7 +167,7 @@ mod information_schema {
167167
}
168168
}
169169

170-
sql_function! {
170+
sql_function_v2! {
171171
#[aggregate]
172172
fn array_agg(input: diesel::sql_types::Text) -> diesel::sql_types::Array<diesel::sql_types::Text>;
173173
}

diesel_compile_tests/tests/fail/cannot_mix_aggregate_and_non_aggregate_selects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ table! {
1111
}
1212
}
1313

14-
sql_function!(fn f(x: Nullable<Integer>, y: Nullable<Integer>) -> Nullable<Integer>);
14+
sql_function_v2!(fn f(x: Nullable<Integer>, y: Nullable<Integer>) -> Nullable<Integer>);
1515

1616
fn main() {
1717
use self::users::dsl::*;

diesel_compile_tests/tests/fail/cannot_mix_aggregate_and_non_aggregate_selects.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ error[E0277]: the trait bound `diesel::expression::is_aggregate::No: MixedAggreg
3434
note: required for `__Derived<nullable_int_col, max<Nullable<Integer>, nullable_int_col>>` to implement `ValidGrouping<()>`
3535
--> tests/fail/cannot_mix_aggregate_and_non_aggregate_selects.rs:14:1
3636
|
37-
14 | sql_function!(fn f(x: Nullable<Integer>, y: Nullable<Integer>) -> Nullable<Integer>);
37+
14 | sql_function_v2!(fn f(x: Nullable<Integer>, y: Nullable<Integer>) -> Nullable<Integer>);
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
3939
= note: 1 redundant requirement hidden
4040
= note: required for `f<nullable_int_col, max<Nullable<Integer>, nullable_int_col>>` to implement `ValidGrouping<()>`
4141
= note: required for `SelectStatement<FromClause<users::table>>` to implement `SelectDsl<f::f<columns::nullable_int_col, diesel::expression::functions::aggregate_ordering::max::max<diesel::sql_types::Nullable<diesel::sql_types::Integer>, columns::nullable_int_col>>>`
42-
= note: this error originates in the macro `sql_function` which comes from the expansion of the derive macro `ValidGrouping` (in Nightly builds, run with -Z macro-backtrace for more info)
42+
= note: this error originates in the macro `sql_function_v2` which comes from the expansion of the derive macro `ValidGrouping` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)