From 99b037eaaa86c1811abbe2e80c6e3c4271ca99e5 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Thu, 9 Nov 2023 22:23:35 +0000 Subject: [PATCH 1/5] added support for this --- sqlx-postgres/src/connection/describe.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index 1cd28a8b54..27a4fe58ef 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -185,12 +185,21 @@ impl PgConnection { fn fetch_type_by_oid(&mut self, oid: Oid) -> BoxFuture<'_, Result> { Box::pin(async move { - let (name, typ_type, category, relation_id, element, base_type): (String, i8, i8, Oid, Oid, Oid) = query_as( - "SELECT typname, typtype, typcategory, typrelid, typelem, typbasetype FROM pg_catalog.pg_type WHERE oid = $1", + let (name, typ_type, category, relation_id, element, base_type, namespace): (String, i8, i8, Oid, Oid, Oid, String) = query_as( + r#" + SELECT + t.typname, t.typtype, t.typcategory, t.typrelid, t.typelem, t.typbasetype, n.nspname + FROM + pg_catalog.pg_type t + LEFT JOIN + pg_catalog.pg_namespace n ON t.typnamespace = n.oid + WHERE t.oid = $1"#, ) - .bind(oid) - .fetch_one(&mut *self) - .await?; + .bind(oid) + .fetch_one(&mut *self) + .await?; + + let namespaced_name = namespace + "." + &name; let typ_type = TypType::try_from(typ_type as u8); let category = TypCategory::try_from(category as u8); @@ -221,7 +230,7 @@ impl PgConnection { } (Ok(TypType::Enum), Ok(TypCategory::Enum)) => { - self.fetch_enum_by_oid(oid, name).await + self.fetch_enum_by_oid(oid, namespaced_name).await } (Ok(TypType::Composite), Ok(TypCategory::Composite)) => { From cf0782efa4d9b243a9dbf85d098daf7ddcec35c2 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Thu, 9 Nov 2023 23:07:42 +0000 Subject: [PATCH 2/5] fix tests --- tests/postgres/describe.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/postgres/describe.rs b/tests/postgres/describe.rs index d128eb21b6..a8e5e9d99f 100644 --- a/tests/postgres/describe.rs +++ b/tests/postgres/describe.rs @@ -52,7 +52,7 @@ async fn it_describes_enum() -> anyhow::Result<()> { let ty = d.columns()[0].type_info(); - assert_eq!(ty.name(), "status"); + assert_eq!(ty.name(), "public.status"); assert_eq!( format!("{:?}", ty.kind()), @@ -84,7 +84,7 @@ async fn it_describes_composite() -> anyhow::Result<()> { let ty = d.columns()[0].type_info(); - assert_eq!(ty.name(), "inventory_item"); + assert_eq!(ty.name(), "public.inventory_item"); assert_eq!( format!("{:?}", ty.kind()), From 4fd102fb8be27cbfb33c7ec440ebd5ef7ff3af98 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Thu, 9 Nov 2023 23:15:17 +0000 Subject: [PATCH 3/5] roll in namespace --- sqlx-postgres/src/connection/describe.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index 27a4fe58ef..56b021a2fa 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -185,10 +185,10 @@ impl PgConnection { fn fetch_type_by_oid(&mut self, oid: Oid) -> BoxFuture<'_, Result> { Box::pin(async move { - let (name, typ_type, category, relation_id, element, base_type, namespace): (String, i8, i8, Oid, Oid, Oid, String) = query_as( + let (name, typ_type, category, relation_id, element, base_type): (String, i8, i8, Oid, Oid, Oid) = query_as( r#" SELECT - t.typname, t.typtype, t.typcategory, t.typrelid, t.typelem, t.typbasetype, n.nspname + n.nspname || '.' || t.typname, t.typtype, t.typcategory, t.typrelid, t.typelem, t.typbasetype FROM pg_catalog.pg_type t LEFT JOIN @@ -199,8 +199,6 @@ impl PgConnection { .fetch_one(&mut *self) .await?; - let namespaced_name = namespace + "." + &name; - let typ_type = TypType::try_from(typ_type as u8); let category = TypCategory::try_from(category as u8); From fd8798225fe606a0ea85752737d09398784c3e20 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Thu, 9 Nov 2023 23:22:57 +0000 Subject: [PATCH 4/5] fix --- sqlx-postgres/src/connection/describe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index 56b021a2fa..96df3d5e10 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -228,7 +228,7 @@ impl PgConnection { } (Ok(TypType::Enum), Ok(TypCategory::Enum)) => { - self.fetch_enum_by_oid(oid, namespaced_name).await + self.fetch_enum_by_oid(oid, name).await } (Ok(TypType::Composite), Ok(TypCategory::Composite)) => { From c1d3eba0f88f438257d9a63798792b0feed6a964 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Thu, 9 Nov 2023 23:26:54 +0000 Subject: [PATCH 5/5] format --- sqlx-postgres/src/connection/describe.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index 96df3d5e10..9b0adc64b7 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -193,11 +193,12 @@ impl PgConnection { pg_catalog.pg_type t LEFT JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid - WHERE t.oid = $1"#, + WHERE t.oid = $1 + "#, ) - .bind(oid) - .fetch_one(&mut *self) - .await?; + .bind(oid) + .fetch_one(&mut *self) + .await?; let typ_type = TypType::try_from(typ_type as u8); let category = TypCategory::try_from(category as u8);