Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sea-orm-macros/src/derives/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ impl DeriveValueTypeStruct {
quote!()
};

let impl_try_getable_array = if cfg!(feature = "postgres-array") {
quote!(
#[automatically_derived]
impl sea_orm::TryGetableArray for #name {
fn try_get_by<I: sea_orm::ColIdx>(
res: &sea_orm::QueryResult,
index: I,
) -> std::result::Result<Vec<Self>, sea_orm::TryGetError> {
Ok(<Vec<#field_type> as sea_orm::TryGetable>::try_get_by(res, index)?
.into_iter()
.map(|value| Self(value))
.collect())
}
}
)
} else {
quote!()
};

let impl_not_u8 = if cfg!(feature = "postgres-array") {
quote!(
#[automatically_derived]
Expand All @@ -198,6 +217,7 @@ impl DeriveValueTypeStruct {
#[automatically_derived]
impl std::convert::From<#name> for sea_orm::Value {
fn from(source: #name) -> Self {
println!("Struct");
source.0.into()
}
}
Expand Down Expand Up @@ -243,6 +263,8 @@ impl DeriveValueTypeStruct {
}
}

#impl_try_getable_array

#try_from_u64_impl

#impl_not_u8
Expand Down
14 changes: 14 additions & 0 deletions sea-orm-sync/tests/derive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ struct FromQueryResultNested {
#[sea_orm(nested)]
_test: SimpleTest,
}

#[cfg(feature = "postgres-array")]
mod postgres_array {
use crate::FromQueryResult;
use sea_orm::DeriveValueType;

#[derive(DeriveValueType)]
pub struct GoodId(i32);

#[derive(FromQueryResult)]
pub struct ArrayTest {
pub ingredient_path: Vec<GoodId>,
}
}
14 changes: 14 additions & 0 deletions tests/derive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ struct FromQueryResultNested {
#[sea_orm(nested)]
_test: SimpleTest,
}

#[cfg(feature = "postgres-array")]
mod postgres_array {
use crate::FromQueryResult;
use sea_orm::DeriveValueType;

#[derive(DeriveValueType)]
pub struct GoodId(i32);

#[derive(FromQueryResult)]
pub struct ArrayTest {
pub ingredient_path: Vec<GoodId>,
}
}
Loading