mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
fix(postgres): get correctly qualified type name in describe
This commit is contained in:
parent
05a10de4d8
commit
10192019d8
@ -187,7 +187,16 @@ impl PgConnection {
|
|||||||
fn fetch_type_by_oid(&mut self, oid: Oid) -> BoxFuture<'_, Result<PgTypeInfo, Error>> {
|
fn fetch_type_by_oid(&mut self, oid: Oid) -> BoxFuture<'_, Result<PgTypeInfo, Error>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let (name, typ_type, category, relation_id, element, base_type): (String, i8, i8, Oid, Oid, Oid) = query_as(
|
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",
|
// Converting the OID to `regtype` and then `text` will give us the name that
|
||||||
|
// the type will need to be found at by search_path.
|
||||||
|
"SELECT oid::regtype::text, \
|
||||||
|
typtype, \
|
||||||
|
typcategory, \
|
||||||
|
typrelid, \
|
||||||
|
typelem, \
|
||||||
|
typbasetype \
|
||||||
|
FROM pg_catalog.pg_type \
|
||||||
|
WHERE oid = $1",
|
||||||
)
|
)
|
||||||
.bind(oid)
|
.bind(oid)
|
||||||
.fetch_one(&mut *self)
|
.fetch_one(&mut *self)
|
||||||
|
@ -724,3 +724,29 @@ async fn test_skip() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
|
#[sqlx_macros::test]
|
||||||
|
async fn test_enum_with_schema() -> anyhow::Result<()> {
|
||||||
|
#[derive(Debug, PartialEq, Eq, sqlx::Type)]
|
||||||
|
#[sqlx(type_name = "foo.\"Foo\"")]
|
||||||
|
enum Foo {
|
||||||
|
Bar,
|
||||||
|
Baz,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut conn = new::<Postgres>().await?;
|
||||||
|
|
||||||
|
let foo: Foo = sqlx::query_scalar("SELECT $1::foo.\"Foo\"")
|
||||||
|
.bind(Foo::Bar)
|
||||||
|
.fetch_one(&mut conn).await?;
|
||||||
|
|
||||||
|
assert_eq!(foo, Foo::Bar);
|
||||||
|
|
||||||
|
let foo: Foo = sqlx::query_scalar("SELECT $1::foo.\"Foo\"")
|
||||||
|
.bind(Foo::Baz)
|
||||||
|
.fetch_one(&mut conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
assert_eq!(foo, Foo::Baz);
|
||||||
|
}
|
@ -51,3 +51,7 @@ CREATE OR REPLACE PROCEDURE forty_two(INOUT forty_two INT = NULL)
|
|||||||
CREATE TABLE test_citext (
|
CREATE TABLE test_citext (
|
||||||
foo CITEXT NOT NULL
|
foo CITEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE SCHEMA IF NOT EXISTS foo;
|
||||||
|
|
||||||
|
CREATE ENUM foo."Foo" ('Bar', 'Baz');
|
Loading…
x
Reference in New Issue
Block a user