mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
feat: expose relation_id and relation_attribution_no on PgColumn (#3492)
* expose relation_id and relation_attribution_no on PgColumn * Update sqlx-postgres/src/message/row_description.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Update sqlx-postgres/src/column.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Update sqlx-postgres/src/message/row_description.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Update sqlx-postgres/src/column.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Update sqlx-postgres/src/message/row_description.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * fix --------- Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
This commit is contained in:
parent
10bec32770
commit
c597a225c5
2 changed files with 26 additions and 4 deletions
|
@ -10,11 +10,33 @@ pub struct PgColumn {
|
|||
pub(crate) name: UStr,
|
||||
pub(crate) type_info: PgTypeInfo,
|
||||
#[cfg_attr(feature = "offline", serde(skip))]
|
||||
pub(crate) relation_id: Option<i32>,
|
||||
pub(crate) relation_id: Option<crate::types::Oid>,
|
||||
#[cfg_attr(feature = "offline", serde(skip))]
|
||||
pub(crate) relation_attribute_no: Option<i16>,
|
||||
}
|
||||
|
||||
impl PgColumn {
|
||||
/// Returns the OID of the table this column is from, if applicable.
|
||||
///
|
||||
/// This will be `None` if the column is the result of an expression.
|
||||
///
|
||||
/// Corresponds to column `attrelid` of the `pg_catalog.pg_attribute` table:
|
||||
/// <https://www.postgresql.org/docs/current/catalog-pg-attribute.html>
|
||||
pub fn relation_id(&self) -> Option<crate::types::Oid> {
|
||||
self.relation_id
|
||||
}
|
||||
|
||||
/// Returns the 1-based index of this column in its parent table, if applicable.
|
||||
///
|
||||
/// This will be `None` if the column is the result of an expression.
|
||||
///
|
||||
/// Corresponds to column `attnum` of the `pg_catalog.pg_attribute` table:
|
||||
/// <https://www.postgresql.org/docs/current/catalog-pg-attribute.html>
|
||||
pub fn relation_attribute_no(&self) -> Option<i16> {
|
||||
self.relation_attribute_no
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for PgColumn {
|
||||
type Database = Postgres;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ pub struct Field {
|
|||
|
||||
/// If the field can be identified as a column of a specific table, the
|
||||
/// object ID of the table; otherwise zero.
|
||||
pub relation_id: Option<i32>,
|
||||
pub relation_id: Option<Oid>,
|
||||
|
||||
/// If the field can be identified as a column of a specific table, the attribute number of
|
||||
/// the column; otherwise zero.
|
||||
|
@ -65,7 +65,7 @@ impl BackendMessage for RowDescription {
|
|||
));
|
||||
}
|
||||
|
||||
let relation_id = buf.get_i32();
|
||||
let relation_id = buf.get_u32();
|
||||
let relation_attribute_no = buf.get_i16();
|
||||
let data_type_id = Oid(buf.get_u32());
|
||||
let data_type_size = buf.get_i16();
|
||||
|
@ -77,7 +77,7 @@ impl BackendMessage for RowDescription {
|
|||
relation_id: if relation_id == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(relation_id)
|
||||
Some(Oid(relation_id))
|
||||
},
|
||||
relation_attribute_no: if relation_attribute_no == 0 {
|
||||
None
|
||||
|
|
Loading…
Reference in a new issue