Skip to content

Add table_oid and column_id to column structure of prepared statements #1084

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

Merged
merged 2 commits into from
Dec 11, 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
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
}
}