Skip to content

Commit 54a490b

Browse files
authored
Merge pull request prisma#4 from prisma/feat/expose-stmt-column-info
expose stmt name and column id and table_oid
2 parents a1a2dc6 + 2887426 commit 54a490b

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

tokio-postgres/src/prepare.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ pub async fn prepare(
9595
let mut it = row_description.fields();
9696
while let Some(field) = it.next().map_err(Error::parse)? {
9797
let type_ = get_type(client, field.type_oid()).await?;
98-
let column = Column::new(field.name().to_string(), type_);
98+
let column = Column::new(
99+
field.name().to_string(),
100+
type_,
101+
field.column_id(),
102+
field.table_oid(),
103+
);
99104
columns.push(column);
100105
}
101106
}

tokio-postgres/src/statement.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ impl Statement {
4949
}))
5050
}
5151

52-
pub(crate) fn name(&self) -> &str {
52+
/// Returns the name of the statement.
53+
pub fn name(&self) -> &str {
5354
&self.0.name
5455
}
5556

@@ -68,11 +69,26 @@ impl Statement {
6869
pub struct Column {
6970
name: String,
7071
type_: Type,
72+
column_id: Option<i16>,
73+
table_oid: Option<u32>,
7174
}
7275

7376
impl Column {
74-
pub(crate) fn new(name: String, type_: Type) -> Column {
75-
Column { name, type_ }
77+
pub(crate) fn new(name: String, type_: Type, column_id: i16, table_oid: u32) -> Column {
78+
Column {
79+
name,
80+
type_,
81+
column_id: if column_id == 0 {
82+
None
83+
} else {
84+
Some(column_id)
85+
},
86+
table_oid: if table_oid == 0 {
87+
None
88+
} else {
89+
Some(table_oid)
90+
},
91+
}
7692
}
7793

7894
/// Returns the name of the column.
@@ -84,6 +100,16 @@ impl Column {
84100
pub fn type_(&self) -> &Type {
85101
&self.type_
86102
}
103+
104+
/// Returns the id of the column if there's one.
105+
pub fn column_id(&self) -> Option<i16> {
106+
self.column_id
107+
}
108+
109+
/// Returns the table_oid of the column if there's one.
110+
pub fn table_oid(&self) -> Option<u32> {
111+
self.table_oid
112+
}
87113
}
88114

89115
impl fmt::Debug for Column {

0 commit comments

Comments
 (0)