From 9c250911d17c0c65513fc46d1fe0998c3c25ed34 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 12:12:24 +0500 Subject: [PATCH 01/21] implement array_dims --- diesel/src/pg/expression/functions.rs | 31 ++++++++++++++++++++++++ diesel/src/pg/expression/helper_types.rs | 5 ++++ diesel_derives/tests/auto_type.rs | 1 + 3 files changed, 37 insertions(+) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 0b7bfa9eb989..2adf03cf1b4f 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -748,3 +748,34 @@ define_sql_function! { /// ``` fn array_append + SingleValue, T: SingleValue>(a: Arr, e: T) -> Array; } + +#[cfg(feature = "postgres_backend")] +define_sql_function! { + /// Returns a text representation of the array's dimensions + /// + /// # Example + /// + /// ```rust + /// # include!("../../doctest_setup.rs"); + /// # + /// # fn main(){ + /// # run_test().unwrap(); + /// # } + /// # fn run_test()->QueryResult<()>{ + /// # use diesel::dsl::array_dims; + /// # use diesel::sql_types::{Nullable,Array,Integer}; + /// # let connection = &mut establish_connection(); + /// + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection); + /// assert!(String::from("[1:2]").eq(&dims)); + /// + /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// .get_result::(connection); + /// assert!(String::from("[1:2][1:3]").eq(&dims)); + /// + /// # Ok(()) + /// # } + /// + fn array_dims(arr:Arr) -> Text; +} diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 5bcaadfc3e98..0f61bef7b6e0 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -352,3 +352,8 @@ pub type range_merge = super::functions::range_merge, SqlT #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] pub type array_append = super::functions::array_append, SqlTypeOf, A, E>; + +/// Return type of [`array_dims(array)`](super::functions::array_append()) +#[allow(non_camel_case_types)] +#[cfg(feature = "postgres_backend")] +pub type array_dims = super::functions::array_dims, A>; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index dc2c91c50c11..1e09ea64a6ed 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -411,6 +411,7 @@ fn postgres_functions() -> _ { bound, ), array_append(pg_extras::array, pg_extras::id), + array_dims(pg_extras::array) ) } From 27bc1d60d107e64aa5f07e2c6ee3be0b1f44c539 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:23:41 +0500 Subject: [PATCH 02/21] fixed doc test --- .idea/.gitignore | 5 ++ .idea/diesel.iml | 54 +++++++++++++++++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 4 +- diesel_compile_tests/Cargo.lock | 11 +++- .../numeric_ops_require_numeric_column.stderr | 3 ++ 8 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/diesel.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000000..b58b603fea78 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml new file mode 100644 index 000000000000..cec84ce8e8c6 --- /dev/null +++ b/.idea/diesel.iml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000000..54c7d60e5b26 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000000..35eb1ddfbbc0 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 91c0120d56d8..97cb7f9fa94b 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } +mysqlclient-sys = { version = "0.4.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 2adf03cf1b4f..f00776f01f54 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -767,11 +767,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index f0856d0eee0b..5c211c704d53 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,6 +137,7 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", + "downcast-rs", "ipnetwork", "itoa", "libc", @@ -180,6 +181,12 @@ dependencies = [ "syn", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -356,9 +363,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" +checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index cb1cb547e6b2..53acf55fb277 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,3 +13,6 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs + | + | pub trait Add { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ From d5806107c30044a116e0008e4a5aee57027c7590 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:25:06 +0500 Subject: [PATCH 03/21] Revert "fixed doc test" This reverts commit 27bc1d60d107e64aa5f07e2c6ee3be0b1f44c539. --- .idea/.gitignore | 5 -- .idea/diesel.iml | 54 ------------------- .idea/modules.xml | 8 --- .idea/vcs.xml | 6 --- diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 4 +- diesel_compile_tests/Cargo.lock | 11 +--- .../numeric_ops_require_numeric_column.stderr | 3 -- 8 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/diesel.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603fea78..000000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml deleted file mode 100644 index cec84ce8e8c6..000000000000 --- a/.idea/diesel.iml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 54c7d60e5b26..000000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfbbc0..000000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 97cb7f9fa94b..91c0120d56d8 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = "0.4.0", optional = true } +mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index f00776f01f54..2adf03cf1b4f 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -767,11 +767,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index 5c211c704d53..f0856d0eee0b 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,7 +137,6 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", - "downcast-rs", "ipnetwork", "itoa", "libc", @@ -181,12 +180,6 @@ dependencies = [ "syn", ] -[[package]] -name = "downcast-rs" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" - [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -363,9 +356,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.4.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" +checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index 53acf55fb277..cb1cb547e6b2 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,6 +13,3 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs - | - | pub trait Add { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ From bf30144d0f0fc462fcde687ae2aac1dc5b0524ed Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:28:18 +0500 Subject: [PATCH 04/21] fixed doc test --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 2adf03cf1b4f..f00776f01f54 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -767,11 +767,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) From f7a7f62f4685fc5f70c88ca5d090265b2c7c2724 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 15:59:20 +0500 Subject: [PATCH 05/21] doctest fix --- diesel/src/pg/expression/functions.rs | 6 +++--- diesel/src/pg/expression/helper_types.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index f00776f01f54..dec2dbbb5bb1 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -766,16 +766,16 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) /// # } /// - fn array_dims(arr:Arr) -> Text; + fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 0f61bef7b6e0..65ad46214910 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -356,4 +356,4 @@ pub type array_append = super::functions::array_append, SqlTy /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims, A>; +pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; From 1e3b9d765b7741d76df1dfaf6ada7709ed0ae457 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 13:44:51 +0500 Subject: [PATCH 06/21] fixed doc test and added new doc tests for None --- diesel/src/pg/expression/functions.rs | 15 +++++++++------ diesel/src/pg/expression/helper_types.rs | 2 +- diesel_derives/tests/auto_type.rs | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index dec2dbbb5bb1..fbca87785b45 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -766,16 +766,19 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); - /// assert!(String::from("[1:2][1:3]").eq(&dims)); + /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:2]").eq(&dims)); /// + /// let dims = diesel::select(array_dims::,_>(vec![None::])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(()) /// # } /// - fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; + fn array_dims + SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 65ad46214910..0f61bef7b6e0 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -356,4 +356,4 @@ pub type array_append = super::functions::array_append, SqlTy /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; +pub type array_dims = super::functions::array_dims, A>; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index 1e09ea64a6ed..1c6ccbc15ba0 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -411,7 +411,7 @@ fn postgres_functions() -> _ { bound, ), array_append(pg_extras::array, pg_extras::id), - array_dims(pg_extras::array) + array_dims(pg_extras::array), ) } From 02c080c06faf62ab18ea2987cd59144913643ea3 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 14:10:39 +0500 Subject: [PATCH 07/21] doctest fix --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index fbca87785b45..303b531c5d78 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -770,11 +770,11 @@ define_sql_function! { /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::])) /// .get_result::(connection)?; /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(()) From d02ecb452e8d4cb8e8714cc40b0a74400e963cc1 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 12:12:24 +0500 Subject: [PATCH 08/21] implement array_dims --- diesel/src/pg/expression/functions.rs | 36 +++++++++++++++++++++++- diesel/src/pg/expression/helper_types.rs | 5 ++++ diesel_derives/tests/auto_type.rs | 3 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 1f0fbe95ba50..c2971794f85e 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -776,7 +776,7 @@ define_sql_function! { /// /// let ints = diesel::select(array_replace::>, Integer, _, _, _>(None::>, 1, 2)) /// .get_result::>>(connection)?; - /// + /// /// let ints = diesel::select(array_replace::>, Nullable, _, _, _>(None::>, None::, Some(1))) /// .get_result::>>>(connection)?; /// assert_eq!(None, ints); @@ -785,3 +785,37 @@ define_sql_function! { /// ``` fn array_replace + SingleValue, T: SingleValue>(a: Arr, e: T, r: T) -> Arr; } + +#[cfg(feature = "postgres_backend")] +define_sql_function! { + /// Returns a text representation of the array's dimensions + /// + /// # Example + /// + /// ```rust + /// # include!("../../doctest_setup.rs"); + /// # + /// # fn main(){ + /// # run_test().unwrap(); + /// # } + /// # fn run_test()->QueryResult<()>{ + /// # use diesel::dsl::array_dims; + /// # use diesel::sql_types::{Nullable,Array,Integer}; + /// # let connection = &mut establish_connection(); + /// + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:2]").eq(&dims)); + /// + /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:2]").eq(&dims)); + /// + /// let dims = diesel::select(array_dims::>,_>(vec![None::])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:1]").eq(&dims)); + /// # Ok(()) + /// # } + /// + fn array_dims + SingleValue>(arr:Arr) -> Text; +} diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 0a582ba1ebfc..105c58029a70 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -357,3 +357,8 @@ pub type array_append = super::functions::array_append, SqlTy #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] pub type array_replace = super::functions::array_replace, SqlTypeOf, A, E, R>; + +/// Return type of [`array_dims(array)`](super::functions::array_append()) +#[allow(non_camel_case_types)] +#[cfg(feature = "postgres_backend")] +pub type array_dims = super::functions::array_dims, A>; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index c556e2f10b32..651dc5b3f311 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -411,7 +411,8 @@ fn postgres_functions() -> _ { bound, ), array_append(pg_extras::array, pg_extras::id), - array_replace(pg_extras::array, pg_extras::id, pg_extras::id) + array_replace(pg_extras::array, pg_extras::id, pg_extras::id), + array_dims(pg_extras::array) ) } From 10ab6bd497ebd42ef4ee670f1f9d7ffb44975dd4 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:23:41 +0500 Subject: [PATCH 09/21] fixed doc test --- .idea/.gitignore | 5 ++ .idea/diesel.iml | 54 +++++++++++++++++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 7 +++ diesel_compile_tests/Cargo.lock | 11 +++- .../numeric_ops_require_numeric_column.stderr | 3 ++ 8 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/diesel.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000000..b58b603fea78 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml new file mode 100644 index 000000000000..cec84ce8e8c6 --- /dev/null +++ b/.idea/diesel.iml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000000..54c7d60e5b26 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000000..35eb1ddfbbc0 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 91c0120d56d8..97cb7f9fa94b 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } +mysqlclient-sys = { version = "0.4.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index c2971794f85e..697ef08aea32 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -810,6 +810,13 @@ define_sql_function! { /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection).unwrap(); + /// assert!(String::from("[1:2]").eq(&dims)); + /// + /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// .get_result::(connection).unwrap(); + /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// let dims = diesel::select(array_dims::>,_>(vec![None::])) /// .get_result::(connection)?; diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index f0856d0eee0b..5c211c704d53 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,6 +137,7 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", + "downcast-rs", "ipnetwork", "itoa", "libc", @@ -180,6 +181,12 @@ dependencies = [ "syn", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -356,9 +363,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" +checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index cb1cb547e6b2..53acf55fb277 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,3 +13,6 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs + | + | pub trait Add { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ From 3e17a01fff8e769d7033e6e7a6bb4b280f679d50 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:25:06 +0500 Subject: [PATCH 10/21] Revert "fixed doc test" This reverts commit 27bc1d60d107e64aa5f07e2c6ee3be0b1f44c539. --- .idea/.gitignore | 5 -- .idea/diesel.iml | 54 ------------------- .idea/modules.xml | 8 --- .idea/vcs.xml | 6 --- diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 4 +- diesel_compile_tests/Cargo.lock | 11 +--- .../numeric_ops_require_numeric_column.stderr | 3 -- 8 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/diesel.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603fea78..000000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml deleted file mode 100644 index cec84ce8e8c6..000000000000 --- a/.idea/diesel.iml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 54c7d60e5b26..000000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfbbc0..000000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 97cb7f9fa94b..91c0120d56d8 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = "0.4.0", optional = true } +mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 697ef08aea32..439fe1c2d8bf 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -811,11 +811,11 @@ define_sql_function! { /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// let dims = diesel::select(array_dims::>,_>(vec![None::])) diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index 5c211c704d53..f0856d0eee0b 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,7 +137,6 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", - "downcast-rs", "ipnetwork", "itoa", "libc", @@ -181,12 +180,6 @@ dependencies = [ "syn", ] -[[package]] -name = "downcast-rs" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" - [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -363,9 +356,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.4.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" +checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index 53acf55fb277..cb1cb547e6b2 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,6 +13,3 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs - | - | pub trait Add { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ From 7ed50b5631d152646113336d409442208ea3ba4a Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:28:18 +0500 Subject: [PATCH 11/21] fixed doc test --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 439fe1c2d8bf..697ef08aea32 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -811,11 +811,11 @@ define_sql_function! { /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// let dims = diesel::select(array_dims::>,_>(vec![None::])) From 144a765806099f7d3d22adddb7cf0ad1382d35f5 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 15:59:20 +0500 Subject: [PATCH 12/21] doctest fix --- diesel/src/pg/expression/functions.rs | 13 +++---------- diesel/src/pg/expression/helper_types.rs | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 697ef08aea32..c896927aeb9a 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -803,18 +803,11 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection)?; - /// assert!(String::from("[1:2]").eq(&dims)); - /// - /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) - /// .get_result::(connection)?; - /// assert!(String::from("[1:2]").eq(&dims)); - /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// @@ -824,5 +817,5 @@ define_sql_function! { /// # Ok(()) /// # } /// - fn array_dims + SingleValue>(arr:Arr) -> Text; + fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 105c58029a70..d64adba0356e 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -361,4 +361,4 @@ pub type array_replace = super::functions::array_replace, /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims, A>; +pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; From d301cf968a1118b823111bf063ab484021841c82 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 13:44:51 +0500 Subject: [PATCH 13/21] fixed doc test and added new doc tests for None --- diesel/src/pg/expression/functions.rs | 14 +++++++------- diesel/src/pg/expression/helper_types.rs | 2 +- diesel_derives/tests/auto_type.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index c896927aeb9a..11dba8437de5 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -803,19 +803,19 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); - /// assert!(String::from("[1:2][1:3]").eq(&dims)); + /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::>,_>(vec![None::])) + /// let dims = diesel::select(array_dims::,_>(vec![None::])) /// .get_result::(connection)?; /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(()) /// # } /// - fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; + fn array_dims + SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index d64adba0356e..105c58029a70 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -361,4 +361,4 @@ pub type array_replace = super::functions::array_replace, /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; +pub type array_dims = super::functions::array_dims, A>; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index 651dc5b3f311..fb37ca58b625 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -412,7 +412,7 @@ fn postgres_functions() -> _ { ), array_append(pg_extras::array, pg_extras::id), array_replace(pg_extras::array, pg_extras::id, pg_extras::id), - array_dims(pg_extras::array) + array_dims(pg_extras::array), ) } From 04c6dacdb9c241ec32258d6d7af6b61834378827 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 14:10:39 +0500 Subject: [PATCH 14/21] doctest fix --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 11dba8437de5..c2971794f85e 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -807,11 +807,11 @@ define_sql_function! { /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::])) /// .get_result::(connection)?; /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(()) From 03b996e84b9dc0bd90125975a39c528d7da87c00 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 12:12:24 +0500 Subject: [PATCH 15/21] implement array_dims --- diesel/src/pg/expression/functions.rs | 31 ++++++++++++++++++++++++ diesel/src/pg/expression/helper_types.rs | 5 ++++ diesel_derives/tests/auto_type.rs | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 1f0fbe95ba50..150b4aa805f0 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -785,3 +785,34 @@ define_sql_function! { /// ``` fn array_replace + SingleValue, T: SingleValue>(a: Arr, e: T, r: T) -> Arr; } + +#[cfg(feature = "postgres_backend")] +define_sql_function! { + /// Returns a text representation of the array's dimensions + /// + /// # Example + /// + /// ```rust + /// # include!("../../doctest_setup.rs"); + /// # + /// # fn main(){ + /// # run_test().unwrap(); + /// # } + /// # fn run_test()->QueryResult<()>{ + /// # use diesel::dsl::array_dims; + /// # use diesel::sql_types::{Nullable,Array,Integer}; + /// # let connection = &mut establish_connection(); + /// + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection); + /// assert!(String::from("[1:2]").eq(&dims)); + /// + /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// .get_result::(connection); + /// assert!(String::from("[1:2][1:3]").eq(&dims)); + /// + /// # Ok(()) + /// # } + /// + fn array_dims(arr:Arr) -> Text; +} diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 0a582ba1ebfc..105c58029a70 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -357,3 +357,8 @@ pub type array_append = super::functions::array_append, SqlTy #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] pub type array_replace = super::functions::array_replace, SqlTypeOf, A, E, R>; + +/// Return type of [`array_dims(array)`](super::functions::array_append()) +#[allow(non_camel_case_types)] +#[cfg(feature = "postgres_backend")] +pub type array_dims = super::functions::array_dims, A>; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index c556e2f10b32..fb37ca58b625 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -411,7 +411,8 @@ fn postgres_functions() -> _ { bound, ), array_append(pg_extras::array, pg_extras::id), - array_replace(pg_extras::array, pg_extras::id, pg_extras::id) + array_replace(pg_extras::array, pg_extras::id, pg_extras::id), + array_dims(pg_extras::array), ) } From eeb3f9b23d042114db1624a329f1645c649670a0 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:23:41 +0500 Subject: [PATCH 16/21] fixed doc test --- .idea/.gitignore | 5 ++ .idea/diesel.iml | 54 +++++++++++++++++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 4 +- diesel_compile_tests/Cargo.lock | 11 +++- .../numeric_ops_require_numeric_column.stderr | 3 ++ 8 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/diesel.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000000..b58b603fea78 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml new file mode 100644 index 000000000000..cec84ce8e8c6 --- /dev/null +++ b/.idea/diesel.iml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000000..54c7d60e5b26 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000000..35eb1ddfbbc0 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 91c0120d56d8..97cb7f9fa94b 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } +mysqlclient-sys = { version = "0.4.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 150b4aa805f0..503177d96fc3 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -804,11 +804,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index f0856d0eee0b..5c211c704d53 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,6 +137,7 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", + "downcast-rs", "ipnetwork", "itoa", "libc", @@ -180,6 +181,12 @@ dependencies = [ "syn", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -356,9 +363,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" +checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index cb1cb547e6b2..53acf55fb277 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,3 +13,6 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs + | + | pub trait Add { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ From c23160bfdabff3e157ce9a9146effdadd6647637 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:25:06 +0500 Subject: [PATCH 17/21] Revert "fixed doc test" This reverts commit 27bc1d60d107e64aa5f07e2c6ee3be0b1f44c539. --- .idea/.gitignore | 5 -- .idea/diesel.iml | 54 ------------------- .idea/modules.xml | 8 --- .idea/vcs.xml | 6 --- diesel/Cargo.toml | 2 +- diesel/src/pg/expression/functions.rs | 4 +- diesel_compile_tests/Cargo.lock | 11 +--- .../numeric_ops_require_numeric_column.stderr | 3 -- 8 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/diesel.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603fea78..000000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/diesel.iml b/.idea/diesel.iml deleted file mode 100644 index cec84ce8e8c6..000000000000 --- a/.idea/diesel.iml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 54c7d60e5b26..000000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfbbc0..000000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 97cb7f9fa94b..91c0120d56d8 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -25,7 +25,7 @@ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.17.2, <0.30.0", optional = true, features = ["bundled_bindings"] } -mysqlclient-sys = { version = "0.4.0", optional = true } +mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.7.0", optional = true } pq-src = { version = "0.3", optional = true } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 503177d96fc3..150b4aa805f0 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -804,11 +804,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); + /// .get_result::(connection); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) diff --git a/diesel_compile_tests/Cargo.lock b/diesel_compile_tests/Cargo.lock index 5c211c704d53..f0856d0eee0b 100644 --- a/diesel_compile_tests/Cargo.lock +++ b/diesel_compile_tests/Cargo.lock @@ -137,7 +137,6 @@ dependencies = [ "byteorder", "chrono", "diesel_derives", - "downcast-rs", "ipnetwork", "itoa", "libc", @@ -181,12 +180,6 @@ dependencies = [ "syn", ] -[[package]] -name = "downcast-rs" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" - [[package]] name = "dsl_auto_type" version = "0.1.0" @@ -363,9 +356,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mysqlclient-sys" -version = "0.4.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa3a303b6e9878b34811838301b00a56878693c47f9ac0ba397f91adc7bf12" +checksum = "bd59c034806974df483883503e8a019b1a0137b0e60dd64811537ab56312ad2d" dependencies = [ "pkg-config", "vcpkg", diff --git a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr index 53acf55fb277..cb1cb547e6b2 100644 --- a/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr +++ b/diesel_compile_tests/tests/fail/numeric_ops_require_numeric_column.stderr @@ -13,6 +13,3 @@ note: an implementation of `std::ops::Add` might be missing for `columns::name` | ^^^^ must implement `std::ops::Add` note: the trait `std::ops::Add` must be implemented --> $RUST/core/src/ops/arith.rs - | - | pub trait Add { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ From a0de4eabdb3a4b5f8d0f155374bddc9607cb4fa0 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 14:28:18 +0500 Subject: [PATCH 18/21] fixed doc test --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 150b4aa805f0..503177d96fc3 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -804,11 +804,11 @@ define_sql_function! { /// # let connection = &mut establish_connection(); /// /// let dims = diesel::select(array_dims::,_>(vec![1,2])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection); + /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) From 930759ef2626877be4450ed33c089a73ffb1dc3a Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Thu, 22 Aug 2024 15:59:20 +0500 Subject: [PATCH 19/21] doctest fix --- diesel/src/pg/expression/functions.rs | 6 +++--- diesel/src/pg/expression/helper_types.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 503177d96fc3..c11ecfa1d4a4 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -803,16 +803,16 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![vec![1,2,3],vec![4,5,6]])) + /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) /// .get_result::(connection).unwrap(); /// assert!(String::from("[1:2][1:3]").eq(&dims)); /// /// # Ok(()) /// # } /// - fn array_dims(arr:Arr) -> Text; + fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index 105c58029a70..d64adba0356e 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -361,4 +361,4 @@ pub type array_replace = super::functions::array_replace, /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims, A>; +pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; From b82895044d8f141e46a292a995603e057c59d0ed Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 13:44:51 +0500 Subject: [PATCH 20/21] fixed doc test and added new doc tests for None --- diesel/src/pg/expression/functions.rs | 15 +++++++++------ diesel/src/pg/expression/helper_types.rs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index c11ecfa1d4a4..07e9aaa13632 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -803,16 +803,19 @@ define_sql_function! { /// # use diesel::sql_types::{Nullable,Array,Integer}; /// # let connection = &mut establish_connection(); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![1,2])) - /// .get_result::(connection).unwrap(); + /// let dims = diesel::select(array_dims::,_>(vec![1,2])) + /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_,_>(vec![vec![1,2,3],vec![4,5,6]])) - /// .get_result::(connection).unwrap(); - /// assert!(String::from("[1:2][1:3]").eq(&dims)); + /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:2]").eq(&dims)); /// + /// let dims = diesel::select(array_dims::,_>(vec![None::])) + /// .get_result::(connection)?; + /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(()) /// # } /// - fn array_dims + SingleValue,T:SingleValue>(arr:Arr) -> Text; + fn array_dims + SingleValue>(arr:Arr) -> Text; } diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index d64adba0356e..105c58029a70 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -361,4 +361,4 @@ pub type array_replace = super::functions::array_replace, /// Return type of [`array_dims(array)`](super::functions::array_append()) #[allow(non_camel_case_types)] #[cfg(feature = "postgres_backend")] -pub type array_dims = super::functions::array_dims,SqlTypeOf, A>; +pub type array_dims = super::functions::array_dims, A>; From f091f57146a50dc7be3970eac7249ec54f5b38e2 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 23 Aug 2024 14:10:39 +0500 Subject: [PATCH 21/21] doctest fix --- diesel/src/pg/expression/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 07e9aaa13632..494dc174dfe3 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -807,11 +807,11 @@ define_sql_function! { /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::,Some(2)])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::,Some(2)])) /// .get_result::(connection)?; /// assert!(String::from("[1:2]").eq(&dims)); /// - /// let dims = diesel::select(array_dims::,_>(vec![None::])) + /// let dims = diesel::select(array_dims::>,_>(vec![None::])) /// .get_result::(connection)?; /// assert!(String::from("[1:1]").eq(&dims)); /// # Ok(())