Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit647a925

Browse files
authored
Merge pull requestrust-postgres#1144 from rigby-dane/add_row_description
Adds RowDescription to the SimpleQueryMessage
2 parentsded5e7d +2647024 commit647a925

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

‎tokio-postgres/src/lib.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub use crate::generic_client::GenericClient;
130130
pubusecrate::portal::Portal;
131131
pubusecrate::query::RowStream;
132132
pubusecrate::row::{Row,SimpleQueryRow};
133-
pubusecrate::simple_query::SimpleQueryStream;
133+
pubusecrate::simple_query::{SimpleColumn,SimpleQueryStream};
134134
#[cfg(feature ="runtime")]
135135
pubusecrate::socket::Socket;
136136
pubusecrate::statement::{Column,Statement};
@@ -141,6 +141,7 @@ pub use crate::to_statement::ToStatement;
141141
pubusecrate::transaction::Transaction;
142142
pubusecrate::transaction_builder::{IsolationLevel,TransactionBuilder};
143143
usecrate::types::ToSql;
144+
use std::sync::Arc;
144145

145146
pubmod binary_copy;
146147
mod bind;
@@ -248,6 +249,8 @@ pub enum SimpleQueryMessage {
248249
///
249250
/// The number of rows modified or selected is returned.
250251
CommandComplete(u64),
252+
/// Column values of the proceeding row values
253+
RowDescription(Arc<[SimpleColumn]>),
251254
}
252255

253256
fnslice_iter<'a>(

‎tokio-postgres/src/simple_query.rs‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,34 @@ impl Stream for SimpleQueryStream {
8585

8686
fnpoll_next(self:Pin<&mutSelf>,cx:&mutContext<'_>) ->Poll<Option<Self::Item>>{
8787
let this =self.project();
88-
loop{
89-
matchready!(this.responses.poll_next(cx)?){
90-
Message::CommandComplete(body) =>{
91-
let rows =extract_row_affected(&body)?;
92-
returnPoll::Ready(Some(Ok(SimpleQueryMessage::CommandComplete(rows))));
93-
}
94-
Message::EmptyQueryResponse =>{
95-
returnPoll::Ready(Some(Ok(SimpleQueryMessage::CommandComplete(0))));
96-
}
97-
Message::RowDescription(body) =>{
98-
let columns = body
99-
.fields()
100-
.map(|f|Ok(SimpleColumn::new(f.name().to_string())))
101-
.collect::<Vec<_>>()
102-
.map_err(Error::parse)?
103-
.into();
88+
matchready!(this.responses.poll_next(cx)?){
89+
Message::CommandComplete(body) =>{
90+
let rows =extract_row_affected(&body)?;
91+
Poll::Ready(Some(Ok(SimpleQueryMessage::CommandComplete(rows))))
92+
}
93+
Message::EmptyQueryResponse =>{
94+
Poll::Ready(Some(Ok(SimpleQueryMessage::CommandComplete(0))))
95+
}
96+
Message::RowDescription(body) =>{
97+
let columns:Arc<[SimpleColumn]> = body
98+
.fields()
99+
.map(|f|Ok(SimpleColumn::new(f.name().to_string())))
100+
.collect::<Vec<_>>()
101+
.map_err(Error::parse)?
102+
.into();
104103

105-
*this.columns =Some(columns);
106-
}
107-
Message::DataRow(body) =>{
108-
let row =match&this.columns{
109-
Some(columns) =>SimpleQueryRow::new(columns.clone(), body)?,
110-
None =>returnPoll::Ready(Some(Err(Error::unexpected_message()))),
111-
};
112-
returnPoll::Ready(Some(Ok(SimpleQueryMessage::Row(row))));
113-
}
114-
Message::ReadyForQuery(_) =>returnPoll::Ready(None),
115-
_ =>returnPoll::Ready(Some(Err(Error::unexpected_message()))),
104+
*this.columns =Some(columns.clone());
105+
Poll::Ready(Some(Ok(SimpleQueryMessage::RowDescription(columns))))
106+
}
107+
Message::DataRow(body) =>{
108+
let row =match&this.columns{
109+
Some(columns) =>SimpleQueryRow::new(columns.clone(), body)?,
110+
None =>returnPoll::Ready(Some(Err(Error::unexpected_message()))),
111+
};
112+
Poll::Ready(Some(Ok(SimpleQueryMessage::Row(row))))
116113
}
114+
Message::ReadyForQuery(_) =>Poll::Ready(None),
115+
_ =>Poll::Ready(Some(Err(Error::unexpected_message()))),
117116
}
118117
}
119118
}

‎tokio-postgres/tests/test/main.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ async fn simple_query() {
328328
_ =>panic!("unexpected message"),
329329
}
330330
match&messages[2]{
331+
SimpleQueryMessage::RowDescription(columns) =>{
332+
assert_eq!(columns.get(0).map(|c| c.name()),Some("id"));
333+
assert_eq!(columns.get(1).map(|c| c.name()),Some("name"));
334+
}
335+
_ =>panic!("unexpected message"),
336+
}
337+
match&messages[3]{
331338
SimpleQueryMessage::Row(row) =>{
332339
assert_eq!(row.columns().get(0).map(|c| c.name()),Some("id"));
333340
assert_eq!(row.columns().get(1).map(|c| c.name()),Some("name"));
@@ -336,7 +343,7 @@ async fn simple_query() {
336343
}
337344
_ =>panic!("unexpected message"),
338345
}
339-
match&messages[3]{
346+
match&messages[4]{
340347
SimpleQueryMessage::Row(row) =>{
341348
assert_eq!(row.columns().get(0).map(|c| c.name()),Some("id"));
342349
assert_eq!(row.columns().get(1).map(|c| c.name()),Some("name"));
@@ -345,11 +352,11 @@ async fn simple_query() {
345352
}
346353
_ =>panic!("unexpected message"),
347354
}
348-
match messages[4]{
355+
match messages[5]{
349356
SimpleQueryMessage::CommandComplete(2) =>{}
350357
_ =>panic!("unexpected message"),
351358
}
352-
assert_eq!(messages.len(),5);
359+
assert_eq!(messages.len(),6);
353360
}
354361

355362
#[tokio::test]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp