sqlx_postgres/
column.rs

1use crate::ext::ustr::UStr;
2use crate::{PgTypeInfo, Postgres};
3
4pub(crate) use sqlx_core::column::{Column, ColumnIndex};
5
6#[derive(Debug, Clone)]
7#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
8pub struct PgColumn {
9    pub(crate) ordinal: usize,
10    pub(crate) name: UStr,
11    pub(crate) type_info: PgTypeInfo,
12    #[cfg_attr(feature = "offline", serde(skip))]
13    pub(crate) relation_id: Option<crate::types::Oid>,
14    #[cfg_attr(feature = "offline", serde(skip))]
15    pub(crate) relation_attribute_no: Option<i16>,
16}
17
18impl PgColumn {
19    /// Returns the OID of the table this column is from, if applicable.
20    ///
21    /// This will be `None` if the column is the result of an expression.
22    ///
23    /// Corresponds to column `attrelid` of the `pg_catalog.pg_attribute` table:
24    /// <https://www.postgresql.org/docs/current/catalog-pg-attribute.html>
25    pub fn relation_id(&self) -> Option<crate::types::Oid> {
26        self.relation_id
27    }
28
29    /// Returns the 1-based index of this column in its parent table, if applicable.
30    ///
31    /// This will be `None` if the column is the result of an expression.
32    ///
33    /// Corresponds to column `attnum` of the `pg_catalog.pg_attribute` table:
34    /// <https://www.postgresql.org/docs/current/catalog-pg-attribute.html>
35    pub fn relation_attribute_no(&self) -> Option<i16> {
36        self.relation_attribute_no
37    }
38}
39
40impl Column for PgColumn {
41    type Database = Postgres;
42
43    fn ordinal(&self) -> usize {
44        self.ordinal
45    }
46
47    fn name(&self) -> &str {
48        &self.name
49    }
50
51    fn type_info(&self) -> &PgTypeInfo {
52        &self.type_info
53    }
54}