diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bbd4f193c..ab5d7663b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -316,7 +316,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - path: [86, 249, 262, 319, 324] + path: [86, 249, 262, 319, 324, 352] steps: - uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index 9a95fba01..34ce2ae9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" } log = { version = "^0.4", optional = true } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.4.0", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.19.0", features = ["thread-safe"] } +sea-query = { version = "^0.19.0", git = "https://github.com/SeaQL/sea-query.git", branch = "sea-orm/issues/352", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } diff --git a/issues/352/Cargo.toml b/issues/352/Cargo.toml new file mode 100644 index 000000000..015b19b7e --- /dev/null +++ b/issues/352/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +# A separate workspace + +[package] +name = "sea-orm-issues-352" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls" ]} diff --git a/issues/352/src/binary_primary_key.rs b/issues/352/src/binary_primary_key.rs new file mode 100644 index 000000000..7728d2851 --- /dev/null +++ b/issues/352/src/binary_primary_key.rs @@ -0,0 +1,18 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub id_2: String, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/352/src/main.rs b/issues/352/src/main.rs new file mode 100644 index 000000000..3a8b741bd --- /dev/null +++ b/issues/352/src/main.rs @@ -0,0 +1,8 @@ +mod unary_primary_key; +mod binary_primary_key; +mod ternary_primary_key; +mod quaternary_primary_key; +mod quinary_primary_key; +mod senary_primary_key; + +pub fn main() {} diff --git a/issues/352/src/quaternary_primary_key.rs b/issues/352/src/quaternary_primary_key.rs new file mode 100644 index 000000000..ca92b7a59 --- /dev/null +++ b/issues/352/src/quaternary_primary_key.rs @@ -0,0 +1,22 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub id_2: String, + #[sea_orm(primary_key, auto_increment = false)] + pub id_3: f64, + #[sea_orm(primary_key, auto_increment = false)] + pub id_4: Uuid, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/352/src/quinary_primary_key.rs b/issues/352/src/quinary_primary_key.rs new file mode 100644 index 000000000..1a829669c --- /dev/null +++ b/issues/352/src/quinary_primary_key.rs @@ -0,0 +1,24 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub id_2: String, + #[sea_orm(primary_key, auto_increment = false)] + pub id_3: f64, + #[sea_orm(primary_key, auto_increment = false)] + pub id_4: Uuid, + #[sea_orm(primary_key, auto_increment = false)] + pub id_5: DateTime, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/352/src/senary_primary_key.rs b/issues/352/src/senary_primary_key.rs new file mode 100644 index 000000000..1a34feb94 --- /dev/null +++ b/issues/352/src/senary_primary_key.rs @@ -0,0 +1,26 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub id_2: String, + #[sea_orm(primary_key, auto_increment = false)] + pub id_3: f64, + #[sea_orm(primary_key, auto_increment = false)] + pub id_4: Uuid, + #[sea_orm(primary_key, auto_increment = false)] + pub id_5: DateTime, + #[sea_orm(primary_key, auto_increment = false)] + pub id_6: DateTimeWithTimeZone, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/352/src/ternary_primary_key.rs b/issues/352/src/ternary_primary_key.rs new file mode 100644 index 000000000..753cd91c8 --- /dev/null +++ b/issues/352/src/ternary_primary_key.rs @@ -0,0 +1,20 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub id_2: String, + #[sea_orm(primary_key, auto_increment = false)] + pub id_3: f64, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/352/src/unary_primary_key.rs b/issues/352/src/unary_primary_key.rs new file mode 100644 index 000000000..d12cb0d34 --- /dev/null +++ b/issues/352/src/unary_primary_key.rs @@ -0,0 +1,16 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "model")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id_1: i32, + pub owner: String, + pub name: String, + pub description: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/executor/query.rs b/src/executor/query.rs index dc2bb51a6..f50703845 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -451,6 +451,48 @@ where } } +impl TryGetableMany for (A, B, C, D, E) +where + A: TryGetable, + B: TryGetable, + C: TryGetable, + D: TryGetable, + E: TryGetable, +{ + fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result { + try_get_many_with_slice_len_of(5, cols)?; + Ok(( + A::try_get(res, pre, &cols[0])?, + B::try_get(res, pre, &cols[1])?, + C::try_get(res, pre, &cols[2])?, + D::try_get(res, pre, &cols[3])?, + E::try_get(res, pre, &cols[4])?, + )) + } +} + +impl TryGetableMany for (A, B, C, D, E, F) +where + A: TryGetable, + B: TryGetable, + C: TryGetable, + D: TryGetable, + E: TryGetable, + F: TryGetable, +{ + fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result { + try_get_many_with_slice_len_of(6, cols)?; + Ok(( + A::try_get(res, pre, &cols[0])?, + B::try_get(res, pre, &cols[1])?, + C::try_get(res, pre, &cols[2])?, + D::try_get(res, pre, &cols[3])?, + E::try_get(res, pre, &cols[4])?, + F::try_get(res, pre, &cols[5])?, + )) + } +} + fn try_get_many_with_slice_len_of(len: usize, cols: &[String]) -> Result<(), TryGetError> { if cols.len() < len { Err(TryGetError::DbErr(DbErr::Query(format!( @@ -501,6 +543,8 @@ macro_rules! try_from_u64_err { try_from_u64_err!(A, B); try_from_u64_err!(A, B, C); try_from_u64_err!(A, B, C, D); +try_from_u64_err!(A, B, C, D, E); +try_from_u64_err!(A, B, C, D, E, F); macro_rules! try_from_u64_numeric { ( $type: ty ) => { @@ -540,10 +584,28 @@ macro_rules! try_from_u64_string { try_from_u64_string!(String); +try_from_u64_err!(bool); +try_from_u64_err!(f32); +try_from_u64_err!(f64); try_from_u64_err!(Vec); -#[cfg(feature = "with-uuid")] -try_from_u64_err!(uuid::Uuid); +#[cfg(feature = "with-json")] +try_from_u64_err!(serde_json::Value); + +#[cfg(feature = "with-chrono")] +try_from_u64_err!(chrono::NaiveDate); + +#[cfg(feature = "with-chrono")] +try_from_u64_err!(chrono::NaiveTime); + +#[cfg(feature = "with-chrono")] +try_from_u64_err!(chrono::NaiveDateTime); #[cfg(feature = "with-chrono")] try_from_u64_err!(chrono::DateTime); + +#[cfg(feature = "with-rust_decimal")] +try_from_u64_err!(rust_decimal::Decimal); + +#[cfg(feature = "with-uuid")] +try_from_u64_err!(uuid::Uuid);