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

62 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 StatementNew;
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>>,
}
impl StatementNew for Statement {
fn new(close_sender: Sender<(u8, String)>,
name: String,
params: Vec<Type>,
columns: Arc<Vec<Column>>)
-> Statement {
Statement {
close_sender: close_sender,
name: name,
params: params,
columns: columns,
}
}
fn columns_arc(&self) -> &Arc<Vec<Column>> {
&self.columns
}
fn name(&self) -> &str {
&self.name
}
}
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 {
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
}
}