Implement get_results

This commit is contained in:
Zachery Gyurkovitz
2019-07-19 14:13:23 -07:00
parent a4b5cfc408
commit 2fb0c545b7

View File

@@ -126,4 +126,46 @@ impl<'a> Prepare<'a> {
// FIXME: This is an end-of-file error. How we should bubble this up here?
unreachable!()
}
}
#[inline]
pub async fn get_results(self) -> io::Result<Vec<DataRow>> {
proto::bind::trailer(
&mut self.connection.wbuf,
self.bind_state,
self.bind_values,
&[],
);
self.connection.send(Execute::new("", 0));
self.connection.send(Sync);
self.connection.flush().await?;
let mut rows = vec![];
while let Some(message) = self.connection.receive().await? {
match message {
Message::BindComplete | Message::ParseComplete => {
// Indicates successful completion of a phase
}
Message::DataRow(row) => {
rows.push(row);
}
Message::CommandComplete(_) => {}
Message::ReadyForQuery(_) => {
// Successful completion of the whole cycle
return Ok(rows);
}
message => {
unimplemented!("received {:?} unimplemented message", message);
}
}
}
// FIXME: This is an end-of-file error. How we should bubble this up here?
unreachable!()
}
}