Skip to content

Commit eb3f595

Browse files
authored
Merge pull request #1084 from bikeshedder/table_oid_column_id
Add table_oid and column_id to column structure of prepared statements
2 parents 10edbcb + 8787615 commit eb3f595

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

tokio-postgres/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Disable `rustc-serialize` compatibility of `eui48-1` dependency
66
* Remove tests for `eui48-04`
7-
7+
* Add `table_oid` and `field_id` fields to `Columns` struct of prepared statements.
88

99
## v0.7.10 - 2023-08-25
1010

tokio-postgres/src/prepare.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use log::debug;
1212
use postgres_protocol::message::backend::Message;
1313
use postgres_protocol::message::frontend;
1414
use std::future::Future;
15+
use std::num::{NonZeroI16, NonZeroU32};
1516
use std::pin::Pin;
1617
use std::sync::atomic::{AtomicUsize, Ordering};
1718
use std::sync::Arc;
@@ -95,7 +96,12 @@ pub async fn prepare(
9596
let mut it = row_description.fields();
9697
while let Some(field) = it.next().map_err(Error::parse)? {
9798
let type_ = get_type(client, field.type_oid()).await?;
98-
let column = Column::new(field.name().to_string(), type_);
99+
let column = Column {
100+
name: field.name().to_string(),
101+
table_oid: NonZeroU32::new(field.table_oid()),
102+
column_id: NonZeroI16::new(field.column_id()),
103+
r#type: type_,
104+
};
99105
columns.push(column);
100106
}
101107
}

tokio-postgres/src/statement.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::connection::RequestMessages;
44
use crate::types::Type;
55
use postgres_protocol::message::frontend;
66
use std::{
7-
fmt,
7+
num::{NonZeroI16, NonZeroU32},
88
sync::{Arc, Weak},
99
};
1010

@@ -65,32 +65,32 @@ impl Statement {
6565
}
6666

6767
/// Information about a column of a query.
68+
#[derive(Debug)]
6869
pub struct Column {
69-
name: String,
70-
type_: Type,
70+
pub(crate) name: String,
71+
pub(crate) table_oid: Option<NonZeroU32>,
72+
pub(crate) column_id: Option<NonZeroI16>,
73+
pub(crate) r#type: Type,
7174
}
7275

7376
impl Column {
74-
pub(crate) fn new(name: String, type_: Type) -> Column {
75-
Column { name, type_ }
76-
}
77-
7877
/// Returns the name of the column.
7978
pub fn name(&self) -> &str {
8079
&self.name
8180
}
8281

83-
/// Returns the type of the column.
84-
pub fn type_(&self) -> &Type {
85-
&self.type_
82+
/// Returns the OID of the underlying database table.
83+
pub fn table_oid(&self) -> Option<NonZeroU32> {
84+
self.table_oid
85+
}
86+
87+
/// Return the column ID within the underlying database table.
88+
pub fn column_id(&self) -> Option<NonZeroI16> {
89+
self.column_id
8690
}
87-
}
8891

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

0 commit comments

Comments
 (0)