use std::sync::Arc; use hashbrown::HashMap; use crate::error::Error; use crate::ext::ustr::UStr; use crate::postgres::message::DataRow; use crate::postgres::value::PgValueFormat; use crate::postgres::{PgTypeInfo, PgValueRef, Postgres}; use crate::row::{ColumnIndex, Row}; // Result column of a prepared statement // See RowDescription/Field for more information #[derive(Debug, Clone)] pub(crate) struct PgColumn { pub(crate) name: UStr, pub(crate) type_info: PgTypeInfo, pub(crate) relation_id: Option, pub(crate) relation_attribute_no: Option, } /// Implementation of [`Row`] for PostgreSQL. pub struct PgRow { pub(crate) data: DataRow, pub(crate) format: PgValueFormat, pub(crate) columns: Arc>, pub(crate) column_names: Arc>, } impl crate::row::private_row::Sealed for PgRow {} impl Row for PgRow { type Database = Postgres; #[inline] fn len(&self) -> usize { self.data.len() } fn try_get_raw(&self, index: I) -> Result, Error> where I: ColumnIndex, { let index = index.index(self)?; let column = &self.columns[index]; let value = self.data.get(index); Ok(PgValueRef { format: self.format, row: Some(&self.data.storage), type_info: column.type_info.clone(), value, }) } } impl ColumnIndex for &'_ str { fn index(&self, row: &PgRow) -> Result { row.column_names .get(*self) .ok_or_else(|| Error::ColumnNotFound((*self).into())) .map(|v| *v) } }