Skip to content

Commit

Permalink
Merge pull request #1084 from bikeshedder/table_oid_column_id
Browse files Browse the repository at this point in the history
Add table_oid and column_id to column structure of prepared statements
  • Loading branch information
sfackler authored Dec 11, 2023
2 parents 10edbcb + 8787615 commit eb3f595
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tokio-postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* Disable `rustc-serialize` compatibility of `eui48-1` dependency
* Remove tests for `eui48-04`

* Add `table_oid` and `field_id` fields to `Columns` struct of prepared statements.

## v0.7.10 - 2023-08-25

Expand Down
8 changes: 7 additions & 1 deletion tokio-postgres/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use log::debug;
use postgres_protocol::message::backend::Message;
use postgres_protocol::message::frontend;
use std::future::Future;
use std::num::{NonZeroI16, NonZeroU32};
use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -95,7 +96,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 {
name: field.name().to_string(),
table_oid: NonZeroU32::new(field.table_oid()),
column_id: NonZeroI16::new(field.column_id()),
r#type: type_,
};
columns.push(column);
}
}
Expand Down
34 changes: 17 additions & 17 deletions tokio-postgres/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::connection::RequestMessages;
use crate::types::Type;
use postgres_protocol::message::frontend;
use std::{
fmt,
num::{NonZeroI16, NonZeroU32},
sync::{Arc, Weak},
};

Expand Down Expand Up @@ -65,32 +65,32 @@ impl Statement {
}

/// Information about a column of a query.
#[derive(Debug)]
pub struct Column {
name: String,
type_: Type,
pub(crate) name: String,
pub(crate) table_oid: Option<NonZeroU32>,
pub(crate) column_id: Option<NonZeroI16>,
pub(crate) r#type: Type,
}

impl Column {
pub(crate) fn new(name: String, type_: Type) -> Column {
Column { name, type_ }
}

/// Returns the name of the column.
pub fn name(&self) -> &str {
&self.name
}

/// Returns the type of the column.
pub fn type_(&self) -> &Type {
&self.type_
/// Returns the OID of the underlying database table.
pub fn table_oid(&self) -> Option<NonZeroU32> {
self.table_oid
}

/// Return the column ID within the underlying database table.
pub fn column_id(&self) -> Option<NonZeroI16> {
self.column_id
}
}

impl fmt::Debug for Column {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Column")
.field("name", &self.name)
.field("type", &self.type_)
.finish()
/// Returns the type of the column.
pub fn type_(&self) -> &Type {
&self.r#type
}
}

0 comments on commit eb3f595

Please sign in to comment.