rust-postgres/tokio-postgres/src/stmt.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

2016-12-26 21:21:20 +00:00
//! Prepared statements.
2016-12-26 20:57:43 +00:00
use std::mem;
use std::sync::Arc;
use std::sync::mpsc::Sender;
#[doc(inline)]
2016-12-26 21:29:30 +00:00
pub use postgres_shared::stmt::Column;
2016-12-26 20:57:43 +00:00
use types::Type;
2016-12-26 21:21:20 +00:00
/// A prepared statement.
2016-12-26 20:57:43 +00:00
pub struct Statement {
close_sender: Sender<(u8, String)>,
name: String,
params: Vec<Type>,
columns: Arc<Vec<Column>>,
}
2017-07-09 17:25:20 +00:00
impl Drop for Statement {
fn drop(&mut self) {
let name = mem::replace(&mut self.name, String::new());
let _ = self.close_sender.send((b'S', name));
}
}
impl Statement {
pub(crate) fn new(
2017-07-01 03:35:17 +00:00
close_sender: Sender<(u8, String)>,
name: String,
params: Vec<Type>,
columns: Arc<Vec<Column>>,
) -> Statement {
2016-12-26 20:57:43 +00:00
Statement {
close_sender: close_sender,
name: name,
params: params,
columns: columns,
}
}
2017-07-09 17:25:20 +00:00
pub(crate) fn columns_arc(&self) -> &Arc<Vec<Column>> {
2016-12-26 20:57:43 +00:00
&self.columns
}
2017-07-09 17:25:20 +00:00
pub(crate) fn name(&self) -> &str {
2016-12-26 20:57:43 +00:00
&self.name
}
2016-12-26 21:21:20 +00:00
/// Returns the types of query parameters for this statement.
2016-12-26 20:57:43 +00:00
pub fn parameters(&self) -> &[Type] {
&self.params
}
2016-12-26 21:21:20 +00:00
/// Returns information about the resulting columns for this statement.
2016-12-26 20:57:43 +00:00
pub fn columns(&self) -> &[Column] {
&self.columns
}
}