1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use super::cursor::NamedCursor; use super::result::PgResult; use pg::Pg; use row::*; pub struct PgRow<'a> { db_result: &'a PgResult, row_idx: usize, col_idx: usize, } impl<'a> PgRow<'a> { pub fn new(db_result: &'a PgResult, row_idx: usize) -> Self { PgRow { db_result: db_result, row_idx: row_idx, col_idx: 0, } } } impl<'a> Row<Pg> for PgRow<'a> { fn take(&mut self) -> Option<&[u8]> { let current_idx = self.col_idx; self.col_idx += 1; self.db_result.get(self.row_idx, current_idx) } fn next_is_null(&self, count: usize) -> bool { (0..count).all(|i| self.db_result.is_null(self.row_idx, self.col_idx + i)) } } pub struct PgNamedRow<'a> { cursor: &'a NamedCursor, idx: usize, } impl<'a> PgNamedRow<'a> { pub fn new(cursor: &'a NamedCursor, idx: usize) -> Self { PgNamedRow { cursor, idx } } } impl<'a> NamedRow<Pg> for PgNamedRow<'a> { fn get_raw_value(&self, index: usize) -> Option<&[u8]> { self.cursor.get_value(self.idx, index) } fn index_of(&self, column_name: &str) -> Option<usize> { self.cursor.index_of_column(column_name) } }