From 8ecb4fccba3bc7eca807899996071069fccf2363 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 15 Sep 2022 15:40:34 +0800 Subject: [PATCH 1/4] Implement `IntoActiveValue` for `Vec` types --- src/entity/active_model.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index cf679d96..0603662c 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -682,6 +682,7 @@ impl_into_active_value!(f32); impl_into_active_value!(f64); impl_into_active_value!(&'static str); impl_into_active_value!(String); +impl_into_active_value!(Vec); #[cfg(feature = "with-json")] #[cfg_attr(docsrs, doc(cfg(feature = "with-json")))] From 0d31a012cc94519efe08b2335f4e9e5a749020bb Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 15 Sep 2022 15:41:13 +0800 Subject: [PATCH 2/4] Add tests to double check and prevent it from happening again --- tests/type_tests.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/type_tests.rs diff --git a/tests/type_tests.rs b/tests/type_tests.rs new file mode 100644 index 00000000..5ceaf511 --- /dev/null +++ b/tests/type_tests.rs @@ -0,0 +1,52 @@ +pub mod common; + +use sea_orm::{IntoActiveValue, TryFromU64, TryGetable, Value}; + +pub fn it_impl_into_active_value, V: Into>() {} + +pub fn it_impl_try_getable() {} + +pub fn it_impl_try_from_u64() {} + +macro_rules! it_impl_traits { + ( $ty: ty ) => { + it_impl_into_active_value::<$ty, $ty>(); + it_impl_into_active_value::, Option<$ty>>(); + it_impl_into_active_value::>, Option<$ty>>(); + + it_impl_try_getable::<$ty>(); + it_impl_try_getable::>(); + + it_impl_try_from_u64::<$ty>(); + }; +} + +#[sea_orm_macros::test] +fn main() { + it_impl_traits!(i8); + it_impl_traits!(i16); + it_impl_traits!(i32); + it_impl_traits!(i64); + it_impl_traits!(u8); + it_impl_traits!(u16); + it_impl_traits!(u32); + it_impl_traits!(u64); + it_impl_traits!(bool); + it_impl_traits!(f32); + it_impl_traits!(f64); + it_impl_traits!(Vec); + it_impl_traits!(String); + it_impl_traits!(serde_json::Value); + it_impl_traits!(chrono::NaiveDate); + it_impl_traits!(chrono::NaiveTime); + it_impl_traits!(chrono::NaiveDateTime); + it_impl_traits!(chrono::DateTime); + it_impl_traits!(chrono::DateTime); + it_impl_traits!(chrono::DateTime); + it_impl_traits!(time::Date); + it_impl_traits!(time::Time); + it_impl_traits!(time::PrimitiveDateTime); + it_impl_traits!(time::OffsetDateTime); + it_impl_traits!(rust_decimal::Decimal); + it_impl_traits!(uuid::Uuid); +} From 7c591049bee99b0142ff307c9d863acbed4f3d65 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 15 Sep 2022 16:18:13 +0800 Subject: [PATCH 3/4] Add docs --- tests/type_tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/type_tests.rs b/tests/type_tests.rs index 5ceaf511..4225b080 100644 --- a/tests/type_tests.rs +++ b/tests/type_tests.rs @@ -2,6 +2,18 @@ pub mod common; use sea_orm::{IntoActiveValue, TryFromU64, TryGetable, Value}; +/* + +When supporting a new type in SeaORM we should implement the following traits for it: + - `IntoActiveValue`, given that it implemented `Into` already + - `TryGetable` + - `TryFromU64` + +Also, we need to update `impl FromQueryResult for JsonValue` at `src/query/json.rs` +to correctly serialize the type as `serde_json::Value`. + +*/ + pub fn it_impl_into_active_value, V: Into>() {} pub fn it_impl_try_getable() {} From 1035bbb431efbb12b696f12fdc58ccbb802a0268 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 15 Sep 2022 16:44:31 +0800 Subject: [PATCH 4/4] Fixup --- tests/type_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/type_tests.rs b/tests/type_tests.rs index 4225b080..0c936130 100644 --- a/tests/type_tests.rs +++ b/tests/type_tests.rs @@ -20,6 +20,7 @@ pub fn it_impl_try_getable() {} pub fn it_impl_try_from_u64() {} +#[allow(unused_macros)] macro_rules! it_impl_traits { ( $ty: ty ) => { it_impl_into_active_value::<$ty, $ty>(); @@ -34,6 +35,7 @@ macro_rules! it_impl_traits { } #[sea_orm_macros::test] +#[cfg(feature = "sqlx-dep")] fn main() { it_impl_traits!(i8); it_impl_traits!(i16);