use prax_query::error::{QueryError, QueryResult};
use prax_query::row::FromRow;
use tokio_postgres::Row;
use crate::row_ref::PgRow;
pub fn rows_into<T: FromRow>(rows: Vec<Row>) -> QueryResult<Vec<T>> {
rows.into_iter()
.map(|r| {
let r = PgRow::from(r);
T::from_row(&r).map_err(|e| {
let msg = e.to_string();
QueryError::deserialization(msg).with_source(e)
})
})
.collect()
}
pub fn row_into<T: FromRow>(row: Row) -> QueryResult<T> {
let row = PgRow::from(row);
T::from_row(&row).map_err(|e| {
let msg = e.to_string();
QueryError::deserialization(msg).with_source(e)
})
}