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

tokio-postgres: Expose table OID and column ID on Column #7

Merged
merged 1 commit into from
Aug 22, 2023
Merged
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
7 changes: 6 additions & 1 deletion tokio-postgres/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ pub async fn prepare(
let mut it = row_description.fields();
while let Some(field) = it.next().map_err(Error::parse)? {
let type_ = get_type(client, field.type_oid()).await?;
let column = Column::new(field.name().to_string(), type_);
let column = Column::new(
field.name().to_string(),
type_,
Some(field.table_oid()).filter(|oid| *oid != 0),
Some(field.column_id()).filter(|id| *id != 0),
);
columns.push(column);
}
}
Expand Down
27 changes: 25 additions & 2 deletions tokio-postgres/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,23 @@ impl Statement {
pub struct Column {
name: String,
type_: Type,
table_oid: Option<u32>,
column_id: Option<i16>,
}

impl Column {
pub(crate) fn new(name: String, type_: Type) -> Column {
Column { name, type_ }
pub(crate) fn new(
name: String,
type_: Type,
table_oid: Option<u32>,
column_id: Option<i16>,
) -> Column {
Column {
name,
type_,
table_oid,
column_id,
}
}

/// Returns the name of the column.
Expand All @@ -84,6 +96,17 @@ impl Column {
pub fn type_(&self) -> &Type {
&self.type_
}

/// Returns the oid of the column's table, if it is a direct alias to a column in a table
pub fn table_oid(&self) -> Option<u32> {
self.table_oid
}

/// Returns the column's attribute number in its table, if it is a direct alias to a column in a
/// table
pub fn column_id(&self) -> Option<i16> {
self.column_id
}
}

impl fmt::Debug for Column {
Expand Down
Loading