Skip to content

Commit ebf04ff

Browse files
authored
fix(#3445): PgHasArrayType (#3453)
* fix(#3445): PgHasArrayType * regression test for custom no_pg_array
1 parent 018ffe7 commit ebf04ff

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

sqlx-macros-core/src/derives/attributes.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,6 @@ pub fn check_struct_attributes(
278278
input
279279
);
280280

281-
assert_attribute!(
282-
!attributes.no_pg_array,
283-
"unused #[sqlx(no_pg_array)]; derive does not emit `PgHasArrayType` impls for custom structs",
284-
input
285-
);
286-
287281
assert_attribute!(attributes.repr.is_none(), "unexpected #[repr(..)]", input);
288282

289283
for field in fields {

tests/postgres/derives.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use futures::TryStreamExt;
22
use sqlx::postgres::types::PgRange;
33
use sqlx::{Connection, Executor, FromRow, Postgres};
4+
use sqlx_postgres::PgHasArrayType;
45
use sqlx_test::{new, test_type};
56
use std::fmt::Debug;
67
use std::ops::Bound;
@@ -792,3 +793,20 @@ async fn test_from_row_hygiene() -> anyhow::Result<()> {
792793

793794
Ok(())
794795
}
796+
797+
#[sqlx_macros::test]
798+
async fn test_custom_pg_array() -> anyhow::Result<()> {
799+
#[derive(sqlx::Type)]
800+
#[sqlx(no_pg_array)]
801+
pub struct User {
802+
pub id: i32,
803+
pub username: String,
804+
}
805+
806+
impl PgHasArrayType for User {
807+
fn array_type_info() -> sqlx::postgres::PgTypeInfo {
808+
sqlx::postgres::PgTypeInfo::array_of("Gebruiker")
809+
}
810+
}
811+
Ok(())
812+
}

0 commit comments

Comments
 (0)