Cleanup
This commit is contained in:
parent
25b32e0ede
commit
fc8ab87797
@ -18,7 +18,7 @@ pub struct Notification {
|
||||
pub payload: String,
|
||||
}
|
||||
|
||||
/// An iterator over asynchronous notifications.
|
||||
/// Notifications from the Postgres backend.
|
||||
pub struct Notifications<'conn> {
|
||||
conn: &'conn Connection,
|
||||
}
|
||||
|
57
src/rows.rs
57
src/rows.rs
@ -163,29 +163,6 @@ impl<'a> Row<'a> {
|
||||
self.stmt.columns()
|
||||
}
|
||||
|
||||
/// Retrieves the contents of a field of the row.
|
||||
///
|
||||
/// A field can be accessed by the name or index of its column, though
|
||||
/// access by index is more efficient. Rows are 0-indexed.
|
||||
///
|
||||
/// Returns an `Error` value if the index does not reference a column or
|
||||
/// the return type is not compatible with the Postgres type.
|
||||
pub fn get_opt<I, T>(&self, idx: I) -> Result<T>
|
||||
where I: RowIndex,
|
||||
T: FromSql
|
||||
{
|
||||
let idx = try!(idx.idx(self.stmt).ok_or(Error::InvalidColumn));
|
||||
let ty = self.stmt.columns()[idx].type_();
|
||||
if !<T as FromSql>::accepts(ty) {
|
||||
return Err(Error::WrongType(ty.clone()));
|
||||
}
|
||||
let conn = self.stmt.conn().conn.borrow();
|
||||
match self.data[idx] {
|
||||
Some(ref data) => FromSql::from_sql(ty, &mut &**data, &SessionInfo::new(&*conn)),
|
||||
None => FromSql::from_sql_null(ty, &SessionInfo::new(&*conn)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the contents of a field of the row.
|
||||
///
|
||||
/// A field can be accessed by the name or index of its column, though
|
||||
@ -209,15 +186,45 @@ impl<'a> Row<'a> {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn get<I, T>(&self, idx: I) -> T
|
||||
where I: RowIndex + fmt::Debug + Clone,
|
||||
where I: RowIndex + fmt::Debug,
|
||||
T: FromSql
|
||||
{
|
||||
match self.get_opt(idx.clone()) {
|
||||
match self.get_inner(&idx) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => panic!("error retrieving column {:?}: {:?}", idx, err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the contents of a field of the row.
|
||||
///
|
||||
/// A field can be accessed by the name or index of its column, though
|
||||
/// access by index is more efficient. Rows are 0-indexed.
|
||||
///
|
||||
/// Returns an `Error` value if the index does not reference a column or
|
||||
/// the return type is not compatible with the Postgres type.
|
||||
pub fn get_opt<I, T>(&self, idx: I) -> Result<T>
|
||||
where I: RowIndex,
|
||||
T: FromSql
|
||||
{
|
||||
self.get_inner(&idx)
|
||||
}
|
||||
|
||||
fn get_inner<I, T>(&self, idx: &I) -> Result<T>
|
||||
where I: RowIndex,
|
||||
T: FromSql
|
||||
{
|
||||
let idx = try!(idx.idx(self.stmt).ok_or(Error::InvalidColumn));
|
||||
let ty = self.stmt.columns()[idx].type_();
|
||||
if !<T as FromSql>::accepts(ty) {
|
||||
return Err(Error::WrongType(ty.clone()));
|
||||
}
|
||||
let conn = self.stmt.conn().conn.borrow();
|
||||
match self.data[idx] {
|
||||
Some(ref data) => FromSql::from_sql(ty, &mut &**data, &SessionInfo::new(&*conn)),
|
||||
None => FromSql::from_sql_null(ty, &SessionInfo::new(&*conn)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the specified field as a raw buffer of Postgres data.
|
||||
///
|
||||
/// # Panics
|
||||
|
24
src/stmt.rs
24
src/stmt.rs
@ -538,6 +538,18 @@ impl ColumnNew for Column {
|
||||
}
|
||||
}
|
||||
|
||||
impl Column {
|
||||
/// The name of the column.
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// The type of the data in the column.
|
||||
pub fn type_(&self) -> &Type {
|
||||
&self.type_
|
||||
}
|
||||
}
|
||||
|
||||
/// A struct containing information relevant for a `COPY` operation.
|
||||
pub struct CopyInfo<'a> {
|
||||
conn: RefMut<'a, InnerConnection>,
|
||||
@ -590,18 +602,6 @@ impl<W: Write> WriteWithInfo for W {
|
||||
}
|
||||
}
|
||||
|
||||
impl Column {
|
||||
/// The name of the column.
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// The type of the data in the column.
|
||||
pub fn type_(&self) -> &Type {
|
||||
&self.type_
|
||||
}
|
||||
}
|
||||
|
||||
/// The format of a portion of COPY query data.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Format {
|
||||
|
Loading…
Reference in New Issue
Block a user