fix(#3445): PgHasArrayType (#3453)

* fix(#3445): PgHasArrayType

* regression test for custom no_pg_array
This commit is contained in:
joeydewaal 2024-08-25 04:25:08 +02:00 committed by GitHub
parent 018ffe7e0d
commit ebf04ff499
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -278,12 +278,6 @@ pub fn check_struct_attributes(
input
);
assert_attribute!(
!attributes.no_pg_array,
"unused #[sqlx(no_pg_array)]; derive does not emit `PgHasArrayType` impls for custom structs",
input
);
assert_attribute!(attributes.repr.is_none(), "unexpected #[repr(..)]", input);
for field in fields {

View File

@ -1,6 +1,7 @@
use futures::TryStreamExt;
use sqlx::postgres::types::PgRange;
use sqlx::{Connection, Executor, FromRow, Postgres};
use sqlx_postgres::PgHasArrayType;
use sqlx_test::{new, test_type};
use std::fmt::Debug;
use std::ops::Bound;
@ -792,3 +793,20 @@ async fn test_from_row_hygiene() -> anyhow::Result<()> {
Ok(())
}
#[sqlx_macros::test]
async fn test_custom_pg_array() -> anyhow::Result<()> {
#[derive(sqlx::Type)]
#[sqlx(no_pg_array)]
pub struct User {
pub id: i32,
pub username: String,
}
impl PgHasArrayType for User {
fn array_type_info() -> sqlx::postgres::PgTypeInfo {
sqlx::postgres::PgTypeInfo::array_of("Gebruiker")
}
}
Ok(())
}