mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-28 22:21:11 +00:00
fix(postgres): invert the type description logic to allow all "simple" type categories
closes #379
This commit is contained in:
@@ -134,16 +134,21 @@ impl PgConnection {
|
||||
.await?;
|
||||
|
||||
match category as u8 {
|
||||
b'S' => Ok(PgTypeInfo(PgType::Custom(Arc::new(PgCustomType {
|
||||
b'A' => Err(err_protocol!("user-defined array types are unsupported")),
|
||||
|
||||
b'P' => Err(err_protocol!("pseudo types are unsupported")),
|
||||
|
||||
b'R' => Err(err_protocol!("user-defined range types are unsupported")),
|
||||
|
||||
b'E' => self.fetch_enum_by_oid(oid, name).await,
|
||||
|
||||
b'C' => self.fetch_composite_by_oid(oid, relation_id, name).await,
|
||||
|
||||
_ => Ok(PgTypeInfo(PgType::Custom(Arc::new(PgCustomType {
|
||||
kind: PgTypeKind::Simple,
|
||||
name: name.into(),
|
||||
oid,
|
||||
})))),
|
||||
|
||||
b'E' => self.fetch_enum_by_oid(oid, name).await,
|
||||
b'C' => self.fetch_composite_by_oid(oid, relation_id, name).await,
|
||||
|
||||
c => Err(err_protocol!("unknown type category: {:?}", c as char)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +209,26 @@ ORDER BY attnum
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn fetch_type_id_by_name(&mut self, name: &str) -> Result<u32, Error> {
|
||||
if let Some(oid) = self.cache_type_oid.get(name) {
|
||||
return Ok(*oid);
|
||||
}
|
||||
|
||||
// language=SQL
|
||||
let (oid,): (u32,) = query_as(
|
||||
"
|
||||
SELECT oid FROM pg_catalog.pg_type WHERE typname ILIKE $1
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.fetch_one(&mut *self)
|
||||
.await?;
|
||||
|
||||
self.cache_type_oid.insert(name.to_string().into(), oid);
|
||||
|
||||
Ok(oid)
|
||||
}
|
||||
|
||||
pub(crate) async fn map_result_columns(
|
||||
&mut self,
|
||||
columns: &[PgColumn],
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::postgres::message::{
|
||||
};
|
||||
use crate::postgres::type_info::PgType;
|
||||
use crate::postgres::{PgArguments, PgConnection, PgRow, PgValueFormat, Postgres};
|
||||
use crate::query_as::query_as;
|
||||
|
||||
async fn prepare(
|
||||
conn: &mut PgConnection,
|
||||
@@ -95,26 +94,6 @@ impl PgConnection {
|
||||
Ok(statement)
|
||||
}
|
||||
|
||||
pub(crate) async fn fetch_type_id_by_name(&mut self, name: &str) -> Result<u32, Error> {
|
||||
if let Some(oid) = self.cache_type_oid.get(name) {
|
||||
return Ok(*oid);
|
||||
}
|
||||
|
||||
// language=SQL
|
||||
let (oid,): (u32,) = query_as(
|
||||
"
|
||||
SELECT oid FROM pg_catalog.pg_type WHERE typname ILIKE $1
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.fetch_one(&mut *self)
|
||||
.await?;
|
||||
|
||||
self.cache_type_oid.insert(name.to_string().into(), oid);
|
||||
|
||||
Ok(oid)
|
||||
}
|
||||
|
||||
async fn run(
|
||||
&mut self,
|
||||
query: &str,
|
||||
|
||||
Reference in New Issue
Block a user