Replies: 1 comment
-
This is reported here: #1031 and is ultimately from a bug in rust, so you might not see a fix soon. As recommended in the linked issue, the path forward would be to expand the macro to get the derivation you need, and manually remove the extra problematic use sqlx::{types::Uuid, FromRow, Type};
#[derive(FromRow, Type)]
#[sqlx(type_name = "t_get_test1")]
pub struct Test1 {
pub test1_var1: i64,
pub val: String,
}
#[derive(FromRow, Type)]
#[sqlx(type_name = "t_get_test2")]
pub struct Test2 {
pub test2_var1: i64,
pub val: String,
}
#[derive(FromRow, Type)]
#[sqlx(type_name = "d_get_test2")]
pub struct ArrTestVal(Vec<Test2>);
#[derive(FromRow)]
#[sqlx(type_name = "t_get_test_extended")]
pub struct TestCombine {
pub id: i64,
pub test_var1: Test1,
pub test_var2: ArrTestVal,
}
impl ::sqlx::encode::Encode<'_, ::sqlx::Postgres> for TestCombine
where
i64: for<'q> ::sqlx::encode::Encode<'q, ::sqlx::Postgres>,
i64: ::sqlx::types::Type<::sqlx::Postgres>,
Test1: for<'q> ::sqlx::encode::Encode<'q, ::sqlx::Postgres>,
Test1: ::sqlx::types::Type<::sqlx::Postgres>,
ArrTestVal: for<'q> ::sqlx::encode::Encode<'q, ::sqlx::Postgres>,
ArrTestVal: ::sqlx::types::Type<::sqlx::Postgres>,
{
fn encode_by_ref(
&self,
buf: &mut ::sqlx::postgres::PgArgumentBuffer,
) -> ::sqlx::encode::IsNull {
let mut encoder = ::sqlx::postgres::types::PgRecordEncoder::new(buf);
encoder.encode(&self.id);
encoder.encode(&self.test_var1);
encoder.encode(&self.test_var2);
encoder.finish();
::sqlx::encode::IsNull::No
}
fn size_hint(&self) -> ::std::primitive::usize {
3usize * (4 + 4)
+ <i64 as ::sqlx::encode::Encode<::sqlx::Postgres>>::size_hint(&self.id)
+ <Test1 as ::sqlx::encode::Encode<::sqlx::Postgres>>::size_hint(&self.test_var1)
+ <ArrTestVal as ::sqlx::encode::Encode<::sqlx::Postgres>>::size_hint(
&self.test_var2,
)
}
}
impl<'r> ::sqlx::decode::Decode<'r, ::sqlx::Postgres> for TestCombine
where
i64: ::sqlx::types::Type<::sqlx::Postgres>,
Test1: ::sqlx::decode::Decode<'r, ::sqlx::Postgres>,
Test1: ::sqlx::types::Type<::sqlx::Postgres>,
ArrTestVal: ::sqlx::decode::Decode<'r, ::sqlx::Postgres>,
ArrTestVal: ::sqlx::types::Type<::sqlx::Postgres>,
{
fn decode(
value: ::sqlx::postgres::PgValueRef<'r>,
) -> ::std::result::Result<
Self,
::std::boxed::Box<
dyn ::std::error::Error + 'static + ::std::marker::Send + ::std::marker::Sync,
>,
> {
let mut decoder = ::sqlx::postgres::types::PgRecordDecoder::new(value)?;
let id = decoder.try_decode::<i64>()?;
let test_var1 = decoder.try_decode::<Test1>()?;
let test_var2 = decoder.try_decode::<ArrTestVal>()?;
::std::result::Result::Ok(TestCombine {
id,
test_var1,
test_var2,
})
}
}
impl ::sqlx::Type<::sqlx::Postgres> for TestCombine {
fn type_info() -> ::sqlx::postgres::PgTypeInfo {
::sqlx::postgres::PgTypeInfo::with_name("t_get_test_extended")
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Strange situation I was caught when map PostgreSQL type to the Rust structure.
I am using the latest sqlx crate.
The code below:
And I have got error:
Any idea why?
The error happen in
id
parameter inTestCombine
structure.Beta Was this translation helpful? Give feedback.
All reactions