From 61c8c3881f52f2875d65ee319e3ad7c95e34d11c Mon Sep 17 00:00:00 2001 From: Xue Haonan Date: Thu, 12 Dec 2024 00:51:33 +0800 Subject: [PATCH 1/6] add SQLite functions `json` and `jsonb` --- diesel/src/expression/mod.rs | 3 + .../sqlite/expression/expression_methods.rs | 26 ++++ diesel/src/sqlite/expression/functions.rs | 114 ++++++++++++++++++ diesel/src/sqlite/expression/helper_types.rs | 12 +- diesel/src/sqlite/expression/mod.rs | 11 ++ diesel/src/sqlite/mod.rs | 2 +- diesel_derives/tests/auto_type.rs | 22 ++++ 7 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 diesel/src/sqlite/expression/functions.rs diff --git a/diesel/src/expression/mod.rs b/diesel/src/expression/mod.rs index 9d0d127eb4b7..4c4a2c126729 100644 --- a/diesel/src/expression/mod.rs +++ b/diesel/src/expression/mod.rs @@ -74,6 +74,9 @@ pub(crate) mod dsl { #[cfg(feature = "postgres_backend")] pub use crate::pg::expression::dsl::*; + #[cfg(feature = "sqlite")] + pub use crate::sqlite::expression::dsl::*; + /// The return type of [`count(expr)`](crate::dsl::count()) pub type count = super::count::count, Expr>; diff --git a/diesel/src/sqlite/expression/expression_methods.rs b/diesel/src/sqlite/expression/expression_methods.rs index 1708c4975b43..f4f80c724a07 100644 --- a/diesel/src/sqlite/expression/expression_methods.rs +++ b/diesel/src/sqlite/expression/expression_methods.rs @@ -1,5 +1,8 @@ //! Sqlite specific expression methods. +pub(in crate::sqlite) use self::private::{ + JsonOrNullableJsonOrJsonbOrNullableJsonb, MaybeNullableValue, +}; use super::operators::*; use crate::dsl; use crate::expression::grouped::Grouped; @@ -82,3 +85,26 @@ pub trait SqliteExpressionMethods: Expression + Sized { } impl SqliteExpressionMethods for T {} + +pub(in crate::sqlite) mod private { + use crate::sql_types::{Json, Jsonb, MaybeNullableType, Nullable, SingleValue}; + + pub trait JsonOrNullableJsonOrJsonbOrNullableJsonb {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Json {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Jsonb {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} + + pub trait MaybeNullableValue: SingleValue { + type Out: SingleValue; + } + + impl MaybeNullableValue for T + where + T: SingleValue, + T::IsNull: MaybeNullableType, + >::Out: SingleValue, + { + type Out = >::Out; + } +} diff --git a/diesel/src/sqlite/expression/functions.rs b/diesel/src/sqlite/expression/functions.rs new file mode 100644 index 000000000000..790cd4199072 --- /dev/null +++ b/diesel/src/sqlite/expression/functions.rs @@ -0,0 +1,114 @@ +//! SQLite specific functions +use crate::expression::functions::define_sql_function; +use crate::sql_types::*; +use crate::sqlite::expression::expression_methods::JsonOrNullableJsonOrJsonbOrNullableJsonb; +use crate::sqlite::expression::expression_methods::MaybeNullableValue; + +#[cfg(feature = "sqlite")] +define_sql_function! { + /// Verifies that its argument is a valid JSON string or JSONB blob and returns a minified + /// version of that JSON string with all unnecessary whitespace removed. + /// + /// # Example + /// + /// ```rust + /// # include!("../../doctest_setup.rs"); + /// # + /// # fn main() { + /// # #[cfg(feature = "serde_json")] + /// # run_test().unwrap(); + /// # } + /// # + /// # #[cfg(feature = "serde_json")] + /// # fn run_test() -> QueryResult<()> { + /// # use diesel::dsl::json; + /// # use serde_json::{json, Value}; + /// # use diesel::sql_types::{Text, Json, Jsonb, Nullable}; + /// # let connection = &mut establish_connection(); + /// + /// let result = diesel::select(json::(json!({"a": "b", "c": 1}))) + /// .get_result::(connection)?; + /// + /// assert_eq!(r#"{"a":"b","c":1}"#, result); + /// + /// let result = diesel::select(json::(json!({ "this" : "is", "a": [ "test" ] }))) + /// .get_result::(connection)?; + /// + /// assert_eq!(r#"{"a":["test"],"this":"is"}"#, result); + /// + /// let result = diesel::select(json::, _>(None::)) + /// .get_result::>(connection)?; + /// + /// assert!(result.is_none()); + /// + /// let result = diesel::select(json::(json!({"a": "b", "c": 1}))) + /// .get_result::(connection)?; + /// + /// assert_eq!(r#"{"a":"b","c":1}"#, result); + /// + /// let result = diesel::select(json::(json!({ "this" : "is", "a": [ "test" ] }))) + /// .get_result::(connection)?; + /// + /// assert_eq!(r#"{"a":["test"],"this":"is"}"#, result); + /// + /// let result = diesel::select(json::, _>(None::)) + /// .get_result::>(connection)?; + /// + /// assert!(result.is_none()); + /// + /// + /// # Ok(()) + /// # } + /// ``` + fn json>(e: E) -> E::Out; +} + +#[cfg(feature = "sqlite")] +define_sql_function! { + /// + /// # Example + /// + /// ```rust + /// # include!("../../doctest_setup.rs"); + /// # + /// # fn main() { + /// # #[cfg(feature = "serde_json")] + /// # run_test().unwrap(); + /// # } + /// # + /// # #[cfg(feature = "serde_json")] + /// # fn run_test() -> QueryResult<()> { + /// # use diesel::dsl::jsonb; + /// # use serde_json::{json, Value}; + /// # use diesel::sql_types::{Text, Json, Jsonb, Nullable}; + /// # let connection = &mut establish_connection(); + /// + /// let result = diesel::select(jsonb::(json!({"a": "b", "c": 1}))) + /// .get_result::(connection)?; + /// + /// assert_eq!(json!({"a": "b", "c": 1}), result); + /// println!("json abc1"); + /// + /// let result = diesel::select(jsonb::(json!({"a": "b", "c": 1}))) + /// .get_result::(connection)?; + /// + /// assert_eq!(json!({"a": "b", "c": 1}), result); + /// println!("jsonb abc1"); + /// + /// let result = diesel::select(jsonb::, _>(None::)) + /// .get_result::>(connection)?; + /// + /// assert!(result.is_none()); + /// println!("json null"); + /// + /// let result = diesel::select(jsonb::, _>(None::)) + /// .get_result::>(connection)?; + /// + /// assert!(result.is_none()); + /// println!("jsonb null"); + /// + /// # Ok(()) + /// # } + /// ``` + fn jsonb>(e: E) -> E::Out; +} diff --git a/diesel/src/sqlite/expression/helper_types.rs b/diesel/src/sqlite/expression/helper_types.rs index 77f54ebe0d6a..807aea965c68 100644 --- a/diesel/src/sqlite/expression/helper_types.rs +++ b/diesel/src/sqlite/expression/helper_types.rs @@ -1,4 +1,4 @@ -use crate::dsl::AsExpr; +use crate::dsl::{AsExpr, SqlTypeOf}; use crate::expression::grouped::Grouped; /// The return type of `lhs.is(rhs)`. @@ -6,3 +6,13 @@ pub type Is = Grouped>>; /// The return type of `lhs.is_not(rhs)`. pub type IsNot = Grouped>>; + +/// Return type of [`json(json)`](super::functions::json()) +#[allow(non_camel_case_types)] +#[cfg(feature = "sqlite")] +pub type json = super::functions::json, E>; + +/// Return type of [`jsonb(json)`](super::functions::jsonb()) +#[allow(non_camel_case_types)] +#[cfg(feature = "sqlite")] +pub type jsonb = super::functions::jsonb, E>; diff --git a/diesel/src/sqlite/expression/mod.rs b/diesel/src/sqlite/expression/mod.rs index 00a224ca9f6a..3ac455134170 100644 --- a/diesel/src/sqlite/expression/mod.rs +++ b/diesel/src/sqlite/expression/mod.rs @@ -5,5 +5,16 @@ //! kept separate purely for documentation purposes. pub(crate) mod expression_methods; +pub mod functions; pub(crate) mod helper_types; mod operators; + +/// SQLite specific expression DSL methods. +/// +/// This module will be glob imported by +/// [`diesel::dsl`](crate::dsl) when compiled with the `feature = +/// "postgres"` flag. +pub mod dsl { + #[doc(inline)] + pub use super::functions::*; +} \ No newline at end of file diff --git a/diesel/src/sqlite/mod.rs b/diesel/src/sqlite/mod.rs index 45cabe6f86c4..ee625acb0cb1 100644 --- a/diesel/src/sqlite/mod.rs +++ b/diesel/src/sqlite/mod.rs @@ -6,7 +6,7 @@ pub(crate) mod backend; mod connection; -pub(crate) mod expression; +pub mod expression; pub mod query_builder; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index 2cc13b35c277..16eed102f5be 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -57,6 +57,16 @@ table! { } } +#[cfg(feature = "sqlite")] +table! { + sqlite_extras { + id -> Integer, + text -> Text, + json -> Json, + jsonb -> Jsonb, + } +} + joinable!(posts -> users(user_id)); joinable!(posts2 -> users(user_id)); joinable!(posts3 -> users(user_id)); @@ -465,6 +475,18 @@ fn postgres_functions() -> _ { ) } +#[cfg(feature = "sqlite")] +#[auto_type] +fn sqlite_functions() -> _ { + use diesel::sqlite::expression::functions::{json, jsonb}; + ( + json(sqlite_extras::json), + json(sqlite_extras::jsonb), + jsonb(sqlite_extras::json), + jsonb(sqlite_extras::jsonb), + ) +} + #[auto_type] fn with_lifetime<'a>(name: &'a str) -> _ { users::table.filter(users::name.eq(name)) From 287c9f6b290999623510a8421d76fbebaf5af30d Mon Sep 17 00:00:00 2001 From: Xue Haonan Date: Thu, 12 Dec 2024 14:46:02 +0800 Subject: [PATCH 2/6] fix: rustfmt and `libsqlite3-sys` feature from `bundled-bindings` to `bundled` to support jsonb. --- diesel/Cargo.toml | 2 +- diesel/src/sqlite/expression/functions.rs | 4 ++-- diesel/src/sqlite/expression/mod.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index fc69b80ac609..bf4316f189a6 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -24,7 +24,7 @@ include = [ 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.31.0", optional = true, features = ["bundled_bindings"] } +libsqlite3-sys = { version = ">=0.17.2, <0.31.0", optional = true, features = ["bundled"] } 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 } diff --git a/diesel/src/sqlite/expression/functions.rs b/diesel/src/sqlite/expression/functions.rs index 790cd4199072..4c297dc95ad6 100644 --- a/diesel/src/sqlite/expression/functions.rs +++ b/diesel/src/sqlite/expression/functions.rs @@ -25,7 +25,7 @@ define_sql_function! { /// # use serde_json::{json, Value}; /// # use diesel::sql_types::{Text, Json, Jsonb, Nullable}; /// # let connection = &mut establish_connection(); - /// + /// /// let result = diesel::select(json::(json!({"a": "b", "c": 1}))) /// .get_result::(connection)?; /// @@ -100,7 +100,7 @@ define_sql_function! { /// /// assert!(result.is_none()); /// println!("json null"); - /// + /// /// let result = diesel::select(jsonb::, _>(None::)) /// .get_result::>(connection)?; /// diff --git a/diesel/src/sqlite/expression/mod.rs b/diesel/src/sqlite/expression/mod.rs index 3ac455134170..e3dedb19245a 100644 --- a/diesel/src/sqlite/expression/mod.rs +++ b/diesel/src/sqlite/expression/mod.rs @@ -10,11 +10,11 @@ pub(crate) mod helper_types; mod operators; /// SQLite specific expression DSL methods. -/// +/// /// This module will be glob imported by /// [`diesel::dsl`](crate::dsl) when compiled with the `feature = /// "postgres"` flag. pub mod dsl { #[doc(inline)] pub use super::functions::*; -} \ No newline at end of file +} From 75ccf87f96efd807944491fda50fe7bc8d4b730d Mon Sep 17 00:00:00 2001 From: Xue Haonan Date: Thu, 12 Dec 2024 21:14:18 +0800 Subject: [PATCH 3/6] Fix `json` `jsonb` definition and `libsqite3-sys` feature. --- diesel/Cargo.toml | 2 +- .../sqlite/expression/expression_methods.rs | 24 +++++++- diesel/src/sqlite/expression/functions.rs | 61 ++++++------------- diesel/src/sqlite/expression/mod.rs | 2 +- diesel_derives/tests/auto_type.rs | 9 +-- 5 files changed, 45 insertions(+), 53 deletions(-) diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index bf4316f189a6..fc69b80ac609 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -24,7 +24,7 @@ include = [ 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.31.0", optional = true, features = ["bundled"] } +libsqlite3-sys = { version = ">=0.17.2, <0.31.0", optional = true, features = ["bundled_bindings"] } 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 } diff --git a/diesel/src/sqlite/expression/expression_methods.rs b/diesel/src/sqlite/expression/expression_methods.rs index f4f80c724a07..07d1602b349a 100644 --- a/diesel/src/sqlite/expression/expression_methods.rs +++ b/diesel/src/sqlite/expression/expression_methods.rs @@ -1,7 +1,7 @@ //! Sqlite specific expression methods. pub(in crate::sqlite) use self::private::{ - JsonOrNullableJsonOrJsonbOrNullableJsonb, MaybeNullableValue, + BinaryOrNullableBinary, MaybeNullableValue, TextOrNullableText, }; use super::operators::*; use crate::dsl; @@ -87,13 +87,33 @@ pub trait SqliteExpressionMethods: Expression + Sized { impl SqliteExpressionMethods for T {} pub(in crate::sqlite) mod private { - use crate::sql_types::{Json, Jsonb, MaybeNullableType, Nullable, SingleValue}; + use crate::sql_types::{Binary, MaybeNullableType, Nullable, SingleValue, Text}; + /* pub trait JsonOrNullableJsonOrJsonbOrNullableJsonb {} impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Json {} impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Jsonb {} impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} + */ + + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Text` nor `diesel::sql_types::Nullable`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait TextOrNullableText {} + + impl TextOrNullableText for Text {} + impl TextOrNullableText for Nullable {} + + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Binary` nor `diesel::sql_types::Nullable`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait BinaryOrNullableBinary {} + + impl BinaryOrNullableBinary for Binary {} + impl BinaryOrNullableBinary for Nullable {} pub trait MaybeNullableValue: SingleValue { type Out: SingleValue; diff --git a/diesel/src/sqlite/expression/functions.rs b/diesel/src/sqlite/expression/functions.rs index 4c297dc95ad6..a91cc625686d 100644 --- a/diesel/src/sqlite/expression/functions.rs +++ b/diesel/src/sqlite/expression/functions.rs @@ -1,8 +1,9 @@ //! SQLite specific functions use crate::expression::functions::define_sql_function; use crate::sql_types::*; -use crate::sqlite::expression::expression_methods::JsonOrNullableJsonOrJsonbOrNullableJsonb; +use crate::sqlite::expression::expression_methods::BinaryOrNullableBinary; use crate::sqlite::expression::expression_methods::MaybeNullableValue; +use crate::sqlite::expression::expression_methods::TextOrNullableText; #[cfg(feature = "sqlite")] define_sql_function! { @@ -23,48 +24,33 @@ define_sql_function! { /// # fn run_test() -> QueryResult<()> { /// # use diesel::dsl::json; /// # use serde_json::{json, Value}; - /// # use diesel::sql_types::{Text, Json, Jsonb, Nullable}; + /// # use diesel::sql_types::{Text, Nullable}; /// # let connection = &mut establish_connection(); /// - /// let result = diesel::select(json::(json!({"a": "b", "c": 1}))) - /// .get_result::(connection)?; - /// - /// assert_eq!(r#"{"a":"b","c":1}"#, result); - /// - /// let result = diesel::select(json::(json!({ "this" : "is", "a": [ "test" ] }))) - /// .get_result::(connection)?; - /// - /// assert_eq!(r#"{"a":["test"],"this":"is"}"#, result); - /// - /// let result = diesel::select(json::, _>(None::)) - /// .get_result::>(connection)?; - /// - /// assert!(result.is_none()); - /// - /// let result = diesel::select(json::(json!({"a": "b", "c": 1}))) - /// .get_result::(connection)?; + /// let result = diesel::select(json::(r#"{"a": "b", "c": 1}"#)) + /// .get_result::(connection)?; /// - /// assert_eq!(r#"{"a":"b","c":1}"#, result); + /// assert_eq!(json!({"a":"b","c":1}), result); /// - /// let result = diesel::select(json::(json!({ "this" : "is", "a": [ "test" ] }))) - /// .get_result::(connection)?; + /// let result = diesel::select(json::(r#"{ "this" : "is", "a": [ "test" ] }"#)) + /// .get_result::(connection)?; /// - /// assert_eq!(r#"{"a":["test"],"this":"is"}"#, result); + /// assert_eq!(json!({"a":["test"],"this":"is"}), result); /// - /// let result = diesel::select(json::, _>(None::)) - /// .get_result::>(connection)?; + /// let result = diesel::select(json::, _>(None::<&str>)) + /// .get_result::>(connection)?; /// /// assert!(result.is_none()); /// - /// /// # Ok(()) /// # } /// ``` - fn json>(e: E) -> E::Out; + fn json>(e: E) -> E::Out; } #[cfg(feature = "sqlite")] define_sql_function! { + /// The jsonb(X) function returns the binary JSONB representation of the JSON provided as argument X. /// /// # Example /// @@ -80,35 +66,26 @@ define_sql_function! { /// # fn run_test() -> QueryResult<()> { /// # use diesel::dsl::jsonb; /// # use serde_json::{json, Value}; - /// # use diesel::sql_types::{Text, Json, Jsonb, Nullable}; + /// # use diesel::sql_types::{Text, Binary, Json, Jsonb, Nullable}; /// # let connection = &mut establish_connection(); /// - /// let result = diesel::select(jsonb::(json!({"a": "b", "c": 1}))) + /// let result = diesel::select(jsonb::(br#"{"a": "b", "c": 1}"#)) /// .get_result::(connection)?; /// /// assert_eq!(json!({"a": "b", "c": 1}), result); - /// println!("json abc1"); /// - /// let result = diesel::select(jsonb::(json!({"a": "b", "c": 1}))) + /// let result = diesel::select(jsonb::(br#"{"this":"is","a":["test"]}"#)) /// .get_result::(connection)?; /// - /// assert_eq!(json!({"a": "b", "c": 1}), result); - /// println!("jsonb abc1"); - /// - /// let result = diesel::select(jsonb::, _>(None::)) - /// .get_result::>(connection)?; - /// - /// assert!(result.is_none()); - /// println!("json null"); + /// assert_eq!(json!({"this":"is","a":["test"]}), result); /// - /// let result = diesel::select(jsonb::, _>(None::)) + /// let result = diesel::select(jsonb::, _>(None::>)) /// .get_result::>(connection)?; /// /// assert!(result.is_none()); - /// println!("jsonb null"); /// /// # Ok(()) /// # } /// ``` - fn jsonb>(e: E) -> E::Out; + fn jsonb>(e: E) -> E::Out; } diff --git a/diesel/src/sqlite/expression/mod.rs b/diesel/src/sqlite/expression/mod.rs index e3dedb19245a..009bd1de33f0 100644 --- a/diesel/src/sqlite/expression/mod.rs +++ b/diesel/src/sqlite/expression/mod.rs @@ -13,7 +13,7 @@ mod operators; /// /// This module will be glob imported by /// [`diesel::dsl`](crate::dsl) when compiled with the `feature = -/// "postgres"` flag. +/// "sqlite"` flag. pub mod dsl { #[doc(inline)] pub use super::functions::*; diff --git a/diesel_derives/tests/auto_type.rs b/diesel_derives/tests/auto_type.rs index 16eed102f5be..640706e9141f 100644 --- a/diesel_derives/tests/auto_type.rs +++ b/diesel_derives/tests/auto_type.rs @@ -62,6 +62,7 @@ table! { sqlite_extras { id -> Integer, text -> Text, + blob -> Binary, json -> Json, jsonb -> Jsonb, } @@ -478,13 +479,7 @@ fn postgres_functions() -> _ { #[cfg(feature = "sqlite")] #[auto_type] fn sqlite_functions() -> _ { - use diesel::sqlite::expression::functions::{json, jsonb}; - ( - json(sqlite_extras::json), - json(sqlite_extras::jsonb), - jsonb(sqlite_extras::json), - jsonb(sqlite_extras::jsonb), - ) + (json(sqlite_extras::text), jsonb(sqlite_extras::blob)) } #[auto_type] From d3818245e73ad27ef11613f43106ea0de55d7a7f Mon Sep 17 00:00:00 2001 From: Xue Haonan Date: Thu, 12 Dec 2024 21:42:24 +0800 Subject: [PATCH 4/6] fix: skip `jsonb` test if SQLite does not support. --- diesel/src/sqlite/expression/functions.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/diesel/src/sqlite/expression/functions.rs b/diesel/src/sqlite/expression/functions.rs index a91cc625686d..82fcfe956da9 100644 --- a/diesel/src/sqlite/expression/functions.rs +++ b/diesel/src/sqlite/expression/functions.rs @@ -64,11 +64,27 @@ define_sql_function! { /// # /// # #[cfg(feature = "serde_json")] /// # fn run_test() -> QueryResult<()> { - /// # use diesel::dsl::jsonb; + /// # use diesel::dsl::{sql, jsonb}; /// # use serde_json::{json, Value}; - /// # use diesel::sql_types::{Text, Binary, Json, Jsonb, Nullable}; + /// # use diesel::sql_types::{Text, Binary, Nullable}; /// # let connection = &mut establish_connection(); /// + /// let version = diesel::select(sql::("sqlite_version();")) + /// .get_result::(connection)?; + /// + /// // Querying SQLite version should not fail. + /// let version_components: Vec<&str> = version.split('.').collect(); + /// let major: u32 = version_components[0].parse().unwrap(); + /// let minor: u32 = version_components[1].parse().unwrap(); + /// let patch: u32 = version_components[2].parse().unwrap(); + /// + /// if major > 3 || (major == 3 && minor >= 45) { + /// /* Valid sqlite version, do nothing */ + /// } else { + /// println!("SQLite version is too old, skipping the test."); + /// return Ok(()); + /// } + /// /// let result = diesel::select(jsonb::(br#"{"a": "b", "c": 1}"#)) /// .get_result::(connection)?; /// From 0991d428db5b7b081496816dff68dd26ad118bf2 Mon Sep 17 00:00:00 2001 From: Xue Haonan Date: Thu, 12 Dec 2024 21:50:51 +0800 Subject: [PATCH 5/6] style: rustfmt --- diesel/src/sqlite/expression/functions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel/src/sqlite/expression/functions.rs b/diesel/src/sqlite/expression/functions.rs index 82fcfe956da9..7d37531d5c31 100644 --- a/diesel/src/sqlite/expression/functions.rs +++ b/diesel/src/sqlite/expression/functions.rs @@ -71,7 +71,7 @@ define_sql_function! { /// /// let version = diesel::select(sql::("sqlite_version();")) /// .get_result::(connection)?; - /// + /// /// // Querying SQLite version should not fail. /// let version_components: Vec<&str> = version.split('.').collect(); /// let major: u32 = version_components[0].parse().unwrap(); From 683a8afed5f441562d91558647370c57f094f0e4 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Fri, 13 Dec 2024 08:09:16 +0000 Subject: [PATCH 6/6] Remove some unneeded lines --- diesel/src/sqlite/expression/expression_methods.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/diesel/src/sqlite/expression/expression_methods.rs b/diesel/src/sqlite/expression/expression_methods.rs index 07d1602b349a..8043cb45320e 100644 --- a/diesel/src/sqlite/expression/expression_methods.rs +++ b/diesel/src/sqlite/expression/expression_methods.rs @@ -89,14 +89,6 @@ impl SqliteExpressionMethods for T {} pub(in crate::sqlite) mod private { use crate::sql_types::{Binary, MaybeNullableType, Nullable, SingleValue, Text}; - /* - pub trait JsonOrNullableJsonOrJsonbOrNullableJsonb {} - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Json {} - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Jsonb {} - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} - */ - #[diagnostic::on_unimplemented( message = "`{Self}` is neither `diesel::sql_types::Text` nor `diesel::sql_types::Nullable`", note = "try to provide an expression that produces one of the expected sql types"