Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support fetching (pg) enums that are not in the public schema #2870

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sqlx-postgres/src/connection/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ impl PgConnection {
fn fetch_type_by_oid(&mut self, oid: Oid) -> BoxFuture<'_, Result<PgTypeInfo, Error>> {
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",
r#"
SELECT
n.nspname || '.' || t.typname, t.typtype, t.typcategory, t.typrelid, t.typelem, t.typbasetype
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)
Expand Down
4 changes: 2 additions & 2 deletions tests/postgres/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down