Skip to content

Commit

Permalink
fix(launchbadge#3445): PgHasArrayType (launchbadge#3453)
Browse files Browse the repository at this point in the history
* fix(launchbadge#3445): PgHasArrayType

* regression test for custom no_pg_array
  • Loading branch information
joeydewaal authored Aug 25, 2024
1 parent 018ffe7 commit ebf04ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 0 additions & 6 deletions sqlx-macros-core/src/derives/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions tests/postgres/derives.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(())
}

0 comments on commit ebf04ff

Please sign in to comment.